Skip to content

Commit 0d41738

Browse files
Improve local storage check
1 parent 8b3fa35 commit 0d41738

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

webroot/js/toolbar-app.js

Lines changed: 24 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,36 @@ 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+
{
54+
window.localStorage.setItem('testKey', '1');
55+
window.localStorage.removeItem('testKey');
56+
this._localStorageAvailable = true;
57+
}
58+
catch (error)
59+
{
60+
this._localStorageAvailable = false;
61+
}
62+
}
63+
}
64+
65+
return this._localStorageAvailable;
66+
},
67+
4668
saveState: function() {
47-
if (!window.localStorage) {
69+
if (!this.localStorageAvailable()) {
4870
return;
4971
}
5072
window.localStorage.setItem('toolbar_state', this._state);
5173
},
5274

5375
loadState: function() {
54-
if (!window.localStorage) {
76+
if (!this.localStorageAvailable()) {
5577
return;
5678
}
5779
var old = window.localStorage.getItem('toolbar_state');

0 commit comments

Comments
 (0)