diff options
author | Sam Potts <me@sampotts.me> | 2017-11-05 11:45:02 +1100 |
---|---|---|
committer | Sam Potts <me@sampotts.me> | 2017-11-05 11:45:02 +1100 |
commit | 1c693df00b44961674a35243f5172716a3735b71 (patch) | |
tree | 2df8dd8d252d1f80688cd3a3549de7374dca676c /src/js/storage.js | |
parent | 8aaa9320505baec3575bc1e92f37225729ee88f6 (diff) | |
download | plyr-1c693df00b44961674a35243f5172716a3735b71.tar.lz plyr-1c693df00b44961674a35243f5172716a3735b71.tar.xz plyr-1c693df00b44961674a35243f5172716a3735b71.zip |
src getter fix, local storage fix
Diffstat (limited to 'src/js/storage.js')
-rw-r--r-- | src/js/storage.js | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/js/storage.js b/src/js/storage.js index 0d6031be..ff4222ad 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -5,18 +5,37 @@ import support from './support'; import utils from './utils'; +// Get contents of local storage +function get() { + const store = window.localStorage.getItem(this.config.storage.key); + + if (utils.is.empty(store)) { + return {}; + } + + return JSON.parse(store); +} + // Save a value back to local storage -function set(value) { +function set(object) { // Bail if we don't have localStorage support or it's disabled if (!support.storage || !this.config.storage.enabled) { return; } + // Can only store objectst + if (!utils.is.object(object)) { + return; + } + + // Get current storage + const storage = get.call(this); + // Update the working copy of the values - utils.extend(this.storage, value); + utils.extend(storage, object); // Update storage - window.localStorage.setItem(this.config.storage.key, JSON.stringify(this.storage)); + window.localStorage.setItem(this.config.storage.key, JSON.stringify(storage)); } // Setup localStorage @@ -53,4 +72,4 @@ function setup() { return storage; } -export default { setup, set }; +export default { setup, set, get }; |