| 
									
										
										
										
											2016-03-12 06:24:35 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | define(function(require){ var module = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var toggler = require('lib/toggler') | 
					
						
							|  |  |  | var actions = require('lib/actions') | 
					
						
							|  |  |  | var features = require('lib/features') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var core = require('features/core') | 
					
						
							|  |  |  | var base = require('features/base') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | var browse = require('lib/widget/browse') | 
					
						
							|  |  |  | var overlay = require('lib/widget/overlay') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-12 06:24:35 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | // XXX still needs work...
 | 
					
						
							| 
									
										
										
										
											2016-03-12 06:24:35 +03:00
										 |  |  | var SlideshowActions = actions.Actions({ | 
					
						
							|  |  |  | 	config: { | 
					
						
							| 
									
										
										
										
											2016-03-28 21:46:05 +03:00
										 |  |  | 		'ui-slideshow-looping': 'on', | 
					
						
							|  |  |  | 		'ui-slideshow-direction': 'forward', | 
					
						
							| 
									
										
										
										
											2016-03-27 20:07:48 +03:00
										 |  |  | 		'ui-slideshow-interval': '3s', | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 		'ui-slideshow-intervals': [ | 
					
						
							| 
									
										
										
										
											2016-03-27 20:07:48 +03:00
										 |  |  | 			'0.2s', | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 			'1s', | 
					
						
							| 
									
										
										
										
											2016-03-27 20:07:48 +03:00
										 |  |  | 			'3s', | 
					
						
							|  |  |  | 			'5s', | 
					
						
							|  |  |  | 			'7s', | 
					
						
							|  |  |  | 		], | 
					
						
							| 
									
										
										
										
											2016-03-12 06:24:35 +03:00
										 |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 	// XXX make interval editable...
 | 
					
						
							| 
									
										
										
										
											2016-03-12 06:24:35 +03:00
										 |  |  | 	// 		i.e.
 | 
					
						
							|  |  |  | 	// 			Interval: 3s /		-- 3s is editable...
 | 
					
						
							|  |  |  | 	// 				0.2		x		-- a history of values that can be 
 | 
					
						
							|  |  |  | 	// 									selected w/o closing the dialog
 | 
					
						
							|  |  |  | 	// 									or can be removed...
 | 
					
						
							|  |  |  | 	// 				1		x
 | 
					
						
							|  |  |  | 	// 				3		x
 | 
					
						
							|  |  |  | 	// 				Custom...		-- editable/placeholder... 'enter' 
 | 
					
						
							|  |  |  | 	// 									selects value and adds it to 
 | 
					
						
							|  |  |  | 	// 									history...
 | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 	// XXX BUG: there are still problems with focus...
 | 
					
						
							|  |  |  | 	// 		to reproduce:
 | 
					
						
							|  |  |  | 	// 			click on the first option with a mouse...
 | 
					
						
							|  |  |  | 	// 		result:
 | 
					
						
							|  |  |  | 	// 			the top dialog is not focused...
 | 
					
						
							|  |  |  | 	slideshowDialog: ['Slideshow/Toggle and options', | 
					
						
							|  |  |  | 		function(){ | 
					
						
							|  |  |  | 			var that = this | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			this.suspendSlideshowTimer() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var o = overlay.Overlay(this.ribbons.viewer,  | 
					
						
							|  |  |  | 				browse.makeList( | 
					
						
							|  |  |  | 					null, | 
					
						
							|  |  |  | 					[ | 
					
						
							|  |  |  | 						['Interval: ',  | 
					
						
							|  |  |  | 							function(){ return that.config['ui-slideshow-interval'] }], | 
					
						
							|  |  |  | 						['Direction: ',  | 
					
						
							|  |  |  | 							function(){ return that.config['ui-slideshow-direction'] }], | 
					
						
							|  |  |  | 						['Looping: ',  | 
					
						
							|  |  |  | 							function(){ return that.config['ui-slideshow-looping'] }], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						'---', | 
					
						
							|  |  |  | 						[function(){  | 
					
						
							|  |  |  | 							return that.toggleSlideshow('?') == 'on' ? 'Stop' : 'Start' }], | 
					
						
							|  |  |  | 					]) | 
					
						
							|  |  |  | 					.open(function(evt, path){ | 
					
						
							|  |  |  | 						// start/stop...
 | 
					
						
							|  |  |  | 						if(path == 'Start' || path == 'Stop'){ | 
					
						
							|  |  |  | 							that.toggleSlideshow() | 
					
						
							|  |  |  | 							o.close() | 
					
						
							|  |  |  | 							return | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// interval...
 | 
					
						
							|  |  |  | 						// XXX add custom interval editing...
 | 
					
						
							|  |  |  | 						if(/interval/i.test(path)){ | 
					
						
							|  |  |  | 							var to_remove = [] | 
					
						
							|  |  |  | 							var oo = overlay.Overlay(that.ribbons.viewer,  | 
					
						
							|  |  |  | 								browse.makeList( null,  | 
					
						
							|  |  |  | 									that.config['ui-slideshow-intervals'],  | 
					
						
							|  |  |  | 									{itemButtons: [ | 
					
						
							|  |  |  | 										// mark for removal...
 | 
					
						
							|  |  |  | 										['×',  | 
					
						
							|  |  |  | 											function(p){ | 
					
						
							|  |  |  | 												var e = this.filter('"'+p+'"', false) | 
					
						
							|  |  |  | 													.toggleClass('strike-out') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 												if(e.hasClass('strike-out')){ | 
					
						
							|  |  |  | 													to_remove.indexOf(p) < 0  | 
					
						
							|  |  |  | 														&& to_remove.push(p) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 												} else { | 
					
						
							|  |  |  | 													var i = to_remove.indexOf(p) | 
					
						
							|  |  |  | 													if(i >= 0){ | 
					
						
							|  |  |  | 														to_remove.splice(i, 1) | 
					
						
							|  |  |  | 													} | 
					
						
							|  |  |  | 												} | 
					
						
							|  |  |  | 											}], | 
					
						
							|  |  |  | 									]}) | 
					
						
							|  |  |  | 									.open(function(evt, time){ | 
					
						
							|  |  |  | 										that.config['ui-slideshow-interval'] = time | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 										// XXX this is ugly...
 | 
					
						
							|  |  |  | 										oo.close() | 
					
						
							|  |  |  | 										o.client.update() | 
					
						
							|  |  |  | 										o.client.select(path.split(':')[0]) | 
					
						
							|  |  |  | 									})) | 
					
						
							|  |  |  | 								.close(function(){ | 
					
						
							|  |  |  | 									// remove striked items...
 | 
					
						
							|  |  |  | 									to_remove.forEach(function(e){ | 
					
						
							|  |  |  | 										var lst = that.config['ui-slideshow-intervals'].slice() | 
					
						
							|  |  |  | 										lst.splice(lst.indexOf(e), 1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 										that.config['ui-slideshow-intervals'] = lst | 
					
						
							|  |  |  | 									}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 									// XXX this is ugly...
 | 
					
						
							|  |  |  | 									o.focus() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 									if(that.toggleSlideshow('?') == 'on'){ | 
					
						
							|  |  |  | 										o.close() | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							oo.client.select(that.config['ui-slideshow-interval']) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							return | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// direction...
 | 
					
						
							|  |  |  | 						if(/direction/i.test(path)){ | 
					
						
							|  |  |  | 							that.toggleSlideshowDirection() | 
					
						
							|  |  |  | 							o.client.update() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// Looping...
 | 
					
						
							|  |  |  | 						} else if(/looping/i.test(path)){ | 
					
						
							|  |  |  | 							that.toggleSlideshowLooping() | 
					
						
							|  |  |  | 							o.client.update() | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// XXX this is ugly...
 | 
					
						
							|  |  |  | 						o.client.select(path.split(':')[0]) | 
					
						
							| 
									
										
										
										
											2016-03-28 21:46:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 						// do not keep the dialog open during the slideshow...
 | 
					
						
							|  |  |  | 						if(that.toggleSlideshow('?') == 'on'){ | 
					
						
							|  |  |  | 							o.close() | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					})) | 
					
						
							|  |  |  | 				.close(function(){ | 
					
						
							|  |  |  | 					that.resetSlideshowTimer() | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			o.client.dom.addClass('metadata-view') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			o.client.select(-1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return o | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// XXX add a custom time setting...
 | 
					
						
							|  |  |  | 	toggleSlideshowInterval: ['- Slideshow/Interval', | 
					
						
							|  |  |  | 		core.makeConfigToggler('ui-slideshow-interval',  | 
					
						
							|  |  |  | 			function(){ return this.config['ui-slideshow-intervals'] }, | 
					
						
							|  |  |  | 			function(){ this.resetSlideshowTimer() })], | 
					
						
							|  |  |  | 	toggleSlideshowDirection: ['- Slideshow/Direction', | 
					
						
							| 
									
										
										
										
											2016-03-28 22:07:38 +03:00
										 |  |  | 		core.makeConfigToggler('ui-slideshow-direction', ['forward', 'reverse'])], | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 	toggleSlideshowLooping: ['- Slideshow/Looping', | 
					
						
							| 
									
										
										
										
											2016-03-28 22:07:38 +03:00
										 |  |  | 		core.makeConfigToggler('ui-slideshow-looping', ['on', 'off'])], | 
					
						
							| 
									
										
										
										
											2016-03-29 00:31:50 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 	toggleSlideshow: ['Slideshow/Quick toggle', | 
					
						
							| 
									
										
										
										
											2016-03-28 21:46:05 +03:00
										 |  |  | 		toggler.CSSClassToggler( | 
					
						
							|  |  |  | 			function(){ return this.ribbons.viewer },  | 
					
						
							|  |  |  | 			'slideshow-running', | 
					
						
							|  |  |  | 			function(state){ | 
					
						
							|  |  |  | 				// start...
 | 
					
						
							|  |  |  | 				if(state == 'on'){ | 
					
						
							|  |  |  | 					var that = this | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// reset the timer...
 | 
					
						
							|  |  |  | 					// NOTE: this means we were in a slideshow mode so we do not
 | 
					
						
							|  |  |  | 					// 		need to prepare...
 | 
					
						
							|  |  |  | 					if(this.__slideshouw_timer){ | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 						this.__slideshouw_timer != 'suspended' | 
					
						
							|  |  |  | 							&& clearInterval(this.__slideshouw_timer) | 
					
						
							| 
									
										
										
										
											2016-03-28 21:46:05 +03:00
										 |  |  | 						delete this.__slideshouw_timer | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// prepare for the slideshow...
 | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2016-03-29 00:31:50 +03:00
										 |  |  | 						// save current workspace...
 | 
					
						
							|  |  |  | 						this.__pre_slideshow_workspace = this.workspace | 
					
						
							|  |  |  | 						this.saveWorkspace()  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// construct the slideshow workspace if it does not exist...
 | 
					
						
							|  |  |  | 						if(this.workspaces['slideshow'] == null){ | 
					
						
							|  |  |  | 							this.toggleChrome('off') | 
					
						
							|  |  |  | 							this.saveWorkspace('slideshow')  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// load the slideshow workspace...
 | 
					
						
							|  |  |  | 						} else { | 
					
						
							|  |  |  | 							this.loadWorkspace('slideshow') | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2016-03-28 21:46:05 +03:00
										 |  |  | 				 | 
					
						
							|  |  |  | 						// single image mode...
 | 
					
						
							|  |  |  | 						this.toggleSingleImage('on') | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// start the timer... 
 | 
					
						
							|  |  |  | 					// XXX might be a good idea to add a pause button for either
 | 
					
						
							|  |  |  | 					// 		"toggle" or "hold to pause" mode...
 | 
					
						
							|  |  |  | 					this.__slideshouw_timer = setInterval(function(){ | 
					
						
							|  |  |  | 						var cur = that.current | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// next step...
 | 
					
						
							|  |  |  | 						that.config['ui-slideshow-direction'] == 'forward' ? | 
					
						
							|  |  |  | 							that.nextImage() | 
					
						
							|  |  |  | 							: that.prevImage() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						// we have reached the end...
 | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 						if(that.current == cur){ | 
					
						
							|  |  |  | 							// loop...
 | 
					
						
							|  |  |  | 							if(that.config['ui-slideshow-looping'] == 'on'){ | 
					
						
							|  |  |  | 								that.config['ui-slideshow-direction'] == 'forward' ? | 
					
						
							|  |  |  | 									that.firstImage() | 
					
						
							|  |  |  | 									: that.lastImage() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							// stop...
 | 
					
						
							|  |  |  | 							} else { | 
					
						
							|  |  |  | 								that.toggleSlideshow('off') | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2016-03-28 21:46:05 +03:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					}, Date.str2ms(this.config['ui-slideshow-interval'] || '3s')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				// stop...
 | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2016-03-29 00:58:20 +03:00
										 |  |  | 					this.saveWorkspace('slideshow')  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-28 21:46:05 +03:00
										 |  |  | 					// stop timer...
 | 
					
						
							| 
									
										
										
										
											2016-03-29 00:31:50 +03:00
										 |  |  | 					this.__slideshouw_timer | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 						&& clearInterval(this.__slideshouw_timer) | 
					
						
							| 
									
										
										
										
											2016-03-28 21:46:05 +03:00
										 |  |  | 					delete this.__slideshouw_timer | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-29 00:31:50 +03:00
										 |  |  | 					// XXX should this be a dedicated slideshow workspace??
 | 
					
						
							|  |  |  | 					this.__pre_slideshow_workspace && | 
					
						
							|  |  |  | 						this.loadWorkspace(this.__pre_slideshow_workspace) | 
					
						
							|  |  |  | 					delete this.__pre_slideshow_workspace | 
					
						
							| 
									
										
										
										
											2016-03-27 20:07:48 +03:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-03-28 21:46:05 +03:00
										 |  |  | 			})], | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// NOTE: these can be used as pause and resume...
 | 
					
						
							|  |  |  | 	resetSlideshowTimer: ['- Slideshow/', | 
					
						
							| 
									
										
										
										
											2016-03-27 20:07:48 +03:00
										 |  |  | 		function(){ | 
					
						
							| 
									
										
										
										
											2016-03-28 21:46:05 +03:00
										 |  |  | 			this.__slideshouw_timer && this.toggleSlideshow('on') | 
					
						
							| 
									
										
										
										
											2016-03-27 20:07:48 +03:00
										 |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2016-03-29 03:09:31 +03:00
										 |  |  | 	suspendSlideshowTimer: ['- Slideshow/', | 
					
						
							|  |  |  | 		function(){ | 
					
						
							|  |  |  | 			if(this.__slideshouw_timer){ | 
					
						
							|  |  |  | 				clearInterval(this.__slideshouw_timer) | 
					
						
							|  |  |  | 				this.__slideshouw_timer = 'suspended' | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							| 
									
										
										
										
											2016-03-12 06:24:35 +03:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var Slideshow =  | 
					
						
							|  |  |  | module.Slideshow = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'ui-slideshow', | 
					
						
							|  |  |  | 	depends: [ | 
					
						
							| 
									
										
										
										
											2016-03-29 00:31:50 +03:00
										 |  |  | 		'workspace', | 
					
						
							| 
									
										
										
										
											2016-03-12 06:24:35 +03:00
										 |  |  | 		'ui', | 
					
						
							| 
									
										
										
										
											2016-03-27 20:07:48 +03:00
										 |  |  | 		'ui-single-image-view', | 
					
						
							| 
									
										
										
										
											2016-03-12 06:24:35 +03:00
										 |  |  | 	], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	actions: SlideshowActions, | 
					
						
							| 
									
										
										
										
											2016-03-29 00:31:50 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	handlers: [ | 
					
						
							|  |  |  | 		['stop', | 
					
						
							|  |  |  | 			function(){ this.toggleSlideshow('off') }] | 
					
						
							|  |  |  | 	], | 
					
						
							| 
									
										
										
										
											2016-03-12 06:24:35 +03:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ | 
					
						
							|  |  |  | return module }) |