Commit 091a3e66 authored by Clement Ho's avatar Clement Ho

Add getParameterByName

parent 98cb6101
...@@ -138,24 +138,10 @@ ...@@ -138,24 +138,10 @@
search() { search() {
let paths = []; 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); const { tokens, searchToken } = this.tokenizer.processTokens(this.filteredSearchInput.value);
const currentState = gl.utils.getParameterByName('state') || 'opened';
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);
}
paths.push(`state=${currentState}`); paths.push(`state=${currentState}`);
tokens.forEach((token) => { tokens.forEach((token) => {
const match = gl.FilteredSearchTokenKeys.get().filter(t => t.key === token.key)[0]; const match = gl.FilteredSearchTokenKeys.get().filter(t => t.key === token.key)[0];
let tokenPath = ''; let tokenPath = '';
......
...@@ -124,6 +124,22 @@ ...@@ -124,6 +124,22 @@
return parsedUrl.pathname.charAt(0) === '/' ? parsedUrl.pathname : '/' + parsedUrl.pathname; 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) { gl.utils.isMetaKey = function(e) {
return e.metaKey || e.ctrlKey || e.altKey || e.shiftKey; return e.metaKey || e.ctrlKey || e.altKey || e.shiftKey;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment