| 
									
										
										
										
											2015-12-17 03:34:20 +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
										 |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 18:27:59 +03:00
										 |  |  | if(typeof(process) != 'undefined'){ | 
					
						
							|  |  |  | 	var pathlib = requirejs('path') | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var actions = require('lib/actions') | 
					
						
							|  |  |  | var features = require('lib/features') | 
					
						
							| 
									
										
										
										
											2016-04-09 18:39:01 +03:00
										 |  |  | var toggler = require('lib/toggler') | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var core = require('features/core') | 
					
						
							|  |  |  | var base = require('features/base') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var AppControlActions = actions.Actions({ | 
					
						
							|  |  |  | 	config: { | 
					
						
							|  |  |  | 		'window-title': 'ImageGrid.Viewer (${VERSION}): ${FILENAME}', | 
					
						
							| 
									
										
										
										
											2016-04-15 02:09:02 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		'window-delay-initial-display': 200, | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XXX revise these...
 | 
					
						
							|  |  |  | 	close: ['File|Interface/Close viewer', | 
					
						
							|  |  |  | 		function(){ window.close() }], | 
					
						
							|  |  |  | 	storeWindowGeometry: ['- Interface/Store window state', | 
					
						
							|  |  |  | 		function(){ | 
					
						
							|  |  |  | 			// store window parameters (size, state)...
 | 
					
						
							| 
									
										
										
										
											2016-04-09 18:39:01 +03:00
										 |  |  | 			var win = nw.Window.get() | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// fullscreen...
 | 
					
						
							|  |  |  | 			// ...avoid overwriting size...
 | 
					
						
							| 
									
										
										
										
											2016-04-09 18:39:01 +03:00
										 |  |  | 			if(this.toggleFullScreen('?') == 'on'){ | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 				this.config.window = this.config.window || {} | 
					
						
							|  |  |  | 				this.config.window.fullscreen = true | 
					
						
							|  |  |  | 				this.config.window.zoom = win.zoomLevel  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				this.config.window = { | 
					
						
							|  |  |  | 					size: { | 
					
						
							|  |  |  | 						width: win.width, | 
					
						
							|  |  |  | 						height: win.height, | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					fullscreen: false, | 
					
						
							|  |  |  | 					zoom: win.zoomLevel , | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 	restoreWindowGeometry: ['- Interface/Restore window state', | 
					
						
							|  |  |  | 		function(){ | 
					
						
							| 
									
										
										
										
											2016-05-08 15:58:22 +03:00
										 |  |  | 			var that = this | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 			// or global.window.nwDispatcher.requireNwGui()
 | 
					
						
							|  |  |  | 			// (see: https://github.com/rogerwang/node-webkit/issues/707)
 | 
					
						
							| 
									
										
										
										
											2016-04-09 18:39:01 +03:00
										 |  |  | 			var win = nw.Window.get() | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// XXX move this into .restoreWindowGeometry(..)
 | 
					
						
							|  |  |  | 			// get window state from config and load it...
 | 
					
						
							|  |  |  | 			var cfg = this.config.window | 
					
						
							|  |  |  | 			if(cfg != null){ | 
					
						
							|  |  |  | 				var W = screen.width | 
					
						
							|  |  |  | 				var H = screen.height | 
					
						
							|  |  |  | 				var w = 800 | 
					
						
							|  |  |  | 				var h = 600 | 
					
						
							|  |  |  | 				var s = cfg.scale | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(cfg.size){ | 
					
						
							|  |  |  | 					w = win.width = Math.min(cfg.size.width, screen.width) | 
					
						
							|  |  |  | 					h = win.height = Math.min(cfg.size.height, screen.height) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// place on center of the screen...
 | 
					
						
							|  |  |  | 				var x = win.x = (W - w)/2 | 
					
						
							|  |  |  | 				var y = win.y = (H - h)/2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(s){ | 
					
						
							|  |  |  | 					win.zoomLevel = s | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				//console.log('GEOMETRY:', w, h, x, y)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				this.centerViewer() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* XXX still buggy.... | 
					
						
							|  |  |  | 			// restore interface scale...
 | 
					
						
							|  |  |  | 			this.toggleInterfaceScale( | 
					
						
							|  |  |  | 				this.config['ui-scale-mode']  | 
					
						
							|  |  |  | 				|| this.toggleInterfaceScale('??')[0]) | 
					
						
							|  |  |  | 			*/ | 
					
						
							| 
									
										
										
										
											2016-04-15 02:09:02 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// NOTE: we delay this to enable the browser time to render
 | 
					
						
							|  |  |  | 			// 		things before we show them to the user...
 | 
					
						
							|  |  |  | 			setTimeout(function(){ | 
					
						
							|  |  |  | 				win.show() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// XXX check if we are full screen...
 | 
					
						
							| 
									
										
										
										
											2016-05-08 19:03:04 +03:00
										 |  |  | 				if(cfg != null && cfg.fullscreen){ | 
					
						
							| 
									
										
										
										
											2016-05-08 15:58:22 +03:00
										 |  |  | 					that.toggleFullScreen('on') | 
					
						
							| 
									
										
										
										
											2016-04-15 02:09:02 +03:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}, this.config['window-delay-initial-display'] || 0) | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2016-04-09 18:39:01 +03:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2016-05-05 01:32:47 +03:00
										 |  |  | 	minimize: ['Interface/Minimize', | 
					
						
							|  |  |  | 		function(){ | 
					
						
							|  |  |  | 			nw.Window.get().minimize() | 
					
						
							|  |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	toggleFullScreen: ['Interface/Toggle full screen mode', | 
					
						
							| 
									
										
										
										
											2016-04-09 18:39:01 +03:00
										 |  |  | 		toggler.CSSClassToggler( | 
					
						
							|  |  |  | 			function(){ return document.body },  | 
					
						
							|  |  |  | 			'.full-screen-mode', | 
					
						
							|  |  |  | 			function(action){ | 
					
						
							|  |  |  | 				var that = this | 
					
						
							|  |  |  | 				var w = nw.Window.get() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// change the state only if the target state is not the same
 | 
					
						
							|  |  |  | 				// as the current state...
 | 
					
						
							| 
									
										
										
										
											2016-04-15 06:03:03 +03:00
										 |  |  | 				if((w.isFullscreen ? 'on' : 'off') != action){ | 
					
						
							| 
									
										
										
										
											2016-04-09 18:39:01 +03:00
										 |  |  | 					this.ribbons.preventTransitions() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// hide the viewer to hide any animation crimes...
 | 
					
						
							|  |  |  | 					this.ribbons.viewer[0].style.visibility = 'hidden' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// XXX async...
 | 
					
						
							|  |  |  | 					// 		...this complicates things as we need to do the next
 | 
					
						
							|  |  |  | 					// 		bit AFTER the resize is done...
 | 
					
						
							|  |  |  | 					w.toggleFullscreen() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					setTimeout(function(){  | 
					
						
							|  |  |  | 						that | 
					
						
							|  |  |  | 							.centerViewer() | 
					
						
							|  |  |  | 							.focusImage() | 
					
						
							|  |  |  | 							.ribbons | 
					
						
							|  |  |  | 								.restoreTransitions() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						that.ribbons.viewer[0].style.visibility = '' | 
					
						
							|  |  |  | 					}, 100) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// NOTE: we delay this to account for window animation...
 | 
					
						
							|  |  |  | 				setTimeout(function(){  | 
					
						
							|  |  |  | 					that.storeWindowGeometry()  | 
					
						
							|  |  |  | 				}, 500) | 
					
						
							|  |  |  | 			})], | 
					
						
							| 
									
										
										
										
											2016-05-08 16:13:19 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// XXX add ability to use devtools on background page (node context)...
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	showDevTools: ['Interface|Development/Show Dev Tools', | 
					
						
							|  |  |  | 		function(){ | 
					
						
							| 
									
										
										
										
											2016-04-09 18:39:01 +03:00
										 |  |  | 			nw.Window.get().showDevTools && | 
					
						
							|  |  |  | 				nw.Window.get().showDevTools() | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2016-05-08 18:27:59 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// XXX should this be here???
 | 
					
						
							|  |  |  | 	showInFolder: ['File|Image/Show in folder', | 
					
						
							|  |  |  | 		function(image){ | 
					
						
							|  |  |  | 			image = this.images[this.data.getImage(image)] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var base = image.base_path || this.location.path | 
					
						
							|  |  |  | 			var filename = image.path | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			path = pathlib.normalize(base + '/' + filename) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			nw.Shell.showItemInFolder(path) | 
					
						
							|  |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX this needs a better .isApplicable(..)
 | 
					
						
							|  |  |  | // XXX store/load window state...
 | 
					
						
							|  |  |  | // 		- size
 | 
					
						
							|  |  |  | // 		- state (fullscreen/normal)
 | 
					
						
							|  |  |  | var AppControl =  | 
					
						
							|  |  |  | module.AppControl = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 10:37:21 +03:00
										 |  |  | 	tag: 'ui-app-control', | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	depends: [ | 
					
						
							|  |  |  | 		'ui', | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	actions: AppControlActions, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XXX test if in:
 | 
					
						
							|  |  |  | 	// 	- chrome app
 | 
					
						
							|  |  |  | 	// 	- nw
 | 
					
						
							|  |  |  | 	// 	- mobile
 | 
					
						
							| 
									
										
										
										
											2015-12-31 10:37:21 +03:00
										 |  |  | 	isApplicable: function(){ return this.runtime == 'nw' }, | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// XXX show main window...
 | 
					
						
							|  |  |  | 	handlers: [ | 
					
						
							|  |  |  | 		['start', | 
					
						
							|  |  |  | 			function(){  | 
					
						
							|  |  |  | 				// XXX this messes up ribbon scale...
 | 
					
						
							|  |  |  | 				// 		...to close/fast?
 | 
					
						
							|  |  |  | 				//this.toggleInterfaceScale('!')
 | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 				this.restoreWindowGeometry() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			}], | 
					
						
							|  |  |  | 		[[ | 
					
						
							|  |  |  | 			'close.pre', | 
					
						
							|  |  |  | 			'toggleFullScreen', | 
					
						
							|  |  |  | 		], | 
					
						
							|  |  |  | 			function(){ this.storeWindowGeometry() }], | 
					
						
							|  |  |  | 		['focusImage', | 
					
						
							|  |  |  | 			function(){ | 
					
						
							| 
									
										
										
										
											2016-04-09 18:39:01 +03:00
										 |  |  | 				var win = nw.Window.get() | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if(this.images){ | 
					
						
							|  |  |  | 					var img = this.images[this.current] | 
					
						
							|  |  |  | 					win.title = (this.config['window-title']  | 
					
						
							|  |  |  | 							|| 'ImageGrid.Viewer (${VERSION}): ${FILENAME}') | 
					
						
							|  |  |  | 						// XXX get this from the viewer...
 | 
					
						
							|  |  |  | 						.replace('${VERSION}', this.version || 'gen4') | 
					
						
							|  |  |  | 						.replace('${FILENAME}',  | 
					
						
							| 
									
										
										
										
											2016-04-08 19:28:38 +03:00
										 |  |  | 							img ?  | 
					
						
							|  |  |  | 									(img.name || img.path.replace(/\.[\\\/]/, '')) | 
					
						
							|  |  |  | 								: '') | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 						.replace('${PATH}',  | 
					
						
							| 
									
										
										
										
											2016-04-08 19:28:38 +03:00
										 |  |  | 							img ? | 
					
						
							|  |  |  | 									(img.base_path || '.')  | 
					
						
							|  |  |  | 										+'/'+ img.path.replace(/\.[\\\/]/, '') | 
					
						
							|  |  |  | 								: '') | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 						/* | 
					
						
							|  |  |  | 						.replace('${DIR}',  | 
					
						
							|  |  |  | 							pathlib.dirname((img.base_path || '.')  | 
					
						
							|  |  |  | 								+'/'+ img.path.replace(/\.[\\\/]/, ''))) | 
					
						
							|  |  |  | 						*/ | 
					
						
							|  |  |  | 						// XXX add ...
 | 
					
						
							|  |  |  | 						 | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}], | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-05 01:32:47 +03:00
										 |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | // Fullscreen app control buttons...
 | 
					
						
							|  |  |  | var FullScreenControllsActions = actions.Actions({ | 
					
						
							|  |  |  | 	toggleFullScreenControls: ['Interface/', | 
					
						
							|  |  |  | 		toggler.Toggler(null, | 
					
						
							|  |  |  | 			function(){  | 
					
						
							|  |  |  | 				return this.ribbons.viewer.find('.fullscreen-controls').length > 0 ? 'on' : 'off' }, | 
					
						
							|  |  |  | 			['off', 'on'], | 
					
						
							|  |  |  | 			function(state){ | 
					
						
							|  |  |  | 				// clear the controls....
 | 
					
						
							|  |  |  | 				this.ribbons.viewer.find('.fullscreen-controls').remove() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(state == 'on'){ | 
					
						
							|  |  |  | 					var that = this | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					$('<div>') | 
					
						
							|  |  |  | 						.addClass('fullscreen-controls') | 
					
						
							|  |  |  | 						// minimize....
 | 
					
						
							|  |  |  | 						.append($('<div>') | 
					
						
							|  |  |  | 							.addClass('button') | 
					
						
							|  |  |  | 							.html('_') | 
					
						
							|  |  |  | 							.click(function(){ that.minimize() })) | 
					
						
							|  |  |  | 						// fullscreen....
 | 
					
						
							|  |  |  | 						.append($('<div>') | 
					
						
							|  |  |  | 							.addClass('button') | 
					
						
							| 
									
										
										
										
											2016-06-03 04:46:51 +03:00
										 |  |  | 							// square...
 | 
					
						
							|  |  |  | 							//.html('□')
 | 
					
						
							|  |  |  | 							// diagonal arrows...
 | 
					
						
							|  |  |  | 							.html('↙') | 
					
						
							| 
									
										
										
										
											2016-05-05 01:32:47 +03:00
										 |  |  | 							.click(function(){ that.toggleFullScreen() })) | 
					
						
							|  |  |  | 						// close...
 | 
					
						
							|  |  |  | 						.append($('<div>') | 
					
						
							|  |  |  | 							.addClass('button close') | 
					
						
							|  |  |  | 							.html('×') | 
					
						
							|  |  |  | 							.click(function(){ that.close() })) | 
					
						
							|  |  |  | 						.appendTo(this.ribbons.viewer) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			})], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var FullScreenControlls =  | 
					
						
							|  |  |  | module.FullScreenControlls = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'ui-fullscreen-controls', | 
					
						
							|  |  |  | 	depends: [ | 
					
						
							|  |  |  | 		'ui-app-control', | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	actions: FullScreenControllsActions, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	handlers: [ | 
					
						
							|  |  |  | 		['toggleFullScreen',  | 
					
						
							|  |  |  | 			function(){ | 
					
						
							|  |  |  | 				this.toggleFullScreenControls(this.toggleFullScreen('?')) | 
					
						
							|  |  |  | 			}], | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | /********************************************************************** | 
					
						
							| 
									
										
										
										
											2016-08-20 22:49:36 +03:00
										 |  |  | * vim:set ts=4 sw=4 :                               */ return module }) |