mirror of
				https://github.com/flynx/PortableMag.git
				synced 2025-10-31 03:50:16 +00:00 
			
		
		
		
	added page construction and moving + added more defaults to setCurrentPage(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									ca6302ae4b
								
							
						
					
					
						commit
						bac9d68f34
					
				| @ -47,6 +47,10 @@ $(document).ready(function(){ | ||||
| 		.on('bookmarkAdded', function(_, n){makeBookmarkIndicator(n)}) | ||||
| 		.on('bookmarkRemoved', function(_, n){removeBookmarkIndicator(n)}) | ||||
| 
 | ||||
| 		// editor specific events... | ||||
| 		.on('pageCreated articleCreated magazineCreated', resetNavigator) | ||||
| 		.on('pageMoved articleMoved', resetNavigator) | ||||
| 
 | ||||
| 		// user interactions... | ||||
| 		.swipe({ | ||||
| 			swipeStatus: swipeHandler, | ||||
| @ -170,7 +174,7 @@ CKEDITOR.on('instanceCreated', function(evt){ | ||||
| 
 | ||||
| 	<div class="top-toolbar"> | ||||
| 		<div class="left-set"> | ||||
| 			<div class="button cover title"><a href="#home">PortableMag</a></div> | ||||
| 			<div class="button cover title"><a href="#home">PortableMag Editor</a></div> | ||||
| 		</div> | ||||
| 		<div class="right-set"> | ||||
| 			<div class="button prev-bookmark"> | ||||
|  | ||||
							
								
								
									
										124
									
								
								magazine.js
									
									
									
									
									
								
							
							
						
						
									
										124
									
								
								magazine.js
									
									
									
									
									
								
							| @ -87,8 +87,13 @@ function getPageNumber(page){ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // NOTE: negative values will yield results from the tail...
 | ||||
| function getPageAt(n){ | ||||
| 	return $($('.page')[n]) | ||||
| 	var page = $('.page') | ||||
| 	if(n < 0){ | ||||
| 		n = page.length + n | ||||
| 	} | ||||
| 	return $(page[n]) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| @ -327,11 +332,36 @@ function fitNPages(n, fit_to_content){ | ||||
| // 		- page element
 | ||||
| // NOTE: this will fire a 'pageChanged(n)' event on the viewer each time 
 | ||||
| // 		it is called...
 | ||||
| // NOTE: this now supports negative indexes to count pages from the end...
 | ||||
| function setCurrentPage(n, offset, width){ | ||||
| 	var page = $('.page') | ||||
| 	if(n == null){ | ||||
| 		var cur = $('.current.page') | ||||
| 		n = $('.page').index(cur)  | ||||
| 		// no current page...
 | ||||
| 		// try to land on the magazine cover...
 | ||||
| 		if(cur.length == 0){ | ||||
| 			cur = $('.magazine > .cover') | ||||
| 		} | ||||
| 		// try the first cover...
 | ||||
| 		if(cur.length == 0){ | ||||
| 			cur = $('.cover.page') | ||||
| 		} | ||||
| 		// try first page...
 | ||||
| 		if(cur.length == 0){ | ||||
| 			cur = page.first() | ||||
| 		} | ||||
| 		// no pages to work with...
 | ||||
| 		if(cur.length == 0){ | ||||
| 			return | ||||
| 		} | ||||
| 		n = page.index(cur)  | ||||
| 	} else if(typeof(n) == typeof(1)) { | ||||
| 		// invalid n...
 | ||||
| 		if(n >= page.length){ | ||||
| 			n = page.length-1 | ||||
| 		} else if(-n > page.length){ | ||||
| 			n = 0 | ||||
| 		} | ||||
| 		var cur = getPageAt(n) | ||||
| 	} else { | ||||
| 		var cur = $(n) | ||||
| @ -575,6 +605,11 @@ function setupNavigator(){ | ||||
| 	}) | ||||
| 
 | ||||
| 	updateNavigator() | ||||
| 
 | ||||
| 	// need to reconstruct indicators...
 | ||||
| 	$('.magazine .page .bookmark').each(function(_, e){ | ||||
| 		makeBookmarkIndicator($(e).parents('.page')) | ||||
| 	}) | ||||
| 	 | ||||
| 	// setup event handlers...
 | ||||
| 	$('.viewer') | ||||
| @ -583,11 +618,17 @@ function setupNavigator(){ | ||||
| } | ||||
| 
 | ||||
| function clearNavigator(){ | ||||
| 	// XXX this needs to unbind events...
 | ||||
| 	$('.navigator .indicator').hide() | ||||
| 	clearBookmarkIndicators() | ||||
| 	clearArticleIndicators() | ||||
| } | ||||
| 
 | ||||
| function resetNavigator(){ | ||||
| 	clearNavigator() | ||||
| 	setupNavigator() | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| function updateNavigator(n){ | ||||
| 	var mag = $('.magazine') | ||||
| @ -854,7 +895,10 @@ function createMagazine(){ | ||||
| // XXX create article (magazine, title, position)...
 | ||||
| // 		- article
 | ||||
| // 		- cover
 | ||||
| function createArticle(magazine, title){ | ||||
| function createArticleBefore(article, title){ | ||||
| 	// XXX
 | ||||
| } | ||||
| function createArticleAfter(article, title){ | ||||
| 	// XXX
 | ||||
| } | ||||
| 
 | ||||
| @ -862,8 +906,80 @@ function createArticle(magazine, title){ | ||||
| // XXX create page (article, template, position)...
 | ||||
| // 		- page
 | ||||
| // 		- content
 | ||||
| function createPage(article, template){ | ||||
| function createPageIn(article, template){ | ||||
| 	// XXX
 | ||||
| 	$('.viewer').trigger('pageCreated', res) | ||||
| } | ||||
| // XXX the next two are almost identical...
 | ||||
| // XXX prevent this from working outside of an article....
 | ||||
| function createPageAfter(page, template){ | ||||
| 	if(page == null){ | ||||
| 		page = $('.current.page') | ||||
| 	} | ||||
| 
 | ||||
| 	var res = $('<div/>') | ||||
| 		.addClass('page') | ||||
| 		.append($('<div/>') | ||||
| 				.addClass('content') | ||||
| 				.text('Page')) | ||||
| 		.insertAfter(page) | ||||
| 
 | ||||
| 	$('.viewer').trigger('pageCreated', res) | ||||
| 
 | ||||
| 	return res | ||||
| } | ||||
| // XXX prevent this from working outside of an article....
 | ||||
| function createPageBefore(page, template){ | ||||
| 	if(page == null){ | ||||
| 		page = $('.current.page') | ||||
| 	} | ||||
| 
 | ||||
| 	var res = $('<div/>') | ||||
| 		.addClass('page') | ||||
| 		.append($('<div/>') | ||||
| 				.addClass('content') | ||||
| 				.text('Page')) | ||||
| 		.insertBefore(page) | ||||
| 
 | ||||
| 	$('.viewer').trigger('pageCreated', res) | ||||
| 
 | ||||
| 	return res | ||||
| } | ||||
| // XXX make this push pages between articles...
 | ||||
| function pushPageLeft(page){ | ||||
| 	if(page == null){ | ||||
| 		page = $('.current.page') | ||||
| 	} | ||||
| 	var prev = page.prev() | ||||
| 	if(prev.length == 0){ | ||||
| 		return page | ||||
| 	} | ||||
| 	page | ||||
| 		.detach() | ||||
| 		.insertBefore(prev) | ||||
| 	setCurrentPage() | ||||
| 
 | ||||
| 	$('.viewer').trigger('pageMoved', page) | ||||
| 
 | ||||
| 	return page | ||||
| } | ||||
| // XXX make this push pages between articles...
 | ||||
| function pushPageRight(page){ | ||||
| 	if(page == null){ | ||||
| 		page = $('.current.page') | ||||
| 	} | ||||
| 	var next = page.next() | ||||
| 	if(next.length == 0){ | ||||
| 		return page | ||||
| 	} | ||||
| 	page | ||||
| 		.detach() | ||||
| 		.insertAfter(next) | ||||
| 	setCurrentPage() | ||||
| 
 | ||||
| 	$('.viewer').trigger('pageMoved', page) | ||||
| 
 | ||||
| 	return page | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user