MCPcopy Create free account
hub / github.com/TruthHun/BookStack / updateQueryStringParam

Function updateQueryStringParam

static/mergely/editor/editor.js:673–698  ·  view source on GitHub ↗
(key, value, defaultValue, urlQueryString)

Source from the content-addressed store, hash-verified

671 }
672 // Explicitly save/update a url parameter using HTML5's replaceState().
673 function updateQueryStringParam(key, value, defaultValue, urlQueryString) {
674 urlQueryString = urlQueryString || document.location.search;
675 var parts = urlQueryString.replace(/^\?/, '').split(/&/), found = false;
676 for (var i in parts) {
677 if (parts[i].startsWith(key + '=')) {
678 found = true;
679 if (value === defaultValue) {
680 // value is default value, remove option
681 parts.splice(i, 1);
682 }
683 else {
684 // make new value
685 parts[i] = key + '=' + value;
686 }
687 break;
688 }
689 else if (parts[i].length === 0) {
690 parts.splice(i, 1);
691 break;
692 }
693 }
694 if (!found) {
695 parts.push(key + '=' + value);
696 }
697 return (parts.length) ? '?' + parts.join('&') : '';
698 }
699});

Callers 2

editor.jsFile · 0.70
applyColorCssFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected