Blacklist special params in history and do not trigger change on page load

This commit is contained in:
Thomas Gelf 2014-03-31 16:24:29 +00:00
parent d3c4660c2d
commit 9b79a8280f
2 changed files with 38 additions and 4 deletions

View File

@ -49,7 +49,7 @@
) {
this.enabled = true;
this.icinga.logger.debug('History API enabled');
this.applyLocationBar();
this.applyLocationBar(true);
$(window).on('popstate', { self: this }, this.onHistoryChange);
}
@ -62,13 +62,16 @@
*/
pushCurrentState: function () {
var icinga = this.icinga;
// No history API, no action
if (!this.enabled) {
return;
}
this.icinga.logger.debug('Pushing current state to history');
icinga.logger.debug('Pushing current state to history');
var url = '';
var blacklist = ['_render', '_reload'];
// We only store URLs of containers sitting directly under #main:
$('#main > .container').each(function (idx, container) {
@ -76,6 +79,7 @@
// TODO: I'd prefer to have the rightmost URL first
if ('undefined' !== typeof cUrl) {
cUrl = icinga.utils.removeUrlParams(cUrl, blacklist);
if (url === '') {
url = cUrl;
} else {
@ -120,14 +124,18 @@
},
applyLocationBar: function () {
applyLocationBar: function (onload) {
var icinga = this.icinga,
main,
parts;
if (typeof onload === 'undefined') {
onload = false;
}
// TODO: Still hardcoding col1/col2, shall be dynamic soon
main = document.location.pathname + document.location.search;
if ($('#col1').data('icingaUrl') !== main) {
if (! onload && $('#col1').data('icingaUrl') !== main) {
icinga.loader.loadUrl(
main,
$('#col1')

View File

@ -114,6 +114,32 @@
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
*/