mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 08:36:33 +03:00
url parameter for demo page (fixes #22)
This commit is contained in:
parent
f5ca1e04f0
commit
2cbb516059
24
demo/main.js
24
demo/main.js
|
@ -5,9 +5,31 @@
|
|||
var schemaUrlInput = document.getElementById('schema-url-input');
|
||||
schemaUrlForm.addEventListener('submit', function(event) {
|
||||
event.preventDefault();
|
||||
Redoc.init(schemaUrlInput.value);
|
||||
event.stopPropagation();
|
||||
location.search = updateQueryStringParameter(location.search, 'url', schemaUrlInput.value)
|
||||
return false;
|
||||
})
|
||||
|
||||
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;
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue
Block a user