| 
									
										
										
										
											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', | 
					
						
							|  |  |  | 		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-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
										 |  |  | 		], | 
					
						
							|  |  |  | 		function(action){ | 
					
						
							|  |  |  | 			SETTINGS['theme'] = action | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2013-05-17 17:58:23 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 15:34:45 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-30 03:26:49 +04:00
										 |  |  | var toggleImageInfo = createCSSClassToggler('.viewer', '.image-info-visible') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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'){ | 
					
						
							|  |  |  | 		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') | 
					
						
							|  |  |  | 		return 'square' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// viewer size...
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		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') | 
					
						
							|  |  |  | 		return 'viewer' | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) | 
					
						
							|  |  |  | 					.css({ | 
					
						
							|  |  |  | 						cursor: 'hand', | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 					.appendTo(body) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// add exit by click...
 | 
					
						
							|  |  |  | 				body | 
					
						
							|  |  |  | 					.one('click', function(){ | 
					
						
							|  |  |  | 						toggleKeyboardHelp('off') | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// 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 | 
					
						
							|  |  |  | 							.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 :                                                */ |