From 4d02d8f6d6bc38dacd9bea4409d6d184c292b602 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Tue, 14 Jan 2020 14:53:08 +0100 Subject: [PATCH] JS: Introduce Icinga.Utils.addUrlFlag() --- public/js/icinga/utils.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/public/js/icinga/utils.js b/public/js/icinga/utils.js index 8b2a90921..615e3ab0f 100644 --- a/public/js/icinga/utils.js +++ b/public/js/icinga/utils.js @@ -210,6 +210,30 @@ return params; }, + /** + * Add the specified flag to the given URL + * + * @param {string} url + * @param {string} flag + * + * @returns {string} + */ + addUrlFlag: function (url, flag) { + var pos = url.lastIndexOf('#'); + + if (url.indexOf('?') !== -1) { + flag = '&' + flag; + } else { + flag = '?' + flag; + } + + if (pos === -1) { + return url + flag; + } + + return url.slice(0, pos) + flag + url.slice(pos); + }, + /** * Check whether two HTMLElements overlap *