Add getParameterByName
This commit is contained in:
parent
98cb6101ec
commit
091a3e66e9
|
@ -138,24 +138,10 @@
|
|||
|
||||
search() {
|
||||
let paths = [];
|
||||
|
||||
// Check current state
|
||||
const currentPath = window.location.search;
|
||||
const stateIndex = currentPath.indexOf('state=');
|
||||
const defaultState = 'opened';
|
||||
let currentState = defaultState;
|
||||
|
||||
const { tokens, searchToken } = this.tokenizer.processTokens(this.filteredSearchInput.value);
|
||||
|
||||
if (stateIndex !== -1) {
|
||||
// Get currentState from url params if available
|
||||
const remaining = currentPath.slice(stateIndex + 'state='.length);
|
||||
const separatorIndex = remaining.indexOf('&');
|
||||
|
||||
currentState = separatorIndex === -1 ? remaining : remaining.slice(0, separatorIndex);
|
||||
}
|
||||
|
||||
const currentState = gl.utils.getParameterByName('state') || 'opened';
|
||||
paths.push(`state=${currentState}`);
|
||||
|
||||
tokens.forEach((token) => {
|
||||
const match = gl.FilteredSearchTokenKeys.get().filter(t => t.key === token.key)[0];
|
||||
let tokenPath = '';
|
||||
|
|
|
@ -124,6 +124,22 @@
|
|||
return parsedUrl.pathname.charAt(0) === '/' ? parsedUrl.pathname : '/' + parsedUrl.pathname;
|
||||
};
|
||||
|
||||
gl.utils.getParameterByName = function(name) {
|
||||
var url = window.location.href;
|
||||
var param = name.replace(/[[\]]/g, '\\$&');
|
||||
var regex = new RegExp(`[?&]${param}(=([^&#]*)|&|#|$)`);
|
||||
var results = regex.exec(url);
|
||||
|
||||
if (!results) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!results[2]) {
|
||||
return '';
|
||||
}
|
||||
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
||||
};
|
||||
|
||||
gl.utils.isMetaKey = function(e) {
|
||||
return e.metaKey || e.ctrlKey || e.altKey || e.shiftKey;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue