mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
create localStorage abstraction
This commit is contained in:
parent
ecba850f43
commit
c5a40e9616
19 changed files with 138 additions and 103 deletions
|
@ -1,25 +1,4 @@
|
|||
function IsStorageEnabled(skipRetry) {
|
||||
|
||||
if (!window.localStorage) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
window.localStorage.setItem("__test", "data");
|
||||
} catch (err) {
|
||||
|
||||
if (!skipRetry) {
|
||||
if ((err.name).toUpperCase().indexOf('EXCEEDED') != -1) {
|
||||
window.localStorage.clear();
|
||||
return IsStorageEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function htmlEncode(value) {
|
||||
function htmlEncode(value) {
|
||||
//create a in-memory div, set it's inner text(which jQuery automatically encodes)
|
||||
//then grab the encoded contents back out. The div never exists on the page.
|
||||
return $('<div/>').text(value).html();
|
||||
|
@ -539,4 +518,44 @@ function ticks_to_human(str) {
|
|||
}
|
||||
};
|
||||
|
||||
})(window);
|
||||
|
||||
(function (window) {
|
||||
|
||||
function myStore(defaultObject) {
|
||||
|
||||
var self = this;
|
||||
self.localData = {};
|
||||
|
||||
self.setItem = function (name, value) {
|
||||
|
||||
if (defaultObject) {
|
||||
defaultObject.setItem(name, value);
|
||||
} else {
|
||||
self.localData[name] = value;
|
||||
}
|
||||
};
|
||||
|
||||
self.getItem = function (name) {
|
||||
|
||||
if (defaultObject) {
|
||||
return defaultObject.getItem(name);
|
||||
}
|
||||
|
||||
return self.localData[name];
|
||||
};
|
||||
|
||||
self.removeItem = function (name) {
|
||||
|
||||
if (defaultObject) {
|
||||
defaultObject.removeItem(name);
|
||||
} else {
|
||||
self.localData[name] = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
window.store = new myStore(window.localStorage);
|
||||
window.sessionStore = new myStore(window.sessionStorage);
|
||||
|
||||
})(window);
|
Loading…
Add table
Add a link
Reference in a new issue