diff --git a/public/js/icinga/history.js b/public/js/icinga/history.js index f6acf482c..68e858ddb 100644 --- a/public/js/icinga/history.js +++ b/public/js/icinga/history.js @@ -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') diff --git a/public/js/icinga/utils.js b/public/js/icinga/utils.js index 1af5165ab..5f7cf452c 100644 --- a/public/js/icinga/utils.js +++ b/public/js/icinga/utils.js @@ -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 */