Sha256: 805bb0beb2c8161d8b6160d9a8a5fbca726598042401a76f8e1dffa9d81dabd1
Contents?: true
Size: 1.13 KB
Versions: 3
Compression:
Stored size: 1.13 KB
Contents
// Simple storage plugin // Written by Daniel Mendler (function($) { var storage = {}, data = {}; try { if (window.localStorage) { storage = window.localStorage; } if (storage.oleloStorage) { data = JSON.parse(storage.oleloStorage); } } catch (e) { // Firefox fails when touching localStorage/globalStorage and cookies are disabled } function checkKey(key) { if (typeof(key) != 'string' && typeof(key) != 'number') { throw new TypeError('Key name must be string or numeric'); } } function save() { try { storage.oleloStorage = JSON.stringify(data); } catch (e) { // probably cache is full, nothing is saved this way } } $.storage = { set: function(key, value){ checkKey(key); data[key] = value; save(); return value; }, get: function(key, def){ checkKey(key); if (key in data) { return data[key]; } return typeof(def) == 'undefined' ? null : def; }, remove: function(key){ checkKey(key); if (key in data){ delete data[key]; save(); return true; } return false; } }; })(jQuery);
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
olelo-0.9.6 | static/script/09-olelo.storage.js |
olelo-0.9.5 | static/script/09-olelo.storage.js |
olelo-0.9.4 | static/script/02-olelo.storage.js |