redoc/demo/main.js

36 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-11-04 22:31:10 +03:00
;(function() {
'use strict';
2016-01-23 01:00:28 +03:00
var schemaUrlForm = document.getElementById('schema-url-form');
2015-11-04 22:31:10 +03:00
var schemaUrlInput = document.getElementById('schema-url-input');
2016-01-23 01:00:28 +03:00
schemaUrlForm.addEventListener('submit', function(event) {
2016-01-24 20:01:17 +03:00
event.preventDefault();
event.stopPropagation();
location.search = updateQueryStringParameter(location.search, 'url', schemaUrlInput.value)
2016-01-24 20:01:17 +03:00
return false;
2015-11-04 22:31:10 +03:00
})
var url = window.location.search.match(/url=([^&]+)/);
if (url && url.length > 1) {
url = decodeURIComponent(url[1]);
document.getElementsByTagName('redoc')[0].setAttribute('spec-url', url);
schemaUrlInput.value = url;
}
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp("([?|&])" + key + "=.*?(&|#|$)", "i");
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
} else {
var hash = '';
if( uri.indexOf('#') !== -1 ){
hash = uri.replace(/.*#/, '#');
uri = uri.replace(/#.*/, '');
}
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
return uri + separator + key + "=" + value + hash;
}
}
//window.redocDebugMode = true;
2015-11-04 22:31:10 +03:00
})();