| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-08-21 02:19:24 +03:00
										 |  |  | ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) | 
					
						
							|  |  |  | (function(require){ var module={} // make module AMD/node compatible...
 | 
					
						
							| 
									
										
										
										
											2016-08-20 22:49:36 +03:00
										 |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var actions = require('lib/actions') | 
					
						
							|  |  |  | var features = require('lib/features') | 
					
						
							|  |  |  | var toggler = require('lib/toggler') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var core = require('features/core') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-04-25 04:40:10 +03:00
										 |  |  | // Change image proportions depending on scale...
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // A) Small image -- min(screenwidth, screenheight) > threshold
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | //
 | 
					
						
							|  |  |  | //       viewer
 | 
					
						
							|  |  |  | //      +---------------+
 | 
					
						
							|  |  |  | //      |     image     |   - small image
 | 
					
						
							|  |  |  | //      |     +---+     |   - square image block
 | 
					
						
							|  |  |  | //      |     |   |     |   - smaller than this the block is always square
 | 
					
						
							|  |  |  | //      |     +---+     |   - we just change scale
 | 
					
						
							|  |  |  | //      |               |
 | 
					
						
							|  |  |  | //      +---------------+
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-04-25 04:40:10 +03:00
										 |  |  | // B) min(screenwidth, screenheight) <= threshold
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | //       viewer
 | 
					
						
							|  |  |  | //      +---------------+
 | 
					
						
							|  |  |  | //      | +-----------+ |   - bigger image
 | 
					
						
							|  |  |  | //      | | image     | |   - block close to viewer proportion
 | 
					
						
							|  |  |  | //      | |    <-->   | |   - image block growing parallel to viewer
 | 
					
						
							|  |  |  | //      | |           | |     longer side
 | 
					
						
							|  |  |  | //      | +-----------+ |   - this stage is not affected specific by image
 | 
					
						
							|  |  |  | //      +---------------+     proportions and can be done in bulk
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-04-25 04:40:10 +03:00
										 |  |  | // C) fullscreen -- min(screenwidth, screenheight) == 1
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | //       viewer
 | 
					
						
							|  |  |  | //      +---------------+
 | 
					
						
							|  |  |  | //      | image         |   - image block same size as viewer
 | 
					
						
							|  |  |  | //      |               |   - need to account for chrome
 | 
					
						
							|  |  |  | //      |               |
 | 
					
						
							|  |  |  | //      |               |
 | 
					
						
							|  |  |  | //      |               |
 | 
					
						
							|  |  |  | //      +---------------+
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-04-25 04:40:10 +03:00
										 |  |  | // D) zoomed in -- min(screenwidth, screenheight) < 1 (blocked, no drag)
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | //     image
 | 
					
						
							|  |  |  | //    + - - - - - - - - - +
 | 
					
						
							|  |  |  | //    .                   .
 | 
					
						
							|  |  |  | //    . +---------------+ .
 | 
					
						
							|  |  |  | //    . | viewer        | . - image bigger than viewer 
 | 
					
						
							|  |  |  | //    . |               | . - image block same proportion as image
 | 
					
						
							|  |  |  | //    . |               | . - we just change scale
 | 
					
						
							| 
									
										
										
										
											2016-04-25 04:40:10 +03:00
										 |  |  | //    . |               | . - drag enabled (XXX not implemented)
 | 
					
						
							|  |  |  | //    . |               | . - next/prev image keeps drag position
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | //    . +---------------+ .
 | 
					
						
							| 
									
										
										
										
											2016-04-29 17:59:17 +03:00
										 |  |  | //    .                   . - use tiles instead very large images (XXX ???)
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | //    + - - - - - - - - - +
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-04-26 02:49:06 +03:00
										 |  |  | // NOTE: this in part does the same job as .ribbons.correctImageProportionsForRotation(..)
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-04-02 20:39:58 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var SingleImageActions = actions.Actions({ | 
					
						
							|  |  |  | 	config: { | 
					
						
							| 
									
										
										
										
											2016-05-01 06:13:50 +03:00
										 |  |  | 		// View scale...
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							| 
									
										
										
										
											2016-04-02 20:39:58 +03:00
										 |  |  | 		// NOTE: these will get overwritten if/when the user changes the scale...
 | 
					
						
							| 
									
										
										
										
											2016-06-16 04:49:17 +03:00
										 |  |  | 		'single-image-scale': 1.2, | 
					
						
							|  |  |  | 		'ribbon-scale': 5, | 
					
						
							| 
									
										
										
										
											2016-04-24 14:46:43 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 02:10:26 +03:00
										 |  |  | 		// Scales for small and normal image sizes...
 | 
					
						
							|  |  |  | 		'fit-small-scale': 4, | 
					
						
							|  |  |  | 		'fit-normal-scale': 1.2, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		'fit-custom-scale': {}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-01 06:13:50 +03:00
										 |  |  | 		// Set scale 'units' for different viewes...
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// NOTE: the units are actually properties used to get/set the values.
 | 
					
						
							| 
									
										
										
										
											2016-05-01 21:27:12 +03:00
										 |  |  | 		'single-image-scale-unit': 'screenfit', | 
					
						
							|  |  |  | 		'ribbon-scale-unit': 'screenwidth', | 
					
						
							| 
									
										
										
										
											2016-05-01 06:13:50 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// The threshold from which the image block starts to tend to 
 | 
					
						
							|  |  |  | 		// screen proportions...
 | 
					
						
							|  |  |  | 		// 	- Above this the block is square.
 | 
					
						
							|  |  |  | 		// 	- At 1 the block is the same proportions as the screen.
 | 
					
						
							|  |  |  | 		// 	- between this and 1 the block is proportionally between a
 | 
					
						
							|  |  |  | 		// 		square and screen proportions.
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							| 
									
										
										
										
											2016-04-25 02:37:57 +03:00
										 |  |  | 		// NOTE: setting this to null or to -1 will disable the feature...
 | 
					
						
							| 
									
										
										
										
											2016-04-24 14:46:43 +03:00
										 |  |  | 		'single-image-proportions-threshold': 2, | 
					
						
							| 
									
										
										
										
											2016-11-20 00:04:41 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-20 00:57:26 +03:00
										 |  |  | 		// Config defaults to set on first init of single image mode...
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// NOTE: the keys set here will be handled by the 'single-image'
 | 
					
						
							|  |  |  | 		// 		workspace...
 | 
					
						
							|  |  |  | 		'single-image-config-defaults': { | 
					
						
							|  |  |  | 			'ribbon-focus-mode': 'order', | 
					
						
							| 
									
										
										
										
											2016-11-26 14:29:11 +03:00
										 |  |  | 			'shifts-affect-direction': 'off', | 
					
						
							| 
									
										
										
										
											2016-11-20 00:57:26 +03:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-04-02 20:39:58 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-26 14:29:11 +03:00
										 |  |  | 	// XXX make this accept args for debuging...
 | 
					
						
							| 
									
										
										
										
											2016-12-02 23:21:14 +03:00
										 |  |  | 	// XXX should this size images via vmin rather than px???
 | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | 	updateImageProportions: ['- Interface/', | 
					
						
							|  |  |  | 		function(){ | 
					
						
							|  |  |  | 			var that = this | 
					
						
							|  |  |  | 			var threshold = this.config['single-image-proportions-threshold'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(!threshold || threshold == -1){ | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var viewer = this.ribbons.viewer | 
					
						
							| 
									
										
										
										
											2016-11-23 01:21:56 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			var ribbon = this.ribbons.getRibbon() | 
					
						
							| 
									
										
										
										
											2016-06-21 00:58:53 +03:00
										 |  |  | 			var images = viewer.find('.ribbon .image') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// no images loaded...
 | 
					
						
							| 
									
										
										
										
											2016-06-21 01:31:04 +03:00
										 |  |  | 			if(images.length == 0){ | 
					
						
							| 
									
										
										
										
											2016-06-21 00:58:53 +03:00
										 |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 01:31:04 +03:00
										 |  |  | 			var w = this.ribbons.getVisibleImageSize('width', 1) | 
					
						
							|  |  |  | 			var h = this.ribbons.getVisibleImageSize('height', 1) | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// inner diameter
 | 
					
						
							|  |  |  | 			var di = Math.min(h, w) | 
					
						
							|  |  |  | 			// outer diameter -- (m)ax
 | 
					
						
							|  |  |  | 			var dm = Math.max(h, w) | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			//var c = Math.min(this.screenwidth, this.screenheight)
 | 
					
						
							|  |  |  | 			var c = this.screenfit  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// change proportions...
 | 
					
						
							|  |  |  | 			if(c < threshold){ | 
					
						
							|  |  |  | 				var W = viewer.width() | 
					
						
							|  |  |  | 				var H = viewer.height() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// inner diameter
 | 
					
						
							|  |  |  | 				var Di = Math.min(W, H) | 
					
						
							|  |  |  | 				// outer diameter -- (m)ax
 | 
					
						
							|  |  |  | 				var Dm = Math.max(W, H) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// get dimensional scale....
 | 
					
						
							|  |  |  | 				var s = Di / di  | 
					
						
							|  |  |  | 				// image dimension delta...
 | 
					
						
							|  |  |  | 				var d =  | 
					
						
							|  |  |  | 					// the maximum difference between image and screen proportions...
 | 
					
						
							|  |  |  | 					(Dm / s - di)  | 
					
						
							|  |  |  | 						// coefficient: 0 : c == threshold  ->  1 : c == 1
 | 
					
						
							|  |  |  | 						* (threshold/c - 1) | 
					
						
							|  |  |  | 				// new size...
 | 
					
						
							|  |  |  | 				var n = di + d | 
					
						
							| 
									
										
										
										
											2016-12-02 23:52:56 +03:00
										 |  |  | 				/*/ XXX for some reason 'vmin' ignores scale... | 
					
						
							|  |  |  | 				var n = ((di + d) / di) * 100 | 
					
						
							|  |  |  | 				//*/
 | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-02 23:21:14 +03:00
										 |  |  | 				// XXX not sure why we need to get animation frame here...
 | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | 				getAnimationFrame(function(){ | 
					
						
							|  |  |  | 					that.ribbons.preventTransitions() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// horizontal viewer...
 | 
					
						
							|  |  |  | 					if(Di == H){ | 
					
						
							|  |  |  | 						var a = 'width' | 
					
						
							|  |  |  | 						var b = 'height' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// vertical viewer...
 | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						var a = 'height' | 
					
						
							|  |  |  | 						var b = 'width' | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					images | 
					
						
							|  |  |  | 						.each(function(_, img){ | 
					
						
							|  |  |  | 							var o = img.getAttribute('orientation') | 
					
						
							|  |  |  | 							o = o == null ? 0 : o | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							// rotated images...
 | 
					
						
							|  |  |  | 							if(o == 90 || o == 270){ | 
					
						
							|  |  |  | 								img.style[a] = '' | 
					
						
							|  |  |  | 								img.style[b] = n + 'px' | 
					
						
							|  |  |  | 								img.style.margin = -(n - di)/2 +'px '+ (n - di)/2 +'px' | 
					
						
							| 
									
										
										
										
											2016-12-02 23:52:56 +03:00
										 |  |  | 								/*/ XXX for some reason 'vmin' ignores scale... | 
					
						
							|  |  |  | 								img.style[b] = n + 'vmin' | 
					
						
							|  |  |  | 								img.style.margin = -(n - 100)/2 +'vmin '+ (n - 100)/2 +'vmin' | 
					
						
							|  |  |  | 								//*/
 | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							} else { | 
					
						
							|  |  |  | 								img.style[a] = n + 'px' | 
					
						
							| 
									
										
										
										
											2016-12-02 23:52:56 +03:00
										 |  |  | 								/*/ XXX for some reason 'vmin' ignores scale... | 
					
						
							|  |  |  | 								img.style[a] = n + 'vmin' | 
					
						
							|  |  |  | 								//*/
 | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | 								img.style[b] = '' | 
					
						
							|  |  |  | 								img.style.margin = '' | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						}) | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 					that.ribbons | 
					
						
							|  |  |  | 						.centerImage() | 
					
						
							|  |  |  | 						.restoreTransitions(true) | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// reset proportions to square...
 | 
					
						
							|  |  |  | 			} else if(w != h) { | 
					
						
							|  |  |  | 				getAnimationFrame(function(){ | 
					
						
							|  |  |  | 					that.ribbons.preventTransitions() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					images | 
					
						
							|  |  |  | 						.each(function(_, img){ | 
					
						
							|  |  |  | 							img.style.width = '' | 
					
						
							|  |  |  | 							img.style.height = '' | 
					
						
							|  |  |  | 							img.style.margin = '' | 
					
						
							|  |  |  | 						}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					that.ribbons | 
					
						
							|  |  |  | 						.centerImage() | 
					
						
							|  |  |  | 						.restoreTransitions(true) | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-05 03:06:06 +03:00
										 |  |  | 	toggleSingleImage: ['Interface/Single image view',  | 
					
						
							| 
									
										
										
										
											2016-04-02 20:39:58 +03:00
										 |  |  | 		toggler.CSSClassToggler( | 
					
						
							|  |  |  | 			function(){ return this.ribbons.viewer },  | 
					
						
							| 
									
										
										
										
											2016-05-07 00:47:52 +03:00
										 |  |  | 			'single-image-mode', | 
					
						
							|  |  |  | 			function(state){ | 
					
						
							|  |  |  | 				if(state == 'on'){ | 
					
						
							|  |  |  | 					this.pushWorkspace() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if(this.workspaces['single-image'] == null){ | 
					
						
							|  |  |  | 						this.loadWorkspace('ui-chrome-hidden')  | 
					
						
							| 
									
										
										
										
											2016-11-20 03:51:53 +03:00
										 |  |  | 						this.mergeConfig('single-image-config-defaults') | 
					
						
							|  |  |  | 						this.saveWorkspace('single-image') | 
					
						
							| 
									
										
										
										
											2016-05-07 00:47:52 +03:00
										 |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					this.loadWorkspace('single-image')  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					this.popWorkspace() | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			})], | 
					
						
							| 
									
										
										
										
											2016-06-21 02:10:26 +03:00
										 |  |  | 	 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// basic single image view sizing...
 | 
					
						
							|  |  |  | 	fitSmall: ['Zoom/Show small image', | 
					
						
							|  |  |  | 		function(){ this.screenfit = this.config['fit-small-scale'] || 4 }], | 
					
						
							| 
									
										
										
										
											2016-06-21 02:45:45 +03:00
										 |  |  | 	setSmallScale: ['Zoom/Set small size to current', | 
					
						
							|  |  |  | 		function(value){  | 
					
						
							|  |  |  | 			this.config['fit-small-scale'] | 
					
						
							|  |  |  | 				= value === null ? 4 : (value || this.screenfit) }], | 
					
						
							| 
									
										
										
										
											2016-06-21 02:10:26 +03:00
										 |  |  | 	fitNormal: ['Zoom/Show normal image', | 
					
						
							|  |  |  | 		function(){ this.screenfit = this.config['fit-normal-scale'] || 1.2 }], | 
					
						
							|  |  |  | 	setNormalScale: ['Zoom/Set normal size to current', | 
					
						
							| 
									
										
										
										
											2016-06-21 02:45:45 +03:00
										 |  |  | 		function(value){  | 
					
						
							|  |  |  | 			this.config['fit-normal-scale']  | 
					
						
							|  |  |  | 				= value === null ? 1.2 : (value || this.screenfit) }], | 
					
						
							| 
									
										
										
										
											2016-06-21 02:10:26 +03:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2016-06-21 02:13:20 +03:00
										 |  |  | 	fitCustom: ['- Zoom/Show cusotm size image', | 
					
						
							| 
									
										
										
										
											2016-06-21 02:10:26 +03:00
										 |  |  | 		function(n){ | 
					
						
							|  |  |  | 			if(n == null){ | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var s = this.config['fit-custom-scale'][n] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(s == null){ | 
					
						
							|  |  |  | 				return	 | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			this.screenfit = s | 
					
						
							|  |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2016-06-21 02:13:20 +03:00
										 |  |  | 	setCustomSize: ['- Zoom/Set image cusotm size', | 
					
						
							| 
									
										
										
										
											2016-06-21 02:45:45 +03:00
										 |  |  | 		function(n, value){ | 
					
						
							| 
									
										
										
										
											2016-06-21 02:10:26 +03:00
										 |  |  | 			if(n == null){ | 
					
						
							|  |  |  | 				return | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 02:45:45 +03:00
										 |  |  | 			var sizes = this.config['fit-custom-scale'] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// reset...
 | 
					
						
							|  |  |  | 			if(value === null){ | 
					
						
							|  |  |  | 				if(sizes && n in sizes){ | 
					
						
							|  |  |  | 					delete sizes[n] | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// set...
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				sizes = sizes && JSON.parse(JSON.stringify(sizes)) || {} | 
					
						
							|  |  |  | 				sizes[n] = value || this.screenfit | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-06-21 02:10:26 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// NOTE: we are resetting this for it to be stored correctly...
 | 
					
						
							| 
									
										
										
										
											2016-06-21 02:45:45 +03:00
										 |  |  | 			if(sizes){ | 
					
						
							|  |  |  | 				this.config['fit-custom-scale'] = sizes | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-06-21 02:10:26 +03:00
										 |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2016-04-02 20:39:58 +03:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-30 03:38:52 +03:00
										 |  |  | // XXX HACK: we are forcing redraw of images in some conditions (when 
 | 
					
						
							|  |  |  | // 		they are close to their original size) to compensate for chrome
 | 
					
						
							|  |  |  | // 		rendering them blurry off screen in these conditions...
 | 
					
						
							|  |  |  | // 		XXX I would not bother and leave this as-is but this makes the 
 | 
					
						
							|  |  |  | // 			image jump in size slightly when redrawing...
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | var SingleImageView = | 
					
						
							|  |  |  | module.SingleImageView = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 04:08:02 +03:00
										 |  |  | 	tag: 'ui-single-image', | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 	depends: [ | 
					
						
							| 
									
										
										
										
											2016-11-20 03:51:53 +03:00
										 |  |  | 		'ui', | 
					
						
							|  |  |  | 		'util', | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 	], | 
					
						
							| 
									
										
										
										
											2016-04-26 03:43:22 +03:00
										 |  |  | 	suggested: [ | 
					
						
							| 
									
										
										
										
											2016-04-26 04:08:02 +03:00
										 |  |  | 		'ui-single-image-local-storage', | 
					
						
							|  |  |  | 		'ui-single-image-autohide-cursor', | 
					
						
							| 
									
										
										
										
											2016-04-26 03:43:22 +03:00
										 |  |  | 	], | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	actions: SingleImageActions, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	handlers:[ | 
					
						
							| 
									
										
										
										
											2016-06-18 20:07:19 +03:00
										 |  |  | 		// update config...
 | 
					
						
							|  |  |  | 		//['resizing.post',
 | 
					
						
							| 
									
										
										
										
											2016-12-02 23:52:56 +03:00
										 |  |  | 		['resizingDone resizingWindow', | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 			function(){  | 
					
						
							| 
									
										
										
										
											2016-04-26 03:43:22 +03:00
										 |  |  | 				// prevent this from doing anything while no viewer...
 | 
					
						
							|  |  |  | 				if(!this.ribbons  | 
					
						
							|  |  |  | 						|| !this.ribbons.viewer  | 
					
						
							|  |  |  | 						|| this.ribbons.getRibbonSet().length == 0){ | 
					
						
							|  |  |  | 					return | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 				// singe image mode -- set image proportions...
 | 
					
						
							|  |  |  | 				if(this.toggleSingleImage('?') == 'on'){ | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | 					this.updateImageProportions() | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-18 20:07:19 +03:00
										 |  |  | 					this.config['single-image-scale']  | 
					
						
							|  |  |  | 						= this[this.config['single-image-scale-unit']] | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2016-06-18 20:07:19 +03:00
										 |  |  | 					this.config['ribbon-scale']  | 
					
						
							|  |  |  | 						= this[this.config['ribbon-scale-unit']]  | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}], | 
					
						
							| 
									
										
										
										
											2016-04-25 02:37:57 +03:00
										 |  |  | 		// update new images...
 | 
					
						
							|  |  |  | 		['resizeRibbon', | 
					
						
							|  |  |  | 			function(){ | 
					
						
							|  |  |  | 				if(this.toggleSingleImage('?') == 'on'){ | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | 					this.updateImageProportions() | 
					
						
							| 
									
										
										
										
											2016-04-25 02:37:57 +03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}], | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 		// NOTE: this is not part of the actual action above because we 
 | 
					
						
							|  |  |  | 		// 		need to see if the state has changed and doing this with 
 | 
					
						
							|  |  |  | 		// 		two separate pre/post callbacks (toggler callbacks) is 
 | 
					
						
							|  |  |  | 		// 		harder than with two nested callbacks (action callbacks)
 | 
					
						
							|  |  |  | 		['toggleSingleImage.pre',  | 
					
						
							|  |  |  | 			function(){  | 
					
						
							|  |  |  | 				var pre_state = this.toggleSingleImage('?') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				return function(){ | 
					
						
							| 
									
										
										
										
											2016-04-29 03:49:18 +03:00
										 |  |  | 					var that = this | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 					var state = this.toggleSingleImage('?') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// singe image mode -- set image proportions...
 | 
					
						
							|  |  |  | 					if(state == 'on'){ | 
					
						
							|  |  |  | 						// update scale...
 | 
					
						
							|  |  |  | 						if(state != pre_state){ | 
					
						
							| 
									
										
										
										
											2016-06-18 20:07:19 +03:00
										 |  |  | 							// save ribbon state...
 | 
					
						
							|  |  |  | 							this.config['ribbon-scale'] | 
					
						
							|  |  |  | 								= this[this.config['ribbon-scale-unit']]  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							// change state...
 | 
					
						
							|  |  |  | 							this[this.config['single-image-scale-unit']] | 
					
						
							|  |  |  | 								= this.config['single-image-scale'] | 
					
						
							|  |  |  | 								= this.config['single-image-scale'] | 
					
						
							| 
									
										
										
										
											2016-05-01 06:13:50 +03:00
										 |  |  | 									|| this[this.config['single-image-scale-unit']] | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-23 01:17:18 +03:00
										 |  |  | 						this.updateImageProportions() | 
					
						
							| 
									
										
										
										
											2016-05-01 06:13:50 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 					// ribbon mode -- restore original image size...
 | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2016-11-23 01:29:19 +03:00
										 |  |  | 						this.ribbons | 
					
						
							|  |  |  | 							.preventTransitions() | 
					
						
							|  |  |  | 							// reset image container size...
 | 
					
						
							|  |  |  | 							.viewer.find('.image:not(.clone)') | 
					
						
							|  |  |  | 								.each(function(_, img){ | 
					
						
							|  |  |  | 									img.style.width = '' | 
					
						
							|  |  |  | 									img.style.height = '' | 
					
						
							|  |  |  | 									img.style.margin = '' | 
					
						
							|  |  |  | 								}) | 
					
						
							| 
									
										
										
										
											2016-11-23 01:21:56 +03:00
										 |  |  | 						this | 
					
						
							| 
									
										
										
										
											2016-11-23 01:24:47 +03:00
										 |  |  | 							// align ribbons...
 | 
					
						
							| 
									
										
										
										
											2016-11-23 01:21:56 +03:00
										 |  |  | 							.alignRibbons('now') | 
					
						
							|  |  |  | 							.ribbons | 
					
						
							|  |  |  | 								.restoreTransitions(true) | 
					
						
							| 
									
										
										
										
											2016-04-28 18:45:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 						// update scale...
 | 
					
						
							|  |  |  | 						if(state != pre_state){ | 
					
						
							| 
									
										
										
										
											2016-06-18 20:07:19 +03:00
										 |  |  | 							// save single image view state...
 | 
					
						
							|  |  |  | 							this.config['single-image-scale'] | 
					
						
							|  |  |  | 								= this[this.config['single-image-scale-unit']] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							// change state...
 | 
					
						
							|  |  |  | 							this[this.config['ribbon-scale-unit']] | 
					
						
							|  |  |  | 								= this.config['ribbon-scale'] | 
					
						
							|  |  |  | 								= this.config['ribbon-scale'] | 
					
						
							| 
									
										
										
										
											2016-05-01 06:13:50 +03:00
										 |  |  | 									|| this[this.config['ribbon-scale-unit']]  | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}], | 
					
						
							| 
									
										
										
										
											2016-11-20 00:04:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Workspace...
 | 
					
						
							|  |  |  | 		// 	...set ribbon focus mode to order (default) in single image mode...
 | 
					
						
							|  |  |  | 		['saveWorkspace', | 
					
						
							| 
									
										
										
										
											2016-11-20 00:57:26 +03:00
										 |  |  | 			core.makeWorkspaceConfigWriter( | 
					
						
							| 
									
										
										
										
											2016-11-20 03:51:53 +03:00
										 |  |  | 				function(){  | 
					
						
							|  |  |  | 					return Object.keys(this.config['single-image-config-defaults'] || {}) })], | 
					
						
							| 
									
										
										
										
											2016-11-26 14:34:12 +03:00
										 |  |  | 		// XXX not sure if manual calling of togglers is the right way 
 | 
					
						
							|  |  |  | 		// 		to go here + it's redundant...
 | 
					
						
							|  |  |  | 		// 		...the reasoning is that togglers can be bound to, so we
 | 
					
						
							|  |  |  | 		// 		need to call the bound code...
 | 
					
						
							| 
									
										
										
										
											2016-11-20 00:04:41 +03:00
										 |  |  | 		['loadWorkspace', | 
					
						
							|  |  |  | 			core.makeWorkspaceConfigLoader( | 
					
						
							| 
									
										
										
										
											2016-11-20 03:51:53 +03:00
										 |  |  | 				function(){  | 
					
						
							|  |  |  | 					return Object.keys(this.config['single-image-config-defaults'] || {}) }, | 
					
						
							| 
									
										
										
										
											2016-11-26 14:34:12 +03:00
										 |  |  | 				// NOTE: options toggled by togglers are triggered here...
 | 
					
						
							|  |  |  | 				// 		XXX do not like this -- manual...
 | 
					
						
							| 
									
										
										
										
											2016-11-20 00:04:41 +03:00
										 |  |  | 				function(workspace){ | 
					
						
							| 
									
										
										
										
											2016-11-20 00:57:26 +03:00
										 |  |  | 					'ribbon-focus-mode' in workspace | 
					
						
							|  |  |  | 						&& this.toggleRibbonFocusMode(workspace['ribbon-focus-mode']) | 
					
						
							| 
									
										
										
										
											2016-11-26 15:46:44 +03:00
										 |  |  | 					'shifts-affect-direction' in workspace | 
					
						
							|  |  |  | 						&& this.toggleShiftsAffectDirection(workspace['shifts-affect-direction']) | 
					
						
							| 
									
										
										
										
											2016-11-20 00:04:41 +03:00
										 |  |  | 				})], | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 	], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var SingleImageViewLocalStorage = | 
					
						
							|  |  |  | module.SingleImageViewLocalStorage = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 04:08:02 +03:00
										 |  |  | 	tag: 'ui-single-image-local-storage', | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 	depends: [ | 
					
						
							| 
									
										
										
										
											2016-04-26 04:08:02 +03:00
										 |  |  | 		'ui-single-image', | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 		'config-local-storage', | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	handlers:[ | 
					
						
							|  |  |  | 		// set scale...
 | 
					
						
							| 
									
										
										
										
											2016-04-26 03:43:22 +03:00
										 |  |  | 		['load.pre', | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 			function(){ | 
					
						
							| 
									
										
										
										
											2016-04-26 03:43:22 +03:00
										 |  |  | 				// NOTE: at this stage the viewer is not yet ready, and
 | 
					
						
							|  |  |  | 				// 		we need to save these for when it is, thus avoiding
 | 
					
						
							|  |  |  | 				// 		stray actions overwriting the config with defaults
 | 
					
						
							|  |  |  | 				// 		when not finding a value in the viewer...
 | 
					
						
							| 
									
										
										
										
											2016-05-01 06:13:50 +03:00
										 |  |  | 				var rscale = this.config['ribbon-scale'] | 
					
						
							|  |  |  | 					|| this[this.config['ribbon-scale-unit']]  | 
					
						
							|  |  |  | 				var iscale = this.config['single-image-scale'] | 
					
						
							|  |  |  | 					|| this[this.config['single-image-scale-unit']] | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 03:43:22 +03:00
										 |  |  | 				return function(){ | 
					
						
							|  |  |  | 					// prevent this from doing anything while no viewer...
 | 
					
						
							|  |  |  | 					if(!this.ribbons  | 
					
						
							|  |  |  | 							|| !this.ribbons.viewer  | 
					
						
							|  |  |  | 							|| this.ribbons.getRibbonSet().length == 0){ | 
					
						
							|  |  |  | 						return | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-01 06:22:13 +03:00
										 |  |  | 					if(this.toggleSingleImage('?') == 'on'){ | 
					
						
							|  |  |  | 						this[this.config['single-image-scale-unit']] = iscale | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						this[this.config['ribbon-scale-unit']] = rscale | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}], | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This will store/restore autohide state for single-image and ribbon 
 | 
					
						
							|  |  |  | // views...
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // NOTE: chrome 49 + devtools open appears to prevent the cursor from being hidden...
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // XXX hiding cursor on navigation for some reason does not work...
 | 
					
						
							|  |  |  | var SingleImageAutoHideCursor =  | 
					
						
							|  |  |  | module.SingleImageAutoHideCursor = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-26 04:08:02 +03:00
										 |  |  | 	tag: 'ui-single-image-autohide-cursor', | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 	depends: [ | 
					
						
							|  |  |  | 		'ui-autohide-cursor', | 
					
						
							| 
									
										
										
										
											2016-04-26 04:08:02 +03:00
										 |  |  | 		'ui-single-image', | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | 	], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	config: { | 
					
						
							|  |  |  | 		'cursor-autohide-single-image-view': 'on', | 
					
						
							|  |  |  | 		'cursor-autohide-ribbon-view': 'off', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//'cursor-autohide-on-navigate': true, 
 | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	handlers: [ | 
					
						
							|  |  |  | 		// setup...
 | 
					
						
							|  |  |  | 		['load', | 
					
						
							|  |  |  | 			function(){ | 
					
						
							|  |  |  | 				var mode = this.toggleSingleImage('?') == 'on' ?  | 
					
						
							|  |  |  | 					'cursor-autohide-single-image-view' | 
					
						
							|  |  |  | 					: 'cursor-autohide-ribbon-view' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				this.toggleAutoHideCursor(this.config[mode] || 'off') | 
					
						
							|  |  |  | 			}], | 
					
						
							|  |  |  | 		// store state for each mode...
 | 
					
						
							|  |  |  | 		['toggleAutoHideCursor', | 
					
						
							|  |  |  | 			function(){ | 
					
						
							|  |  |  | 				var mode = this.toggleSingleImage('?') == 'on' ?  | 
					
						
							|  |  |  | 					'cursor-autohide-single-image-view' | 
					
						
							|  |  |  | 					: 'cursor-autohide-ribbon-view' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				this.config[mode] = this.toggleAutoHideCursor('?') | 
					
						
							|  |  |  | 			}], | 
					
						
							|  |  |  | 		// restore state per mode...
 | 
					
						
							|  |  |  | 		['toggleSingleImage',  | 
					
						
							|  |  |  | 			function(){ | 
					
						
							|  |  |  | 				if(this.toggleSingleImage('?') == 'on'){ | 
					
						
							|  |  |  | 					this.toggleAutoHideCursor(this.config['cursor-autohide-single-image-view']) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					this.toggleAutoHideCursor(this.config['cursor-autohide-ribbon-view']) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}], | 
					
						
							|  |  |  | 		/* XXX for some reason this does not work... | 
					
						
							|  |  |  | 		// autohide on navigation...
 | 
					
						
							|  |  |  | 		['focusImage',  | 
					
						
							|  |  |  | 			function(){ | 
					
						
							|  |  |  | 				//if(this.config['cursor-autohide-on-navigate'] 
 | 
					
						
							|  |  |  | 				//		&& this.toggleAutoHideCursor('?') == 'on'){
 | 
					
						
							|  |  |  | 				//	this.toggleAutoHideCursor('on')
 | 
					
						
							|  |  |  | 				//}
 | 
					
						
							|  |  |  | 				if(this.config['cursor-autohide-on-navigate']  | 
					
						
							|  |  |  | 						&& this.toggleAutoHideCursor('?') == 'on' | 
					
						
							|  |  |  | 						&& this.ribbons.viewer.prop('cursor-autohide')){ | 
					
						
							|  |  |  | 					this.ribbons.viewer | 
					
						
							|  |  |  | 						.addClass('cursor-hidden') | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}], | 
					
						
							|  |  |  | 		*/ | 
					
						
							|  |  |  | 	] | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							| 
									
										
										
										
											2016-08-20 22:49:36 +03:00
										 |  |  | * vim:set ts=4 sw=4 :                               */ return module }) |