| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | // XXX need a uniform way to address images (filename?)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:51:02 +04:00
										 |  |  | // XXX move this into the actual html...
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | $(document).ready(setup); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-18 19:24:01 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | /************************************************************ Setup **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setup(){ | 
					
						
							|  |  |  | 	// XXX load state...
 | 
					
						
							|  |  |  | 	// initial state (default)...
 | 
					
						
							|  |  |  | 	setDefaultInitialState() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// setup event handlers...
 | 
					
						
							|  |  |  | 	setupKeyboard() | 
					
						
							|  |  |  | 	setupGestures() | 
					
						
							|  |  |  | 	setupControlElements() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// load images...
 | 
					
						
							|  |  |  | 	// XXX not allowed...
 | 
					
						
							|  |  |  | 	//$.getJSON('images.js', loadImages})
 | 
					
						
							|  |  |  | 	// XXX STUB
 | 
					
						
							|  |  |  | 	loadImages(image_list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// set the default position and init...
 | 
					
						
							|  |  |  | 	$('.current-image').click() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setDefaultInitialState(){ | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	if($('.current-ribbon').length == 0){ | 
					
						
							|  |  |  | 		$('.ribbon').first().addClass('current-ribbon') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if($('.current-image').length == 0){ | 
					
						
							|  |  |  | 		$('.current-ribbon').children('.image').first().addClass('current-image') | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setupKeyboard(){ | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	$(document) | 
					
						
							|  |  |  | 		.keydown(handleKeys) | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setupGestures(){ | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	$('.viewer') | 
					
						
							|  |  |  | 		// XXX this is flaky and breaks some of my code...
 | 
					
						
							| 
									
										
										
										
											2012-06-13 15:16:43 +04:00
										 |  |  | 		.swipe({ | 
					
						
							|  |  |  | 			swipeLeft: nextImage, | 
					
						
							|  |  |  | 			swipeRight: prevImage, | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 			swipeUp: shiftImageUp, | 
					
						
							|  |  |  | 			swipeDown: shiftImageDown, | 
					
						
							| 
									
										
										
										
											2012-06-13 15:16:43 +04:00
										 |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 		/* XXX jquery.mobile handlers... (with this I'm getting way too much bling) | 
					
						
							|  |  |  | 		.bind('swipeleft', function(e){ | 
					
						
							|  |  |  | 			nextImage() | 
					
						
							|  |  |  | 			e.preventDefault() | 
					
						
							|  |  |  | 			return false | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 		.bind('swiperight', function(e){ | 
					
						
							|  |  |  | 			prevImage() | 
					
						
							|  |  |  | 			e.preventDefault() | 
					
						
							|  |  |  | 			return false | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 		*/ | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setupControlElements(){ | 
					
						
							|  |  |  | 	// images...
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 	$(".image").click(handleImageClick) | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 	// buttons...
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	$('.next-image').click(nextImage) | 
					
						
							|  |  |  | 	$('.prev-image').click(prevImage) | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 	$('.demote').click(shiftImageUp) | 
					
						
							|  |  |  | 	$('.promote').click(shiftImageDown) | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	$('.toggle-wide').click(toggleWideView) | 
					
						
							|  |  |  | 	$('.toggle-single').click(toggleRibbonView) | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | function loadImages(json){ | 
					
						
							|  |  |  | 	var images = json.images | 
					
						
							|  |  |  | 	var ribbon = $('.ribbon').last() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$('.image').remove() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(var i = 0; i < images.length; i++){ | 
					
						
							|  |  |  | 		$('<div class="image"></div>') | 
					
						
							|  |  |  | 			.css({ 'background-image': 'url('+images[i]+')' }) | 
					
						
							| 
									
										
										
										
											2012-07-03 03:38:28 +04:00
										 |  |  | 			// set a unique id for each image...
 | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | 			.attr({'id': i}) | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 			.click(handleImageClick) | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			.appendTo(ribbon) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ribbon.children().first().click() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*************************************************** Event Handlers **/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | function handleImageClick(e) { | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	var cur = $(this) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// switch classes...
 | 
					
						
							|  |  |  | 	cur.parents().siblings().children(".image").removeClass("current-image") | 
					
						
							|  |  |  | 	cur.siblings(".image").removeClass("current-image") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cur.siblings().children(".image").removeClass("current-image") | 
					
						
							|  |  |  | 	cur.parents().siblings(".ribbon").removeClass("current-ribbon") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cur.addClass("current-image") | 
					
						
							|  |  |  | 	cur.parents(".ribbon").addClass("current-ribbon") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var container = cur.parents('.container') | 
					
						
							|  |  |  | 	var field = cur.parents(".field") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var image_offset = cur.offset() | 
					
						
							|  |  |  | 	var field_offset = field.offset() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// center the current image...
 | 
					
						
							|  |  |  | 	field.css({ | 
					
						
							|  |  |  | 		left: field_offset.left - image_offset.left + (container.innerWidth() - cur.innerWidth())/2,  | 
					
						
							|  |  |  | 		top: field_offset.top - image_offset.top + (container.innerHeight() - cur.innerHeight())/2  | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XXX do I need this???
 | 
					
						
							|  |  |  | 	e.preventDefault(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // key configuration...
 | 
					
						
							|  |  |  | // XXX need to make this handle modifiers gracefully...
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | var keys = { | 
					
						
							|  |  |  | 	toggleHelpKeys: [72], | 
					
						
							| 
									
										
										
										
											2012-06-08 20:41:14 +04:00
										 |  |  | 	toggleRibbonView: [70], | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	closeKeys: [27, 88, 67], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	firstKeys: [36], | 
					
						
							|  |  |  | 	lastKeys: [35], | 
					
						
							| 
									
										
										
										
											2012-06-08 20:41:14 +04:00
										 |  |  | 	previousKeys: [37, 80, 188, 8], | 
					
						
							|  |  |  | 	nextKeys: [39, 78, 190, 32], | 
					
						
							|  |  |  | 	// these work with ctrl and shift modifiers...
 | 
					
						
							|  |  |  | 	downKeys: [40], | 
					
						
							|  |  |  | 	upKeys: [38], | 
					
						
							|  |  |  | 	// these work with ctrl modifier...
 | 
					
						
							|  |  |  | 	promoteKeys: [45], | 
					
						
							|  |  |  | 	demoteKeys: [46], | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ignoreKeys: [16, 17, 18], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	helpShowOnUnknownKey: true | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:51:02 +04:00
										 |  |  | // XXX revise...
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | function handleKeys(event){ | 
					
						
							|  |  |  | 	var code = event.keyCode, fn = $.inArray; | 
					
						
							|  |  |  | 	var _ = (fn(code, keys.closeKeys) >= 0) ? function(){}() | 
					
						
							|  |  |  | 		: (fn(code, keys.firstKeys) >= 0) ? firstImage() | 
					
						
							|  |  |  | 		: (fn(code, keys.nextKeys) >= 0) ? nextImage() | 
					
						
							|  |  |  | 		: (fn(code, keys.previousKeys) >= 0) ? prevImage() | 
					
						
							|  |  |  | 		: (fn(code, keys.lastKeys) >= 0) ? lastImage() | 
					
						
							|  |  |  | 		: (fn(code, keys.promoteKeys) >= 0) ? function(){ | 
					
						
							| 
									
										
										
										
											2012-06-08 20:41:14 +04:00
										 |  |  | 			if(event.ctrlKey){ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:40:36 +04:00
										 |  |  | 				createRibbon('next') | 
					
						
							| 
									
										
										
										
											2012-06-08 20:41:14 +04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 			shiftImageDown() | 
					
						
							| 
									
										
										
										
											2012-06-08 20:41:14 +04:00
										 |  |  | 		}() | 
					
						
							|  |  |  | 		: (fn(code, keys.demoteKeys) >= 0) ? function(){ | 
					
						
							|  |  |  | 			if(event.ctrlKey){ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:40:36 +04:00
										 |  |  | 				createRibbon('prev') | 
					
						
							| 
									
										
										
										
											2012-06-08 20:41:14 +04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 			shiftImageUp() | 
					
						
							| 
									
										
										
										
											2012-06-08 20:41:14 +04:00
										 |  |  | 		}() | 
					
						
							|  |  |  | 		: (fn(code, keys.downKeys) >= 0) ? function(){ | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			if(event.shiftKey){ | 
					
						
							|  |  |  | 				if(event.ctrlKey){ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:40:36 +04:00
										 |  |  | 					createRibbon('next') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 				shiftImageDown() | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				focusBelowRibbon() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}() | 
					
						
							| 
									
										
										
										
											2012-06-08 20:41:14 +04:00
										 |  |  | 		: (fn(code, keys.upKeys) >= 0) ? function(){ | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			if(event.shiftKey){ | 
					
						
							|  |  |  | 				if(event.ctrlKey){ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:40:36 +04:00
										 |  |  | 					createRibbon('prev') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 				shiftImageUp() | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				focusAboveRibbon() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}() | 
					
						
							|  |  |  | 		: (fn(code, keys.toggleRibbonView) >= 0) ? toggleRibbonView() | 
					
						
							|  |  |  | 		: (fn(code, keys.ignoreKeys) >= 0) ? false | 
					
						
							|  |  |  | 		// XXX
 | 
					
						
							|  |  |  | 		: (keys.helpShowOnUnknownKey) ? function(){alert(code)}() | 
					
						
							|  |  |  | 		: false; | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /************************************************************ Modes **/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | // mode switchers...
 | 
					
						
							|  |  |  | function unsetViewerMode(mode){ | 
					
						
							|  |  |  | 	$('.' + mode) | 
					
						
							|  |  |  | 		.removeClass(mode) | 
					
						
							|  |  |  | 			// animation...
 | 
					
						
							| 
									
										
										
										
											2012-06-08 19:35:05 +04:00
										 |  |  | 			.one("webkitTransitionEnd oTransitionEnd msTransitionEnd transitionend", function(){ | 
					
						
							|  |  |  | 				$('.current-image').click() | 
					
						
							|  |  |  | 				return true | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | function setViewerMode(mode){ | 
					
						
							|  |  |  | 	$('.viewer').not('.' + mode) | 
					
						
							|  |  |  | 		.addClass(mode) | 
					
						
							|  |  |  | 			// animation...
 | 
					
						
							| 
									
										
										
										
											2012-06-08 19:35:05 +04:00
										 |  |  | 			.one("webkitTransitionEnd oTransitionEnd msTransitionEnd transitionend", function(){ | 
					
						
							|  |  |  | 				$('.current-image').click() | 
					
						
							|  |  |  | 				return true | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | // ribbon/single view modes...
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | function toggleRibbonView(){ | 
					
						
							|  |  |  | 	if($('.single-image-mode').length > 0){ | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | 		unsetViewerMode('single-image-mode') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | 		setViewerMode('single-image-mode') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | // wide view mode toggle...
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | // XXX replace this with adequate zooming...
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | // XXX need to reposition the whole thing correctly...
 | 
					
						
							|  |  |  | function toggleWideView(){ | 
					
						
							|  |  |  | 	if($('.wide-view-mode').length > 0){ | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | 		unsetViewerMode('wide-view-mode') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | 		unsetViewerMode('single-image-mode') | 
					
						
							|  |  |  | 		setViewerMode('wide-view-mode') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /******************************************************* Navigation **/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | // basic navigation...
 | 
					
						
							|  |  |  | function firstImage(){ | 
					
						
							|  |  |  | 	$('.current-ribbon').children('.image').first().click() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function prevImage(){ | 
					
						
							|  |  |  | 	$('.current-image').prev('.image').click() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function nextImage(){ | 
					
						
							|  |  |  | 	$('.current-image').next('.image').click() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function lastImage(){ | 
					
						
							|  |  |  | 	$('.current-ribbon').children('.image').last().click() | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | // XXX for the above two functions to be stable we will need to jump up 
 | 
					
						
							|  |  |  | // 		to the next and down to the prev element...
 | 
					
						
							|  |  |  | function focusRibbon(direction){ | 
					
						
							|  |  |  | 	var id = $('.current-image').attr('id') | 
					
						
							|  |  |  | 	var prev = getImageBefore(id, $('.current-ribbon')[direction]('.ribbon')) | 
					
						
							|  |  |  | 	if(prev){ | 
					
						
							|  |  |  | 		var next = prev.next() | 
					
						
							|  |  |  | 		if(next.length == 0){ | 
					
						
							|  |  |  | 			prev.click() | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			next.click() | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		$('.current-ribbon')[direction]('.ribbon').children('.image').first().click() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | function focusAboveRibbon(){ | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | 	focusRibbon('prev') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | } | 
					
						
							|  |  |  | function focusBelowRibbon(){ | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | 	focusRibbon('next') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | /********************************************************** Helpers **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // find an image object after which to position image ID...
 | 
					
						
							|  |  |  | // used for two main tasks:
 | 
					
						
							|  |  |  | // 	- positioning pormoted/demoted images
 | 
					
						
							|  |  |  | // 	- centering ribbons
 | 
					
						
							|  |  |  | // returns:
 | 
					
						
							|  |  |  | // 	- null		- empty ribbon or no element greater id should be first
 | 
					
						
							|  |  |  | // 	- element
 | 
					
						
							|  |  |  | // XXX do we need to make ids numbers for this to work?
 | 
					
						
							|  |  |  | // XXX might be better to make this a binary search for very large sets of data
 | 
					
						
							|  |  |  | function getImageBefore(id, ribbon){ | 
					
						
							|  |  |  | 	// walk the ribbon till we find two images one with an ID less and 
 | 
					
						
							|  |  |  | 	// another greater that id...
 | 
					
						
							|  |  |  | 	id = parseInt(id) | 
					
						
							|  |  |  | 	var images = ribbon.children('.image') | 
					
						
							|  |  |  | 	var prev | 
					
						
							|  |  |  | 	for(var i=0; i < images.length; i++){ | 
					
						
							|  |  |  | 		if(parseInt($(images[i]).attr('id')) > id){ | 
					
						
							|  |  |  | 			return prev | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		prev = $(images[i]) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return prev | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | /********************************************************** Actions **/ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | // basic actions...
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:51:02 +04:00
										 |  |  | // NOTE: below 'direction' is meant in the html sence, i.e. next/prev...
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | // create ribbon above/below helpers...
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:40:36 +04:00
										 |  |  | function createRibbon(direction){ | 
					
						
							|  |  |  | 	if(direction == 'next'){ | 
					
						
							|  |  |  | 		var insert = 'insertAfter' | 
					
						
							|  |  |  | 	} else if(direction == 'prev') { | 
					
						
							|  |  |  | 		var insert = 'insertBefore' | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var res = $('<div class="new-ribbon"></div>')[insert]('.current-ribbon') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 		// HACK: without this, the class change below will not animate...
 | 
					
						
							|  |  |  | 		.show() | 
					
						
							|  |  |  | 		.addClass('ribbon') | 
					
						
							|  |  |  | 		.removeClass('new-ribbon') | 
					
						
							| 
									
										
										
										
											2012-06-16 21:40:36 +04:00
										 |  |  | 	// XXX need to account for increased top when creating a ribbon above...
 | 
					
						
							|  |  |  | 	// 		i.e. shift the content upward...
 | 
					
						
							|  |  |  | 	/* | 
					
						
							|  |  |  | 	if(direction == 'prev'){ | 
					
						
							|  |  |  | 		$('.field').css({ | 
					
						
							|  |  |  | 			top: $('.field').position().top - $('.current-ribbon').outerHeight() | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	}*/ | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	return res | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX sort elements correctly...
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:24:11 +04:00
										 |  |  | function mergeRibbons(direction){ | 
					
						
							|  |  |  | 	$('.current-ribbon')[direction]('.ribbon') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			.children() | 
					
						
							|  |  |  | 				.detach() | 
					
						
							|  |  |  | 				.insertAfter('.current-image') | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 	// animate...
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:24:11 +04:00
										 |  |  | 	$('.current-ribbon')[direction]('.ribbon') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			.slideUp(function(){ | 
					
						
							|  |  |  | 				$(this).remove() | 
					
						
							|  |  |  | 				$('.current-image').click() | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | /*************************************************** Editor Actions **/ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | // now the actual modifiers...
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:24:11 +04:00
										 |  |  | function shiftImage(direction){ | 
					
						
							|  |  |  | 	if($('.current-ribbon')[direction]('.ribbon').length == 0){ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:40:36 +04:00
										 |  |  | 		createRibbon(direction) | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get previous element after which we need to put the current...
 | 
					
						
							|  |  |  | 	var prev_elem = getImageBefore( | 
					
						
							|  |  |  | 					$('.current-image').attr('id'),  | 
					
						
							|  |  |  | 					$('.current-ribbon')[direction]('.ribbon')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// last image in ribbon, merge...
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	if($('.current-ribbon').children('.image').length == 1){ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:24:11 +04:00
										 |  |  | 		mergeRibbons(direction) | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		img = $('.current-image') | 
					
						
							|  |  |  | 		if(img.next('.image').length == 0){ | 
					
						
							|  |  |  | 			prevImage() | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			nextImage() | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | 		// do the actual move...
 | 
					
						
							|  |  |  | 		if(prev_elem){ | 
					
						
							|  |  |  | 			// insert element after current...
 | 
					
						
							|  |  |  | 			img | 
					
						
							|  |  |  | 				.detach() | 
					
						
							|  |  |  | 				.insertAfter(prev_elem) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			// empty ribbon or fisrt element...
 | 
					
						
							|  |  |  | 			img | 
					
						
							|  |  |  | 				.detach() | 
					
						
							|  |  |  | 				.prependTo($('.current-ribbon')[direction]('.ribbon')) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-06-16 21:24:11 +04:00
										 |  |  | 	// XXX this has to know aout animations...
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	$('.current-image').click() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | function shiftImageDown(){ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:24:11 +04:00
										 |  |  | 	return shiftImage('next') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | // XXX this has problems, when creating a new ribbon this does not settle 
 | 
					
						
							|  |  |  | //	   into a correct spot...
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | function shiftImageUp(){ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:24:11 +04:00
										 |  |  | 	return shiftImage('prev') | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | // vim:set ts=4 sw=4 nowrap :
 |