| 
									
										
										
										
											2013-05-17 15:34:45 +04:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX make this save and restore settings...
 | 
					
						
							|  |  |  | var toggleSingleImageMode = createCSSClassToggler('.viewer',  | 
					
						
							|  |  |  | 		'single-image-mode', | 
					
						
							| 
									
										
										
										
											2013-06-01 20:16:45 +04:00
										 |  |  | 		function(action){ | 
					
						
							|  |  |  | 			// prevent reiniting...
 | 
					
						
							|  |  |  | 			if(action == toggleSingleImageMode('?')){ | 
					
						
							|  |  |  | 				return false | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2013-05-17 15:34:45 +04:00
										 |  |  | 		function(action){ | 
					
						
							| 
									
										
										
										
											2013-05-24 00:09:13 +04:00
										 |  |  | 			var w = getScreenWidthInImages() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// single image mode...
 | 
					
						
							| 
									
										
										
										
											2013-05-17 15:34:45 +04:00
										 |  |  | 			if(action == 'on'){ | 
					
						
							|  |  |  | 				TRANSITION_MODE_DEFAULT = 'css' | 
					
						
							| 
									
										
										
										
											2013-05-24 00:09:13 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// save things...
 | 
					
						
							|  |  |  | 				SETTINGS['screen-images-ribbon-mode'] = w | 
					
						
							| 
									
										
										
										
											2013-05-30 07:29:07 +04:00
										 |  |  | 				SETTINGS['image-info-ribbon-mode'] = toggleImageInfo('?') | 
					
						
							| 
									
										
										
										
											2013-05-24 00:09:13 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// load things...
 | 
					
						
							|  |  |  | 				w = SETTINGS['screen-images-single-image-mode'] | 
					
						
							|  |  |  | 				w = w == null ? 1 : w | 
					
						
							|  |  |  | 				var p = SETTINGS['single-image-mode-proportions'] | 
					
						
							|  |  |  | 				p = p == null ? 'square' : p | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// set stuff...
 | 
					
						
							|  |  |  | 				toggleImageProportions(p) | 
					
						
							|  |  |  | 				fitNImages(w) | 
					
						
							| 
									
										
										
										
											2013-05-30 07:29:07 +04:00
										 |  |  | 				toggleImageInfo('off') | 
					
						
							| 
									
										
										
										
											2013-05-24 00:09:13 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// ribbon mode...
 | 
					
						
							| 
									
										
										
										
											2013-05-17 15:34:45 +04:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				TRANSITION_MODE_DEFAULT = 'animate' | 
					
						
							| 
									
										
										
										
											2013-05-24 00:09:13 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// save things...
 | 
					
						
							|  |  |  | 				SETTINGS['screen-images-single-image-mode'] = w | 
					
						
							|  |  |  | 				SETTINGS['single-image-mode-proportions'] = toggleImageProportions('?') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// load things...
 | 
					
						
							|  |  |  | 				w = SETTINGS['screen-images-ribbon-mode'] | 
					
						
							|  |  |  | 				w = w == null ? DEFAULT_SCREEN_IMAGES : w | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 16:21:03 +04:00
										 |  |  | 				toggleImageProportions('square') | 
					
						
							| 
									
										
										
										
											2013-05-24 00:09:13 +04:00
										 |  |  | 				fitNImages(w) | 
					
						
							| 
									
										
										
										
											2013-05-30 07:29:07 +04:00
										 |  |  | 				var i = SETTINGS['image-info-ribbon-mode'] == 'on' ? 'on' : 'off' | 
					
						
							|  |  |  | 				toggleImageInfo(i) | 
					
						
							|  |  |  | 				SETTINGS['image-info-ribbon-mode'] = i | 
					
						
							| 
									
										
										
										
											2013-05-17 15:34:45 +04:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-01 19:54:46 +04:00
										 |  |  | var SLIDESHOW_INTERVAL = 3000 | 
					
						
							|  |  |  | var SLIDESHOW_LOOP = true | 
					
						
							|  |  |  | var SLIDESHOW_DIRECTION = 'next' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO transitions...
 | 
					
						
							|  |  |  | // TODO a real setup UI (instead of prompt)
 | 
					
						
							| 
									
										
										
										
											2013-06-01 20:16:45 +04:00
										 |  |  | var toggleSlideShowMode = createCSSClassToggler('.viewer',  | 
					
						
							|  |  |  | 		'.slideshow-mode', | 
					
						
							| 
									
										
										
										
											2013-06-01 19:54:46 +04:00
										 |  |  | 		function(action){ | 
					
						
							|  |  |  | 			if(action == 'on'){ | 
					
						
							|  |  |  | 				updateStatus('Slideshow...').show() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// interval from user...
 | 
					
						
							|  |  |  | 				// XXX make this a real UI...
 | 
					
						
							|  |  |  | 				var interval = prompt('Slideshow interval (sec):', SLIDESHOW_INTERVAL/1000) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// user cancelled...
 | 
					
						
							|  |  |  | 				if(interval == null){ | 
					
						
							|  |  |  | 					showStatus('Slideshow: cencelled...') | 
					
						
							|  |  |  | 					toggleSlideShowMode('off') | 
					
						
							|  |  |  | 					return  | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				SLIDESHOW_INTERVAL = isNaN(interval) ? 3000 : interval*1000 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-01 20:16:45 +04:00
										 |  |  | 				showStatus('Slideshow: starting', SLIDESHOW_LOOP ? 'looped...' : 'unlooped...') | 
					
						
							| 
									
										
										
										
											2013-06-01 19:54:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				toggleSingleImageMode('on') | 
					
						
							|  |  |  | 				_slideshow_timer = setInterval(function(){ | 
					
						
							|  |  |  | 					var cur = getImage() | 
					
						
							|  |  |  | 					// advance the image...
 | 
					
						
							|  |  |  | 					var next = SLIDESHOW_DIRECTION == 'next' ? nextImage() : prevImage() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// handle slideshow end...
 | 
					
						
							|  |  |  | 					if(getImageGID(cur) == getImageGID(next)){ | 
					
						
							|  |  |  | 						if(SLIDESHOW_LOOP){ | 
					
						
							|  |  |  | 							SLIDESHOW_DIRECTION == 'next' ? firstImage() : lastImage() | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							toggleSlideShowMode('off') | 
					
						
							|  |  |  | 							return  | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// center and trigger load events...
 | 
					
						
							|  |  |  | 					centerRibbon() | 
					
						
							|  |  |  | 				}, SLIDESHOW_INTERVAL) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				window._slideshow_timer != null && clearInterval(_slideshow_timer) | 
					
						
							|  |  |  | 				showStatus('Slideshow: stopped...') | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 17:58:23 +04:00
										 |  |  | var toggleTheme = createCSSClassToggler('.viewer', | 
					
						
							|  |  |  | 		[ | 
					
						
							|  |  |  | 			'gray', | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | 			'dark', | 
					
						
							| 
									
										
										
										
											2013-05-17 17:58:23 +04:00
										 |  |  | 			'light' | 
					
						
							| 
									
										
										
										
											2013-05-24 00:32:42 +04:00
										 |  |  | 		], | 
					
						
							| 
									
										
										
										
											2013-06-01 21:06:10 +04:00
										 |  |  | 		// XXX does this get called for default state (gray)???
 | 
					
						
							| 
									
										
										
										
											2013-05-24 00:32:42 +04:00
										 |  |  | 		function(action){ | 
					
						
							|  |  |  | 			SETTINGS['theme'] = action | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2013-05-17 17:58:23 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 15:34:45 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-01 18:43:14 +04:00
										 |  |  | var toggleImageInfo = createCSSClassToggler('.viewer', | 
					
						
							|  |  |  | 		'.image-info-visible', | 
					
						
							|  |  |  | 		function(action){ | 
					
						
							|  |  |  | 			if(toggleSingleImageMode('?') == 'off'){ | 
					
						
							|  |  |  | 				SETTINGS['image-info-ribbon-mode'] = action | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2013-05-30 03:26:49 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-30 19:15:38 +04:00
										 |  |  | var toggleInlineImageInfo = createCSSClassToggler('.viewer',  | 
					
						
							|  |  |  | 		'.image-info-inline-visible', | 
					
						
							|  |  |  | 		function(action){ | 
					
						
							|  |  |  | 			if(action == 'on'){ | 
					
						
							|  |  |  | 				$(document) | 
					
						
							|  |  |  | 					.on('mouseover', inlineImageInfoHoverHandler) | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				$(document) | 
					
						
							|  |  |  | 					.off('mouseover', inlineImageInfoHoverHandler) | 
					
						
							|  |  |  | 					$('.inline-image-info').remove() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | // NOTE: this confirmsto the css toggler protocol, but is not implemented 
 | 
					
						
							|  |  |  | // 		via createCSSClassToggler as we do not need to set any classes,
 | 
					
						
							|  |  |  | // 		al least at this point...
 | 
					
						
							|  |  |  | // XXX should we use the createCSSClassToggler for this?
 | 
					
						
							|  |  |  | // XXX revise: does extra stuff...
 | 
					
						
							|  |  |  | function toggleImageProportions(mode){ | 
					
						
							| 
									
										
										
										
											2013-05-23 18:58:45 +04:00
										 |  |  | 	// normal images...
 | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | 	var image = $('.image') | 
					
						
							|  |  |  | 	var h = image.outerHeight(true) | 
					
						
							|  |  |  | 	var w = image.outerWidth(true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(mode == '?'){ | 
					
						
							|  |  |  | 		return h != w ? 'viewer' : 'square' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// square...
 | 
					
						
							|  |  |  | 	} else if(h != w || mode == 'square'){ | 
					
						
							| 
									
										
										
										
											2013-06-01 21:06:10 +04:00
										 |  |  | 		mode = 'square' | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | 		var size = Math.min(w, h) | 
					
						
							|  |  |  | 		image.css({ | 
					
						
							|  |  |  | 			width: size, | 
					
						
							|  |  |  | 			height: size | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2013-05-23 18:58:45 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// account for rotation...
 | 
					
						
							|  |  |  | 		correctImageProportionsForRotation(image) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | 		centerView(null, 'css') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// viewer size...
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2013-06-01 21:06:10 +04:00
										 |  |  | 		mode = 'viewer' | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | 		var viewer = $('.viewer') | 
					
						
							|  |  |  | 		var W = viewer.innerWidth() | 
					
						
							|  |  |  | 		var H = viewer.innerHeight() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(W > H){ | 
					
						
							|  |  |  | 			image.css('width', W * h/H) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			image.css('height', H * w/W) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-23 18:58:45 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// account for rotation...
 | 
					
						
							|  |  |  | 		correctImageProportionsForRotation(image) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | 		centerView(null, 'css') | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-01 21:06:10 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 'mode' | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-23 16:13:10 +04:00
										 |  |  | var toggleKeyboardHelp = createCSSClassToggler('.viewer', 'help-mode overlay', | 
					
						
							|  |  |  | 		function(action){ | 
					
						
							|  |  |  | 			var body = $(document.body) | 
					
						
							|  |  |  | 			var win = $(window) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// on...
 | 
					
						
							|  |  |  | 			if(action == 'on'){ | 
					
						
							|  |  |  | 				// remove helo when we scroll to the top...
 | 
					
						
							|  |  |  | 				var scroll_handler = function(){ | 
					
						
							|  |  |  | 					if(body.scrollTop() <= 0){ | 
					
						
							|  |  |  | 						toggleKeyboardHelp('off') | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// prepare and cleanup...
 | 
					
						
							|  |  |  | 				$('.keyboard-help').remove() | 
					
						
							|  |  |  | 				$('.viewer').addClass('overlay') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// build the help...
 | 
					
						
							|  |  |  | 				var doc = buildKeybindingsHelpHTML(KEYBOARD_CONFIG) | 
					
						
							| 
									
										
										
										
											2013-06-01 21:17:38 +04:00
										 |  |  | 					.on('click', function(){ | 
					
						
							|  |  |  | 						event.stopImmediatePropagation() | 
					
						
							|  |  |  | 						return false | 
					
						
							|  |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2013-05-23 16:13:10 +04:00
										 |  |  | 					.css({ | 
					
						
							| 
									
										
										
										
											2013-06-01 21:17:38 +04:00
										 |  |  | 						cursor: 'auto', | 
					
						
							| 
									
										
										
										
											2013-05-23 16:13:10 +04:00
										 |  |  | 					}) | 
					
						
							|  |  |  | 					.appendTo(body) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// add exit by click...
 | 
					
						
							|  |  |  | 				body | 
					
						
							|  |  |  | 					.one('click', function(){ | 
					
						
							|  |  |  | 						toggleKeyboardHelp('off') | 
					
						
							|  |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2013-06-01 21:17:38 +04:00
										 |  |  | 					.css({ | 
					
						
							|  |  |  | 						cursor: 'hand', | 
					
						
							|  |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2013-05-23 16:13:10 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// scroll to the help...
 | 
					
						
							|  |  |  | 				// NOTE: need to set the scroll handler AFTER we 
 | 
					
						
							|  |  |  | 				// 		scroll down, or it will be more of a 
 | 
					
						
							|  |  |  | 				// 		tease than a help...
 | 
					
						
							|  |  |  | 				var t = getRelativeVisualPosition($('.viewer'), doc).top | 
					
						
							|  |  |  | 				body | 
					
						
							|  |  |  | 					.animate({ | 
					
						
							|  |  |  | 						scrollTop: Math.abs(t) - 40, | 
					
						
							|  |  |  | 					}, function(){ | 
					
						
							|  |  |  | 						win | 
					
						
							|  |  |  | 							.on('scroll', scroll_handler) | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// off...
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2013-05-24 00:09:13 +04:00
										 |  |  | 				// things to cleanup...
 | 
					
						
							| 
									
										
										
										
											2013-05-23 16:13:10 +04:00
										 |  |  | 				var _cleanup = function(){ | 
					
						
							|  |  |  | 					$('.keyboard-help').remove() | 
					
						
							|  |  |  | 					$('.viewer').removeClass('overlay') | 
					
						
							|  |  |  | 					body.click() | 
					
						
							|  |  |  | 					win.off('scroll', scroll_handler) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-24 00:09:13 +04:00
										 |  |  | 				// animate things if we are not at the top...
 | 
					
						
							| 
									
										
										
										
											2013-05-23 16:13:10 +04:00
										 |  |  | 				if(body.scrollTop() > 0){ | 
					
						
							|  |  |  | 						body | 
					
						
							| 
									
										
										
										
											2013-06-01 21:17:38 +04:00
										 |  |  | 							.css({ | 
					
						
							|  |  |  | 								cursor: '', | 
					
						
							|  |  |  | 							}) | 
					
						
							| 
									
										
										
										
											2013-05-23 16:13:10 +04:00
										 |  |  | 							.animate({ | 
					
						
							|  |  |  | 								scrollTop: 0, | 
					
						
							|  |  |  | 							}, _cleanup)  | 
					
						
							| 
									
										
										
										
											2013-05-24 00:09:13 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// if we are at the top do things fast...
 | 
					
						
							| 
									
										
										
										
											2013-05-23 16:13:10 +04:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					_cleanup() | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 15:34:45 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ |