add fallback localStorage implementation if not functional, #134
This commit is contained in:
parent
f06be982e7
commit
f0a0f40223
@ -7,7 +7,8 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",
|
|||||||
|
|
||||||
var Postbox = function(parent) {
|
var Postbox = function(parent) {
|
||||||
|
|
||||||
var el = $.htmlify(jade.render("postbox", {
|
var localStorage = utils.localStorageImpl,
|
||||||
|
el = $.htmlify(jade.render("postbox", {
|
||||||
"author": JSON.parse(localStorage.getItem("author")),
|
"author": JSON.parse(localStorage.getItem("author")),
|
||||||
"email": JSON.parse(localStorage.getItem("email")),
|
"email": JSON.parse(localStorage.getItem("email")),
|
||||||
"website": JSON.parse(localStorage.getItem("website"))
|
"website": JSON.parse(localStorage.getItem("website"))
|
||||||
|
@ -68,11 +68,34 @@ define(["app/i18n"], function(i18n) {
|
|||||||
.replace(/\n/gi, '<br>');
|
.replace(/\n/gi, '<br>');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Safari private browsing mode supports localStorage, but throws QUOTA_EXCEEDED_ERR
|
||||||
|
var localStorageImpl;
|
||||||
|
try {
|
||||||
|
localStorage.setItem("x", "y");
|
||||||
|
localStorage.removeItem("x");
|
||||||
|
localStorageImpl = localStorage;
|
||||||
|
} catch (ex) {
|
||||||
|
localStorageImpl = (function(storage) {
|
||||||
|
return {
|
||||||
|
setItem: function(key, val) {
|
||||||
|
storage[key] = val;
|
||||||
|
},
|
||||||
|
getItem: function(key) {
|
||||||
|
return typeof(storage[key]) !== 'undefined' ? storage[key] : null;
|
||||||
|
},
|
||||||
|
removeItem: function(key) {
|
||||||
|
delete storage[key];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})({});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cookie: cookie,
|
cookie: cookie,
|
||||||
pad: pad,
|
pad: pad,
|
||||||
ago: ago,
|
ago: ago,
|
||||||
text: text,
|
text: text,
|
||||||
detext: detext
|
detext: detext,
|
||||||
|
localStorageImpl: localStorageImpl
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user