mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-17 03:20:02 +00:00
DynaView: Suppress local storage errors
This commit is contained in:
parent
fd8ede07bf
commit
a6500ba711
@ -31,6 +31,8 @@ var LOCAL_STORAGE_KEY_PREFIX = "tw5-dynaview-scroll-position#";
|
|||||||
|
|
||||||
var hasRestoredScrollPosition = false;
|
var hasRestoredScrollPosition = false;
|
||||||
|
|
||||||
|
var localStorageHasFailed = false;
|
||||||
|
|
||||||
exports.startup = function() {
|
exports.startup = function() {
|
||||||
var topmost = null, lastScrollY;
|
var topmost = null, lastScrollY;
|
||||||
$tw.boot.disableStartupNavigation = true;
|
$tw.boot.disableStartupNavigation = true;
|
||||||
@ -165,16 +167,18 @@ function updateAddressBar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function saveScrollPosition() {
|
function saveScrollPosition() {
|
||||||
if(hasRestoredScrollPosition && $tw.wiki.getTiddlerText("$:/config/DynaView/RestoreScrollPositionAtStartup") === "yes") {
|
if(!localStorageHasFailed) {
|
||||||
var top = findTopmostTiddler();
|
if(hasRestoredScrollPosition && $tw.wiki.getTiddlerText("$:/config/DynaView/RestoreScrollPositionAtStartup") === "yes") {
|
||||||
if(top.element) {
|
var top = findTopmostTiddler();
|
||||||
try {
|
if(top.element) {
|
||||||
window.localStorage.setItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname,JSON.stringify({
|
try {
|
||||||
title: top.title,
|
window.localStorage.setItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname,JSON.stringify({
|
||||||
offset: top.offset
|
title: top.title,
|
||||||
}));
|
offset: top.offset
|
||||||
} catch(e) {
|
}));
|
||||||
console.log("Error setting local storage",e)
|
} catch(e) {
|
||||||
|
localStorageHasFailed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,11 +186,13 @@ function saveScrollPosition() {
|
|||||||
|
|
||||||
function restoreScrollPosition() {
|
function restoreScrollPosition() {
|
||||||
var json;
|
var json;
|
||||||
try {
|
if(!localStorageHasFailed) {
|
||||||
json = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname));
|
try {
|
||||||
} catch(e) {
|
json = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname));
|
||||||
// Ignore errors
|
} catch(e) {
|
||||||
};
|
localStorageHasFailed = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user