Check if localStorage is available (#388)

This commit is contained in:
Norbert Renner 2021-03-24 18:48:44 +01:00
parent 17bbef17bd
commit e9540170a7

View file

@ -4,7 +4,9 @@ BR.WhatsNew = {
self.dismissableMessage = new BR.Message('whats_new_message', { self.dismissableMessage = new BR.Message('whats_new_message', {
onClosed: function () { onClosed: function () {
document.getElementsByClassName('version')[0].classList.remove('version-new'); document.getElementsByClassName('version')[0].classList.remove('version-new');
localStorage.setItem('changelogVersion', self.getLatestVersion()); if (BR.Util.localStorageAvailable()) {
localStorage.setItem('changelogVersion', self.getLatestVersion());
}
// next time popup is open, by default we will see everything // next time popup is open, by default we will see everything
self.prepare(false); self.prepare(false);
}, },
@ -12,7 +14,7 @@ BR.WhatsNew = {
$('#whatsnew').on('shown.bs.modal', function () { $('#whatsnew').on('shown.bs.modal', function () {
self.dismissableMessage.hide(); self.dismissableMessage.hide();
}); });
if (!self.getCurrentVersion()) { if (!self.getCurrentVersion() && BR.Util.localStorageAvailable()) {
localStorage.setItem('changelogVersion', self.getLatestVersion()); localStorage.setItem('changelogVersion', self.getLatestVersion());
} }
self.prepare(self.hasNewVersions()); self.prepare(self.hasNewVersions());
@ -28,12 +30,12 @@ BR.WhatsNew = {
}, },
getCurrentVersion: function () { getCurrentVersion: function () {
if (!BR.Util.localStorageAvailable()) return null;
return localStorage.getItem('changelogVersion'); return localStorage.getItem('changelogVersion');
}, },
hasNewVersions: function () { hasNewVersions: function () {
if (!BR.Util.localStorageAvailable()) return false;
return this.getCurrentVersion() && this.getCurrentVersion() < this.getLatestVersion(); return this.getCurrentVersion() && this.getCurrentVersion() < this.getLatestVersion();
}, },