JS: Introduce Icinga.Utils.addUrlFlag()

This commit is contained in:
Eric Lippmann 2020-01-14 14:53:08 +01:00
parent 8da37e5ca2
commit 4d02d8f6d6
1 changed files with 24 additions and 0 deletions

View File

@ -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
*