jellyfin-web/dashboard-ui/bower_components/emby-apiclient/appstorage.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-01-28 13:45:52 -07:00
define([], function () {
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');
2015-12-14 08:43:03 -07:00
defaultObject.removeItem('_test');
2014-10-23 21:54:35 -07:00
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;
}
};
}
2016-01-28 13:45:52 -07:00
try {
return new myStore(localStorage);
} catch (err) {
return new myStore();
}
});