mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-03-29 00:00:33 -04:00
FIX: ensure we can write to the localStorage
This commit is contained in:
parent
a56e3ccea0
commit
cafff9bf01
2 changed files with 7 additions and 7 deletions
app/assets/javascripts/discourse/lib
|
@ -87,7 +87,7 @@ var initializeUngroupedIcons = function(){
|
|||
|
||||
try {
|
||||
if (localStorage && !localStorage.emojiUsage) { localStorage.emojiUsage = "{}"; }
|
||||
} catch(e){
|
||||
} catch (e) {
|
||||
/* localStorage can be disabled, or cookies disabled, do not crash script here
|
||||
* TODO introduce a global wrapper for dealing with local storage
|
||||
* */
|
||||
|
|
|
@ -5,13 +5,15 @@ try {
|
|||
safeLocalStorage = localStorage;
|
||||
if (localStorage["disableLocalStorage"] === "true") {
|
||||
safeLocalStorage = null;
|
||||
} else {
|
||||
// makes sure we can write to the local storage
|
||||
safeLocalStorage["safeLocalStorage"] = true;
|
||||
}
|
||||
} catch(e){
|
||||
} catch (e) {
|
||||
// cookies disabled, we don't care
|
||||
safeLocalStorage = null;
|
||||
}
|
||||
|
||||
|
||||
const KeyValueStore = function(ctx) {
|
||||
this.context = ctx;
|
||||
};
|
||||
|
@ -56,9 +58,8 @@ KeyValueStore.prototype = {
|
|||
|
||||
getObject(key) {
|
||||
if (!safeLocalStorage) { return null; }
|
||||
try {
|
||||
return JSON.parse(safeLocalStorage[this.context + key]);
|
||||
} catch(e) {}
|
||||
try { return JSON.parse(safeLocalStorage[this.context + key]); }
|
||||
catch (e) {}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -69,5 +70,4 @@ KeyValueStore.prototype.setItem = function(key, value) {
|
|||
this.set({ key, value });
|
||||
};
|
||||
|
||||
|
||||
export default KeyValueStore;
|
||||
|
|
Loading…
Add table
Reference in a new issue