-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
search config: port from cookies to localStorage
Fixes #220
- Loading branch information
Showing
5 changed files
with
63 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,71 @@ | ||
/** | ||
* @param {string} value | ||
* @returns {boolean} | ||
*/ | ||
function parseBoolean(value) { | ||
return (/^true$/i).test(value); | ||
return value === "true"; | ||
} | ||
|
||
|
||
function getCookie(key, def) { | ||
var value = Cookies.get(key); | ||
if (value === undefined) | ||
return def | ||
return value; | ||
} | ||
|
||
|
||
Config = function() { | ||
} | ||
|
||
|
||
Config.prototype.reset = function() { | ||
Cookies.remove('case_insensitive'); | ||
Cookies.remove('include_all'); | ||
Cookies.remove('search_modules'); | ||
/** | ||
* @param {string} key | ||
* @param {string} defaultValue | ||
* @returns {string} | ||
*/ | ||
function getStorageItem(key, defaultValue) { | ||
const value = localStorage.getItem(key); | ||
return value !== null ? value : defaultValue; | ||
} | ||
|
||
|
||
Config.prototype.setCaseInsensitive = function(value) { | ||
Cookies.set('case_insensitive', String(value)); | ||
} | ||
|
||
|
||
Config.prototype.getCaseInsensitive = function() { | ||
return parseBoolean(getCookie('case_insensitive', 'true')); | ||
} | ||
|
||
|
||
Config.prototype.setIncludeAll = function(value) { | ||
Cookies.set('include_all', String(value)); | ||
} | ||
|
||
|
||
Config.prototype.getIncludeAll = function() { | ||
return parseBoolean(getCookie('include_all', 'true')); | ||
} | ||
|
||
|
||
Config.prototype.setModules = function(modules) { | ||
Cookies.set('search_modules', modules.join(",")); | ||
} | ||
|
||
|
||
Config.prototype.getModules = function() { | ||
var result = getCookie('search_modules', ''); | ||
if (result == '') | ||
return []; | ||
class Config { | ||
reset() { | ||
localStorage.removeItem("case_insensitive"); | ||
localStorage.removeItem("include_all"); | ||
localStorage.removeItem("search_modules"); | ||
} | ||
|
||
/** | ||
* @param {boolean} value | ||
*/ | ||
setCaseInsensitive(value) { | ||
localStorage.setItem("case_insensitive", String(value)); | ||
} | ||
|
||
/** | ||
* @returns {boolean} | ||
*/ | ||
getCaseInsensitive() { | ||
return parseBoolean(getStorageItem("case_insensitive", "true")); | ||
} | ||
|
||
/** | ||
* @param {boolean} value | ||
*/ | ||
setIncludeAll(value) { | ||
localStorage.setItem("include_all", String(value)); | ||
} | ||
|
||
/** | ||
* @returns {boolean} | ||
*/ | ||
getIncludeAll() { | ||
return parseBoolean(getStorageItem("include_all", "true")); | ||
} | ||
|
||
/** | ||
* @param {string[]} modules | ||
*/ | ||
setModules(modules) { | ||
localStorage.setItem("search_modules", modules.join(",")); | ||
} | ||
|
||
/** | ||
* @returns {string[]} | ||
*/ | ||
getModules() { | ||
const result = getStorageItem("search_modules", ""); | ||
if (result === "") return []; | ||
return result.split(","); | ||
} | ||
} | ||
|
||
|
||
Config.prototype.getIncludeAll = function() { | ||
return parseBoolean(getCookie('include_all', 'true')); | ||
} | ||
|
||
|
||
var PGIConfig = new Config(); | ||
const PGIConfig = new Config(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters