Blacklist special params in history and do not trigger change on page load
This commit is contained in:
parent
d3c4660c2d
commit
9b79a8280f
public/js/icinga
|
@ -49,7 +49,7 @@
|
||||||
) {
|
) {
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
this.icinga.logger.debug('History API enabled');
|
this.icinga.logger.debug('History API enabled');
|
||||||
this.applyLocationBar();
|
this.applyLocationBar(true);
|
||||||
$(window).on('popstate', { self: this }, this.onHistoryChange);
|
$(window).on('popstate', { self: this }, this.onHistoryChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,13 +62,16 @@
|
||||||
*/
|
*/
|
||||||
pushCurrentState: function () {
|
pushCurrentState: function () {
|
||||||
|
|
||||||
|
var icinga = this.icinga;
|
||||||
|
|
||||||
// No history API, no action
|
// No history API, no action
|
||||||
if (!this.enabled) {
|
if (!this.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.icinga.logger.debug('Pushing current state to history');
|
icinga.logger.debug('Pushing current state to history');
|
||||||
var url = '';
|
var url = '';
|
||||||
|
var blacklist = ['_render', '_reload'];
|
||||||
|
|
||||||
// We only store URLs of containers sitting directly under #main:
|
// We only store URLs of containers sitting directly under #main:
|
||||||
$('#main > .container').each(function (idx, container) {
|
$('#main > .container').each(function (idx, container) {
|
||||||
|
@ -76,6 +79,7 @@
|
||||||
|
|
||||||
// TODO: I'd prefer to have the rightmost URL first
|
// TODO: I'd prefer to have the rightmost URL first
|
||||||
if ('undefined' !== typeof cUrl) {
|
if ('undefined' !== typeof cUrl) {
|
||||||
|
cUrl = icinga.utils.removeUrlParams(cUrl, blacklist);
|
||||||
if (url === '') {
|
if (url === '') {
|
||||||
url = cUrl;
|
url = cUrl;
|
||||||
} else {
|
} else {
|
||||||
|
@ -120,14 +124,18 @@
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
applyLocationBar: function () {
|
applyLocationBar: function (onload) {
|
||||||
var icinga = this.icinga,
|
var icinga = this.icinga,
|
||||||
main,
|
main,
|
||||||
parts;
|
parts;
|
||||||
|
|
||||||
|
if (typeof onload === 'undefined') {
|
||||||
|
onload = false;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Still hardcoding col1/col2, shall be dynamic soon
|
// TODO: Still hardcoding col1/col2, shall be dynamic soon
|
||||||
main = document.location.pathname + document.location.search;
|
main = document.location.pathname + document.location.search;
|
||||||
if ($('#col1').data('icingaUrl') !== main) {
|
if (! onload && $('#col1').data('icingaUrl') !== main) {
|
||||||
icinga.loader.loadUrl(
|
icinga.loader.loadUrl(
|
||||||
main,
|
main,
|
||||||
$('#col1')
|
$('#col1')
|
||||||
|
|
|
@ -114,6 +114,32 @@
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Local URLs only
|
||||||
|
removeUrlParams: function (url, params) {
|
||||||
|
var parts = this.parseUrl(url),
|
||||||
|
result = parts.path,
|
||||||
|
newparams = parts.params;
|
||||||
|
|
||||||
|
$.each(params, function (idx, key) {
|
||||||
|
delete newparams[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
if (Object.keys(newparams).length > 0) {
|
||||||
|
var queryString = '?';
|
||||||
|
$.each(newparams, function (key, value) {
|
||||||
|
if (queryString !== '?') {
|
||||||
|
queryString += '&';
|
||||||
|
}
|
||||||
|
queryString += encodeURIComponent(key) + '=' + encodeURIComponent(value);
|
||||||
|
});
|
||||||
|
result += queryString;
|
||||||
|
}
|
||||||
|
if (parts.hash.length > 0) {
|
||||||
|
result += '#' + parts.hash;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse url params
|
* Parse url params
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue