mirror of
				https://github.com/flynx/PortableMag.git
				synced 2025-10-31 12:00:11 +00:00 
			
		
		
		
	some refactoring and cleaning, history still is broken...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									cb8c260784
								
							
						
					
					
						commit
						f2a034120f
					
				
							
								
								
									
										59
									
								
								magazine.js
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								magazine.js
									
									
									
									
									
								
							| @ -31,7 +31,6 @@ var USE_REAL_PAGE_SIZES = false | |||||||
| // if true this will make each page flip update the hash url...
 | // if true this will make each page flip update the hash url...
 | ||||||
| // if false, only direct linking will update the url.
 | // if false, only direct linking will update the url.
 | ||||||
| // NOTE: this can slow down navigation...
 | // NOTE: this can slow down navigation...
 | ||||||
| // XXX BUG this if false, will break the layer hide/show toggle...
 |  | ||||||
| var UPDATE_HASH_URL_POSITION = false | var UPDATE_HASH_URL_POSITION = false | ||||||
| 
 | 
 | ||||||
| // if true this will enable history for local page navigation regardless
 | // if true this will enable history for local page navigation regardless
 | ||||||
| @ -116,10 +115,33 @@ function getPageAt(n){ | |||||||
| /************************************************** event handlers ***/ | /************************************************** event handlers ***/ | ||||||
| 
 | 
 | ||||||
| // #URL handler...
 | // #URL handler...
 | ||||||
|  | var RELATIVE_URLS = [ | ||||||
|  | 	'back', 'forward', | ||||||
|  | 	'next', 'prev', | ||||||
|  | 	'nextArticle', 'prevArticle', | ||||||
|  | 	'nextBookmark', 'prevBookmark', | ||||||
|  | 	'bookmark', | ||||||
|  | 	'hideLayers' | ||||||
|  | ] | ||||||
| // NOTE: most of the handling actually happens in loadURLState...
 | // NOTE: most of the handling actually happens in loadURLState...
 | ||||||
| function hashChangeHandler(e){ | function hashChangeHandler(e){ | ||||||
| 	e.preventDefault() | 	e.preventDefault() | ||||||
|  | 
 | ||||||
|  | 	var anchor = window.location.hash.split('#')[1] | ||||||
|  | 
 | ||||||
|  | 	// skip empty #URL...
 | ||||||
|  | 	if(anchor == ''){ | ||||||
|  | 		return false | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	var r = loadURLState() | 	var r = loadURLState() | ||||||
|  | 	var n = getPageNumber() | ||||||
|  | 
 | ||||||
|  | 	// for relative #URLs remove them from hash...
 | ||||||
|  | 	if(RELATIVE_URLS.indexOf(anchor) >= 0 && !UPDATE_HASH_URL_POSITION){ | ||||||
|  | 		window.location.hash = '' | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	// if we are dealing with history actions the browser will 
 | 	// if we are dealing with history actions the browser will 
 | ||||||
| 	// do the work for us...
 | 	// do the work for us...
 | ||||||
| 	if(r == 'back'){ | 	if(r == 'back'){ | ||||||
| @ -127,7 +149,18 @@ function hashChangeHandler(e){ | |||||||
| 		window.history.go(-2) | 		window.history.go(-2) | ||||||
| 	} else if(r == 'forward'){ | 	} else if(r == 'forward'){ | ||||||
| 		window.history.go(2) | 		window.history.go(2) | ||||||
| 	} else { | 	} else if(r != n){ | ||||||
|  | 
 | ||||||
|  | 		/* XXX this will put this into an endless loop... | ||||||
|  | 		 * 		...mainly because it changes the #URL from within the handler | ||||||
|  | 		if(!UPDATE_HASH_URL_POSITION){ | ||||||
|  | 			// push current position...
 | ||||||
|  | 			// NOTE: this will enable partial history navigation, but only 
 | ||||||
|  | 			// 		on actions envolving actual links...
 | ||||||
|  | 			window.history.pushState(null, null, '#' + getPageNumber()) | ||||||
|  | 		} | ||||||
|  | 		*/ | ||||||
|  | 
 | ||||||
| 		setCurrentPage(r) | 		setCurrentPage(r) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @ -598,15 +631,9 @@ function prevBookmark(){ | |||||||
| // 			$('[title="<magazine>"] [name="<name>"]')
 | // 			$('[title="<magazine>"] [name="<name>"]')
 | ||||||
| // XXX BUG: if the hash url part coresponds to a real anchor the browser 
 | // XXX BUG: if the hash url part coresponds to a real anchor the browser 
 | ||||||
| // 		shifts the page, need to disable this...
 | // 		shifts the page, need to disable this...
 | ||||||
| var RELATIVE_URLS = [ |  | ||||||
| 	'back', 'forward', |  | ||||||
| 	'next', 'prev', |  | ||||||
| 	'nextArticle', 'prevArticle', |  | ||||||
| 	'nextBookmark', 'prevBookmark', |  | ||||||
| 	'bookmark', |  | ||||||
| 	'hideLayers' |  | ||||||
| ] |  | ||||||
| // URL state managers...
 | // URL state managers...
 | ||||||
|  | // NOTE: loadURLState will have no side-effects on the URL, it will just 
 | ||||||
|  | // 		get the state from the URL and return it.
 | ||||||
| function loadURLState(){ | function loadURLState(){ | ||||||
| 	if(window.location.hash == ''){ | 	if(window.location.hash == ''){ | ||||||
| 		return null | 		return null | ||||||
| @ -617,11 +644,6 @@ function loadURLState(){ | |||||||
| 		return n | 		return n | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// for relative #URLs remove them from hash...
 |  | ||||||
| 	if(RELATIVE_URLS.indexOf(anchor) >= 0 && !UPDATE_HASH_URL_POSITION){ |  | ||||||
| 		window.location.hash = '' |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// XXX add real external aliases...
 | 	// XXX add real external aliases...
 | ||||||
| 	if(anchor == 'thumbnails') { | 	if(anchor == 'thumbnails') { | ||||||
| 		togglePageView('off') | 		togglePageView('off') | ||||||
| @ -689,15 +711,10 @@ function loadURLState(){ | |||||||
| 				.addClass('hidden') | 				.addClass('hidden') | ||||||
| 				.removeClass('shown') | 				.removeClass('shown') | ||||||
| 		} | 		} | ||||||
| 		if(!UPDATE_HASH_URL_POSITION){ |  | ||||||
| 			// push current position...
 |  | ||||||
| 			// NOTE: this will enable partial history navigation, but only 
 |  | ||||||
| 			// 		on actions envolving actual links...
 |  | ||||||
| 			window.history.pushState(null, null, '#' + getPageNumber()) |  | ||||||
| 		} |  | ||||||
| 		return n | 		return n | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | // save current state to URL...
 | ||||||
| function saveURLState(){ | function saveURLState(){ | ||||||
| 	var anchor = window.location.hash.split('#')[1] | 	var anchor = window.location.hash.split('#')[1] | ||||||
| 	var elem = $('[name='+anchor+']') | 	var elem = $('[name='+anchor+']') | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user