news/plugins/admin/themes/grav/app/utils/storage.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

// localStorage
(function() {
function isSupported() {
var item = 'localStoragePollyfill';
try {
localStorage.setItem(item, item);
localStorage.removeItem(item);
sessionStorage.setItem(item, item);
sessionStorage.removeItem(item);
return true;
} catch (e) {
return false;
}
}
if (!isSupported()) {
try {
Storage.prototype._data = {};
Storage.prototype.setItem = function(id, val) {
this._data[id] = String(val);
return this._data[id];
};
Storage.prototype.getItem = function(id) {
return this._data.hasOwnProperty(id) ? this._data[id] : undefined;
};
Storage.prototype.removeItem = function(id) {
return delete this._data[id];
};
Storage.prototype.clear = function() {
this._data = {};
return this._data;
};
} catch (e) {
console.error('localStorage pollyfill error: ', e);
}
}
}());