kopia lustrzana https://github.com/miklobit/TiddlyWiki5
				
				
				
			DynaView: Suppress local storage errors
							rodzic
							
								
									fd8ede07bf
								
							
						
					
					
						commit
						a6500ba711
					
				|  | @ -31,6 +31,8 @@ var LOCAL_STORAGE_KEY_PREFIX = "tw5-dynaview-scroll-position#"; | |||
| 
 | ||||
| var hasRestoredScrollPosition = false; | ||||
| 
 | ||||
| var localStorageHasFailed = false; | ||||
| 
 | ||||
| exports.startup = function() { | ||||
| 	var topmost = null, lastScrollY; | ||||
| 	$tw.boot.disableStartupNavigation = true; | ||||
|  | @ -165,16 +167,18 @@ function updateAddressBar() { | |||
| } | ||||
| 
 | ||||
| function saveScrollPosition() { | ||||
| 	if(hasRestoredScrollPosition && $tw.wiki.getTiddlerText("$:/config/DynaView/RestoreScrollPositionAtStartup") === "yes") { | ||||
| 		var top = findTopmostTiddler(); | ||||
| 		if(top.element) { | ||||
| 			try { | ||||
| 				window.localStorage.setItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname,JSON.stringify({ | ||||
| 					title: top.title, | ||||
| 					offset: top.offset | ||||
| 				})); | ||||
| 			} catch(e) { | ||||
| 				console.log("Error setting local storage",e) | ||||
| 	if(!localStorageHasFailed) { | ||||
| 		if(hasRestoredScrollPosition && $tw.wiki.getTiddlerText("$:/config/DynaView/RestoreScrollPositionAtStartup") === "yes") { | ||||
| 			var top = findTopmostTiddler(); | ||||
| 			if(top.element) { | ||||
| 				try { | ||||
| 					window.localStorage.setItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname,JSON.stringify({ | ||||
| 						title: top.title, | ||||
| 						offset: top.offset | ||||
| 					})); | ||||
| 				} catch(e) { | ||||
| 					localStorageHasFailed = true; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | @ -182,11 +186,13 @@ function saveScrollPosition() { | |||
| 
 | ||||
| function restoreScrollPosition() { | ||||
| 	var json; | ||||
| 	try { | ||||
| 		json = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname)); | ||||
| 	} catch(e) { | ||||
| 		// Ignore errors
 | ||||
| 	}; | ||||
| 	if(!localStorageHasFailed) { | ||||
| 		try { | ||||
| 			json = JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_KEY_PREFIX + window.location.pathname)); | ||||
| 		} catch(e) { | ||||
| 			localStorageHasFailed = true; | ||||
| 		};		 | ||||
| 	} | ||||
| 	return json; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Jeremy Ruston
						Jeremy Ruston