mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-03-02 15:03:28 +00:00
if window.localStorage.config is null then JSON.parse returns an error about "u" not being valid (the word "undefined" is not valid JSON apparently :). So I test for null-ness first.
35 lines
783 B
JavaScript
35 lines
783 B
JavaScript
/**
|
|
* This object storing and retrieving configuration from HTML5 local storage.
|
|
* @module config/localStorage
|
|
*/
|
|
|
|
module.exports = LocalStorage;
|
|
|
|
/**
|
|
* @constructor
|
|
*/
|
|
function LocalStorage() {
|
|
}
|
|
|
|
/**
|
|
* Reads the config out of the HTML5 local storage
|
|
* and initializes the object config.
|
|
* if config is null the default config will be used
|
|
*/
|
|
LocalStorage.prototype.read = function () {
|
|
var raw = window.localStorage.getItem("config");
|
|
var cf = (raw === null ? null : JSON.parse(raw));
|
|
if (cf === null) {
|
|
this.config = this.default_config;
|
|
this.write();
|
|
} else
|
|
this.config = cf;
|
|
};
|
|
|
|
/**
|
|
* Writes the config to HTML5 local storage
|
|
*/
|
|
LocalStorage.prototype.write = function () {
|
|
window.localStorage.setItem("config", JSON.stringify(this.config));
|
|
};
|