location.params = function()

in ui/src/main/resources/static/js/ui_lib.js [17:71]


location.params = function(params_set, params_append, params_subtract) {
    let obj = {}, i, parts, len, key, value;

    const _params = location.search.substr(1).split('&');

    for (i = 0, len = _params.length; i < len; i++) {
        parts = _params[i].split('=');
        if (! parts[0]) {
            continue;
        }
        if (parts[1]) {
            obj[parts[0]] = parts[1].split(',');
        } else {
            obj[parts[0]] = true;
        }
    }

    for (key in params_set) {
        value = params_set[key];
        key = encodeURIComponent(key);
        if (typeof value === 'undefined' || value == null) {
            delete obj[key];
        } else {
            obj[key] = [encodeURIComponent(value)];
        }
    }
    for (key in params_append) {
        value = encodeURIComponent(params_append[key]);
        key = encodeURIComponent(key);
        if (obj[key] != null) {
            if (obj[key].indexOf(value) < 0) {
                obj[key].push(value);
            }
        } else {
            obj[key] = [value];
        }
    }
    for (key in params_subtract) {
        value = encodeURIComponent(params_subtract[key]);
        key = encodeURIComponent(key);
        if (obj[key] != null && obj[key].indexOf(value) >= 0) {
            obj[key].splice(obj[key].indexOf(value), 1);
            if (obj[key].length === 0) {
                delete obj[key];
            }
        }
    }

    parts = [];
    for (key in obj) {
        parts.push(key + (obj[key] === true ? '' : '=' + obj[key]));
    }

    location.search = parts.join('&');
};