jellyfin-web/dashboard-ui/apiclient/store.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-10-27 14:45:50 -07:00
(function (globalScope, localStorage, sessionStorage) {
2014-10-23 21:54:35 -07:00
function myStore(defaultObject) {
var self = this;
self.localData = {};
var isDefaultAvailable;
if (defaultObject) {
try {
defaultObject.setItem('_test', '0');
isDefaultAvailable = true;
} catch (e) {
}
}
self.setItem = function (name, value) {
if (isDefaultAvailable) {
defaultObject.setItem(name, value);
} else {
self.localData[name] = value;
}
};
self.getItem = function (name) {
if (isDefaultAvailable) {
return defaultObject.getItem(name);
}
return self.localData[name];
};
self.removeItem = function (name) {
if (isDefaultAvailable) {
defaultObject.removeItem(name);
} else {
self.localData[name] = null;
}
};
}
2015-05-20 10:29:26 -07:00
globalScope.appStorage = new myStore(localStorage);
2014-10-27 14:45:50 -07:00
globalScope.sessionStore = new myStore(sessionStorage);
2014-10-23 21:54:35 -07:00
2014-10-27 14:45:50 -07:00
})(window, window.localStorage, window.sessionStorage);