Skip to content

Commit d6f5d68

Browse files
authored
Merge pull request #454 from nickygerritsen/fix-local-storage-in-safari
Improve local storage check for Safari private mode
2 parents 8b3fa35 + 17240bb commit d6f5d68

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

webroot/js/toolbar-app.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Toolbar.prototype = {
1414
_currentPanel: null,
1515
_lastPanel: null,
1616
_state: 0,
17+
_localStorageAvailable: null,
1718
currentRequest: null,
1819
originalRequest: null,
1920
ajaxRequests: [],
@@ -43,15 +44,33 @@ Toolbar.prototype = {
4344
return this.state();
4445
},
4546

47+
localStorageAvailable: function() {
48+
if (this._localStorageAvailable === null) {
49+
if (!window.localStorage) {
50+
this._localStorageAvailable = false;
51+
} else {
52+
try {
53+
window.localStorage.setItem('testKey', '1');
54+
window.localStorage.removeItem('testKey');
55+
this._localStorageAvailable = true;
56+
} catch (error) {
57+
this._localStorageAvailable = false;
58+
}
59+
}
60+
}
61+
62+
return this._localStorageAvailable;
63+
},
64+
4665
saveState: function() {
47-
if (!window.localStorage) {
66+
if (!this.localStorageAvailable()) {
4867
return;
4968
}
5069
window.localStorage.setItem('toolbar_state', this._state);
5170
},
5271

5372
loadState: function() {
54-
if (!window.localStorage) {
73+
if (!this.localStorageAvailable()) {
5574
return;
5675
}
5776
var old = window.localStorage.getItem('toolbar_state');

0 commit comments

Comments
 (0)