| 
									
										
										
										
											2013-02-02 07:35:17 +04:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * Magazine editor actions | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2013-02-08 21:04:00 +04:00
										 |  |  | * XXX do a generic shift left/right add/remove set of function and build | 
					
						
							|  |  |  | * 		selectors around them... | 
					
						
							| 
									
										
										
										
											2013-02-02 07:35:17 +04:00
										 |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-08 21:04:00 +04:00
										 |  |  | /********************************************************* generic ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // move element to target and atach it at position 
 | 
					
						
							|  |  |  | // position can be 'before', 'after' (default), 'prepend' or 'append'
 | 
					
						
							|  |  |  | function moveElementTo(elem, target, position){ | 
					
						
							|  |  |  | 	elem | 
					
						
							|  |  |  | 		.detach() | 
					
						
							| 
									
										
										
										
											2013-02-08 21:09:36 +04:00
										 |  |  | 		[position == 'before'? 'insertBefore' | 
					
						
							| 
									
										
										
										
											2013-02-08 21:04:00 +04:00
										 |  |  | 		: position == 'append'? 'appendTo' | 
					
						
							| 
									
										
										
										
											2013-02-08 21:09:36 +04:00
										 |  |  | 		: position == 'prepend'? 'prependTo' | 
					
						
							|  |  |  | 		// the default...
 | 
					
						
							|  |  |  | 		: 'insertAfter'](target) | 
					
						
							| 
									
										
										
										
											2013-02-08 21:04:00 +04:00
										 |  |  | 	return elem | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 07:35:17 +04:00
										 |  |  | /************************************************ editor: magazine ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NOTE: we do not need to create any event handlers here specifically 
 | 
					
						
							|  |  |  | // 		as all events are ahndled by the viewer...
 | 
					
						
							|  |  |  | function loadMagazine(mag, position, bookmarks){ | 
					
						
							|  |  |  | 	mag = loadMagazineData(mag) | 
					
						
							| 
									
										
										
										
											2013-02-02 08:36:54 +04:00
										 |  |  | 	loadMagazineUserData(position, bookmarks) | 
					
						
							| 
									
										
										
										
											2013-02-02 07:35:17 +04:00
										 |  |  | 	return mag | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NOTE: this will, in addition to the magazine itself, will populate with
 | 
					
						
							|  |  |  | // 		the basic content (cover, article, article cover)
 | 
					
						
							|  |  |  | function createBaseMagazine(title, cover, article){ | 
					
						
							|  |  |  | 	removeMagazine() | 
					
						
							| 
									
										
										
										
											2013-02-09 03:08:48 +04:00
										 |  |  | 	var mag = loadMagazine(createMagazine(title, cover, article), 0, []) | 
					
						
							| 
									
										
										
										
											2013-02-02 07:35:17 +04:00
										 |  |  | 	return mag | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /************************************************* editor: article ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function createArticleBefore(article, title){ | 
					
						
							|  |  |  | 	if(article == null){ | 
					
						
							|  |  |  | 		article = $('.current.page').parents('.article') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// XXX fill the data...
 | 
					
						
							|  |  |  | 	var res = createArticle().insertBefore(article) | 
					
						
							|  |  |  | 	setCurrentPage() | 
					
						
							|  |  |  | 	$('.viewer').trigger('articleCreated', res) | 
					
						
							|  |  |  | 	return res | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function createArticleAfter(article, title){ | 
					
						
							|  |  |  | 	if(article == null){ | 
					
						
							|  |  |  | 		article = $('.current.page').parents('.article') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// XXX fill the data...
 | 
					
						
							|  |  |  | 	var res = createArticle().insertAfter(article) | 
					
						
							|  |  |  | 	setCurrentPage() | 
					
						
							|  |  |  | 	$('.viewer').trigger('articleCreated', res) | 
					
						
							|  |  |  | 	return res | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX TEST!
 | 
					
						
							|  |  |  | function shiftArticleLeft(article){ | 
					
						
							|  |  |  | 	var articles = $('.article') | 
					
						
							|  |  |  | 	var i = articles.index(article) | 
					
						
							|  |  |  | 	if(i <= 0){ | 
					
						
							|  |  |  | 		return article | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var target = $(articles[i-1]) | 
					
						
							|  |  |  | 	article | 
					
						
							|  |  |  | 		.detach() | 
					
						
							|  |  |  | 		.insertBefore(target) | 
					
						
							|  |  |  | 	setCurrentPage() | 
					
						
							|  |  |  | 	$('.viewer').trigger('articleMoved', res) | 
					
						
							|  |  |  | 	return res | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | // XXX TEST!
 | 
					
						
							|  |  |  | function shiftArticleRight(article){ | 
					
						
							|  |  |  | 	var articles = $('.article') | 
					
						
							|  |  |  | 	var i = articles.index(article) | 
					
						
							|  |  |  | 	if(i >= articles.length){ | 
					
						
							|  |  |  | 		return article | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var target = $(articles[i+1]) | 
					
						
							|  |  |  | 	article | 
					
						
							|  |  |  | 		.detach() | 
					
						
							|  |  |  | 		.insertAfter(target) | 
					
						
							|  |  |  | 	setCurrentPage() | 
					
						
							|  |  |  | 	$('.viewer').trigger('articleMoved', res) | 
					
						
							|  |  |  | 	return res | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function removeArticle(article){ | 
					
						
							|  |  |  | 	if(article == null){ | 
					
						
							|  |  |  | 		article = $('.current.page').parents('.article') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	article.remove() | 
					
						
							|  |  |  | 	setCurrentPage() | 
					
						
							|  |  |  | 	$('.viewer').trigger('articleRemoved', res) | 
					
						
							|  |  |  | 	return res | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*************************************************** editor: pages ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function createPageIn(article, template){ | 
					
						
							|  |  |  | 	if(article == null){ | 
					
						
							|  |  |  | 		article = $('.current.page').parents('.article') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// no article
 | 
					
						
							|  |  |  | 	if(article.length == 0){ | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var res = createPage(template).appendTo(article) | 
					
						
							|  |  |  | 	$('.viewer').trigger('pageCreated', res) | 
					
						
							|  |  |  | 	return 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 = createPage(template).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 = createPage(template).insertBefore(page) | 
					
						
							|  |  |  | 	$('.viewer').trigger('pageCreated', res) | 
					
						
							|  |  |  | 	return res | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NOTE: on negative position this will position the element after the 
 | 
					
						
							|  |  |  | // 		target, e.g. position -1 is the last element, etc.
 | 
					
						
							|  |  |  | // XXX at this point there is no way to move something to either an 
 | 
					
						
							|  |  |  | // 		article or a magazine that do not contain any pages directly...
 | 
					
						
							|  |  |  | // 		...add special cases:
 | 
					
						
							|  |  |  | // 			- if we are moving the page in the direction of an empty article
 | 
					
						
							|  |  |  | // 			  push the page into the article...
 | 
					
						
							|  |  |  | // 			- if we are moving page 0 left and the magazine has no cover 
 | 
					
						
							|  |  |  | // 			  push it to the magazine...
 | 
					
						
							|  |  |  | function movePageTo(page, position){ | 
					
						
							|  |  |  | 	if(page == null){ | 
					
						
							|  |  |  | 		page = $('.current.page') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if(position >= $('.page').length){ | 
					
						
							|  |  |  | 		position = -1 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var target = getPageAt(position) | 
					
						
							|  |  |  | 	page.detach() | 
					
						
							|  |  |  | 	if(position >= 0){ | 
					
						
							|  |  |  | 			page.insertBefore(target) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 			page.insertAfter(target) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-03-03 01:18:09 +04:00
										 |  |  | 	setCurrentPage(page) | 
					
						
							| 
									
										
										
										
											2013-02-02 07:35:17 +04:00
										 |  |  | 	$('.viewer').trigger('pageMoved', page) | 
					
						
							|  |  |  | 	return page | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function shiftPageLeft(page){ | 
					
						
							|  |  |  | 	if(page == null){ | 
					
						
							|  |  |  | 		page = $('.current.page') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	movePageTo(page, getPageNumber(page)-1) | 
					
						
							|  |  |  | 	return page | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function shiftPageRight(page){ | 
					
						
							|  |  |  | 	if(page == null){ | 
					
						
							|  |  |  | 		page = $('.current.page') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	movePageTo(page, getPageNumber(page)+2) | 
					
						
							|  |  |  | 	return page | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function removePage(page){ | 
					
						
							|  |  |  | 	if(page == null){ | 
					
						
							|  |  |  | 		page = $('.current.page') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var cur = getPageNumber() | 
					
						
							|  |  |  | 	page.remove() | 
					
						
							|  |  |  | 	setCurrentPage(cur) | 
					
						
							|  |  |  | 	$('.viewer').trigger('pageRemoved', page) | 
					
						
							|  |  |  | 	return page | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | // XXX this needs revision...
 | 
					
						
							|  |  |  | // XXX need to split this into more generic parts...
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-09 17:51:32 +04:00
										 |  |  | // XXX STUB
 | 
					
						
							| 
									
										
										
										
											2013-03-10 04:58:10 +04:00
										 |  |  | function _finalize(n){ | 
					
						
							| 
									
										
										
										
											2013-03-09 17:51:32 +04:00
										 |  |  | 	refreshInlineEditor() | 
					
						
							| 
									
										
										
										
											2013-03-10 04:58:10 +04:00
										 |  |  | 	setCurrentPage(n) | 
					
						
							| 
									
										
										
										
											2013-03-09 17:51:32 +04:00
										 |  |  | 	removeOverlay() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function addPage(direction){ | 
					
						
							|  |  |  | 	var n = getPageNumber() | 
					
						
							| 
									
										
										
										
											2013-03-10 04:58:10 +04:00
										 |  |  | 	n = direction == 'before'? n : n+1 | 
					
						
							| 
									
										
										
										
											2013-03-09 17:51:32 +04:00
										 |  |  | 	return function(){ | 
					
						
							|  |  |  | 		showInOverlay($( | 
					
						
							|  |  |  | 			'<div>'+ | 
					
						
							|  |  |  | 				'<h1>Templates</h1>'+ | 
					
						
							| 
									
										
										
										
											2013-03-10 04:58:10 +04:00
										 |  |  | 				'<a href="javascript:$(\'.current.page\').'+direction+'(RawPage());_finalize('+n+')"><h3>Raw Page</h3></a>'+ | 
					
						
							|  |  |  | 				'<a href="javascript:$(\'.current.page\').'+direction+'(TextPage());_finalize('+n+')"><h3>Text Page</h3></a>'+ | 
					
						
							|  |  |  | 				'<a href="javascript:$(\'.current.page\').'+direction+'(CaptionPage());_finalize('+n+')"><h3>Caption Page</h3></a>'+ | 
					
						
							|  |  |  | 				'<a href="javascript:$(\'.current.page\').'+direction+'(ImagePage());_finalize('+n+')"><h3>Image Page</h3></a>'+ | 
					
						
							|  |  |  | 				'<a href="javascript:$(\'.current.page\').'+direction+'(ImageFitHeightPage());_finalize('+n+'))"><h3>Vertical Image Page</h3></a>'+ | 
					
						
							| 
									
										
										
										
											2013-03-09 17:51:32 +04:00
										 |  |  | 			'</div>')) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | function setupEditorToolbars(){ | 
					
						
							|  |  |  | 	var indicator = $('<div class="current-page-indicator"/>') | 
					
						
							|  |  |  | 			.appendTo($('.magazine')) | 
					
						
							|  |  |  | 			.click(function(){ | 
					
						
							|  |  |  | 				// NOTE: this does the same thing as handleClick...
 | 
					
						
							|  |  |  | 				togglePageView('on') | 
					
						
							| 
									
										
										
										
											2013-03-06 05:32:49 +04:00
										 |  |  | 				// XXX for some reason this does not work...
 | 
					
						
							|  |  |  | 				setCurrentPage() | 
					
						
							|  |  |  | 				setTransitionEasing($('.magazien'), 'cubic-bezier(0.33,0.66,0.66,1)') | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 			}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// the toolbars...
 | 
					
						
							|  |  |  | 	var left_bar = $('<div class="left-toolbar"/>') | 
					
						
							|  |  |  | 			.appendTo(indicator) | 
					
						
							|  |  |  | 	var right_bar = $('<div class="right-toolbar"/>') | 
					
						
							|  |  |  | 			.appendTo(indicator) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$('<button class="button remove">×</button>') | 
					
						
							| 
									
										
										
										
											2013-03-07 04:12:19 +04:00
										 |  |  | 		.attr('title', 'Remove') | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 		.appendTo(indicator) | 
					
						
							|  |  |  | 		.click(function(){ | 
					
						
							|  |  |  | 			setTransitionDuration($('.magazine'), 0) | 
					
						
							|  |  |  | 			removePage() | 
					
						
							|  |  |  | 			runMagazineTemplates() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return false | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$('<button class="button shift">></button>') | 
					
						
							| 
									
										
										
										
											2013-03-07 04:12:19 +04:00
										 |  |  | 		.attr('title', 'Move (w. Shift - Clone)') | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 		.appendTo(right_bar) | 
					
						
							|  |  |  | 		.click(function(){ | 
					
						
							| 
									
										
										
										
											2013-03-07 04:12:19 +04:00
										 |  |  | 			// if shift is pressed duplicate current page...
 | 
					
						
							|  |  |  | 			if(event.shiftKey){ | 
					
						
							|  |  |  | 				var n = getPageNumber() | 
					
						
							|  |  |  | 				setTransitionDuration($('.magazine'), 0) | 
					
						
							|  |  |  | 				$('.current.page') | 
					
						
							|  |  |  | 					.clone(true, true) | 
					
						
							|  |  |  | 					.removeClass('current') | 
					
						
							|  |  |  | 					.insertAfter($('.current.page')) | 
					
						
							|  |  |  | 				setCurrentPage(n) | 
					
						
							|  |  |  | 			// simply move...
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				shiftPageRight() | 
					
						
							|  |  |  | 				runMagazineTemplates() | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 			return false | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	$('<button class="button add">+</button>') | 
					
						
							| 
									
										
										
										
											2013-03-07 04:12:19 +04:00
										 |  |  | 		.attr('title', 'New page') | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 		.appendTo(right_bar) | 
					
						
							|  |  |  | 		.click(function(){ | 
					
						
							| 
									
										
										
										
											2013-03-09 17:51:32 +04:00
										 |  |  | 			addPage('after')() | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 			return false | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$('<button class="button shift"><</button>') | 
					
						
							| 
									
										
										
										
											2013-03-07 04:12:19 +04:00
										 |  |  | 		.attr('title', 'Move (w. Shift - Clone)') | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 		.appendTo(left_bar) | 
					
						
							|  |  |  | 		.click(function(){ | 
					
						
							| 
									
										
										
										
											2013-03-07 04:12:19 +04:00
										 |  |  | 			// if shift is pressed duplicate current page...
 | 
					
						
							|  |  |  | 			if(event.shiftKey){ | 
					
						
							|  |  |  | 				var n = getPageNumber() | 
					
						
							|  |  |  | 				setTransitionDuration($('.magazine'), 0) | 
					
						
							|  |  |  | 				$('.current.page') | 
					
						
							|  |  |  | 					.clone(true, true) | 
					
						
							|  |  |  | 					.removeClass('current') | 
					
						
							|  |  |  | 					.insertBefore($('.current.page')) | 
					
						
							|  |  |  | 				setCurrentPage(n+1) | 
					
						
							|  |  |  | 			// simply move...
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				shiftPageLeft() | 
					
						
							|  |  |  | 				runMagazineTemplates() | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 			return false | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	$('<button class="button add">+</button>') | 
					
						
							| 
									
										
										
										
											2013-03-07 04:12:19 +04:00
										 |  |  | 		.attr('title', 'New page') | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 		.appendTo(left_bar) | 
					
						
							|  |  |  | 		.click(function(){ | 
					
						
							| 
									
										
										
										
											2013-03-09 17:51:32 +04:00
										 |  |  | 			addPage('before')() | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 			return false | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$('<div class="editor-status">Editor Mode</div>') | 
					
						
							|  |  |  | 		.appendTo($('.chrome')) | 
					
						
							|  |  |  | 		.click(function(){ | 
					
						
							|  |  |  | 			toggleEditor('off') | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function clearEditorToolbars(){ | 
					
						
							|  |  |  | 	var indicator = $('.current-page-indicator').remove() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // general editor mode...
 | 
					
						
							|  |  |  | var toggleEditor = createCSSClassToggler( | 
					
						
							|  |  |  | 	'.chrome',  | 
					
						
							|  |  |  | 	'editor',  | 
					
						
							|  |  |  | 	function(){ | 
					
						
							|  |  |  | 		setTransitionDuration($('.magazine'), 0) | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	function(action){ | 
					
						
							|  |  |  | 		if(action == 'on'){ | 
					
						
							|  |  |  | 			// make editable fields editable...
 | 
					
						
							|  |  |  | 			if(togglePageView('?') == 'on'){ | 
					
						
							|  |  |  | 				toggleInlineEditor('on') | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			toggleInlineEditor('off') | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		setCurrentPage($('.current.page')) | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | // inline editor switcher...
 | 
					
						
							|  |  |  | var toggleInlineEditor = createCSSClassToggler( | 
					
						
							|  |  |  | 	'.chrome', | 
					
						
							|  |  |  | 	'inline-edior', | 
					
						
							|  |  |  | 	function(action){ | 
					
						
							|  |  |  | 		// prevent switching on while not in editor mode...
 | 
					
						
							|  |  |  | 		if(toggleEditor('?') == 'off' && action == 'on'){ | 
					
						
							|  |  |  | 			return false | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	function(action){ | 
					
						
							|  |  |  | 		if(action == 'on'){ | 
					
						
							|  |  |  | 			MagazineScroller.stop() | 
					
						
							| 
									
										
										
										
											2013-03-09 17:19:24 +04:00
										 |  |  | 			$('[contenteditable]') | 
					
						
							|  |  |  | 				.attr({contenteditable: 'true'}) | 
					
						
							|  |  |  | 				// setup focus/blur events for [contenteditable] elements...
 | 
					
						
							|  |  |  | 				// XXX might get a tad slow...
 | 
					
						
							|  |  |  | 				.on('focus', handleEditableFocus) | 
					
						
							|  |  |  | 				.on('blur', handleEditableBlur)  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 			// ckeditor...
 | 
					
						
							|  |  |  | 			if(window.CKEDITOR){ | 
					
						
							|  |  |  | 				CKEDITOR.inlineAll() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$('[contenteditable]') | 
					
						
							|  |  |  | 				.blur() | 
					
						
							|  |  |  | 				.attr({contenteditable: 'false'}) | 
					
						
							| 
									
										
										
										
											2013-03-09 17:19:24 +04:00
										 |  |  | 				// remove handlers...
 | 
					
						
							|  |  |  | 				// XXX might get a tad slow...
 | 
					
						
							|  |  |  | 				.off('focus', handleEditableFocus) | 
					
						
							|  |  |  | 				.off('blur', handleEditableBlur)  | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 			MagazineScroller.start() | 
					
						
							|  |  |  | 			// ckeditor...
 | 
					
						
							|  |  |  | 			if(window.CKEDITOR){ | 
					
						
							|  |  |  | 				for( var i in CKEDITOR.instances){ | 
					
						
							|  |  |  | 					CKEDITOR.instances[i].destroy() | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2013-03-09 17:19:24 +04:00
										 |  |  | // XXX is this good?
 | 
					
						
							|  |  |  | function refreshInlineEditor(){ | 
					
						
							|  |  |  | 	toggleInlineEditor() | 
					
						
							|  |  |  | 	toggleInlineEditor() | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-03-08 23:47:20 +04:00
										 |  |  | var toggleInlineEditorMode = createCSSClassToggler('.chrome', 'inline-editor-mode') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-09 17:19:24 +04:00
										 |  |  | // XXX move these to the handler...
 | 
					
						
							|  |  |  | function handleEditableFocus(){ | 
					
						
							|  |  |  | 	if(toggleInlineEditor('?') == 'off'){ | 
					
						
							|  |  |  | 		$(':focus').blur() | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		toggleInlineEditorMode('on') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function handleEditableBlur(){ | 
					
						
							|  |  |  | 	toggleInlineEditorMode('off') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 03:55:14 +04:00
										 |  |  | // this will set up the main editor event handlers and data...
 | 
					
						
							| 
									
										
										
										
											2013-03-05 03:47:20 +04:00
										 |  |  | function setupEditor(){ | 
					
						
							|  |  |  | 	$('.viewer') | 
					
						
							|  |  |  | 		// move the page indicator...
 | 
					
						
							|  |  |  | 		// NOTE: this is to be used for page-specific toolbars etc.
 | 
					
						
							|  |  |  | 		.on('pageChanged', function(){ | 
					
						
							|  |  |  | 			var cur = $('.current.page') | 
					
						
							|  |  |  | 			var indicator = $('.current-page-indicator') | 
					
						
							|  |  |  | 			var shift = getElementShift($('.magazine')) | 
					
						
							|  |  |  | 			// XXX this is a stub...
 | 
					
						
							|  |  |  | 			// reverse the align...
 | 
					
						
							|  |  |  | 			indicator | 
					
						
							|  |  |  | 				.width(cur.width()) | 
					
						
							|  |  |  | 				.height(cur.height()) | 
					
						
							|  |  |  | 				.css({ | 
					
						
							|  |  |  | 					left: getPageInMagazineOffset(cur), | 
					
						
							|  |  |  | 					top: 0, | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 		// switch between editor modes...
 | 
					
						
							|  |  |  | 		.on('fullScreenMode', function(){ | 
					
						
							|  |  |  | 			$(':focus').blur() | 
					
						
							|  |  |  | 			if(toggleEditor('?') == 'on'){ | 
					
						
							|  |  |  | 				toggleInlineEditor('on') | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 		.on('ribbonMode', function(){ | 
					
						
							|  |  |  | 			$(':focus').blur() | 
					
						
							|  |  |  | 			if(toggleEditor('?') == 'on'){ | 
					
						
							|  |  |  | 				toggleInlineEditor('off') | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	setupEditorToolbars() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :												 */ |