mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	added action handler tags (siplifies removal) + minor tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									b1221f6c8f
								
							
						
					
					
						commit
						9317ea0566
					
				| @ -33,9 +33,9 @@ | |||||||
| 	height: auto; | 	height: auto; | ||||||
| 	background: black; | 	background: black; | ||||||
| 
 | 
 | ||||||
| 	-webkit-transition: all 0.2s ease-in; | 	-webkit-transition: all 0.1s ease-in; | ||||||
| 	-moz-transition: all 0.2s ease-in; | 	-moz-transition: all 0.1s ease-in; | ||||||
| 	transition: all 0.2s ease-in; | 	transition: all 0.1s ease-in; | ||||||
| } | } | ||||||
| .image.moving { | .image.moving { | ||||||
| 	visibility: hidden; | 	visibility: hidden; | ||||||
|  | |||||||
| @ -334,12 +334,12 @@ module.MetaActions = { | |||||||
| 	// Register an action callback...
 | 	// Register an action callback...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	//	Register a post action callback
 | 	//	Register a post action callback
 | ||||||
| 	// 	.on('action', <function>)
 | 	// 	.on('action', [<tag>, ]<function>)
 | ||||||
| 	// 	.on('action.post', <function>)
 | 	// 	.on('action.post', [<tag>, ]<function>)
 | ||||||
| 	// 		-> <action-set>
 | 	// 		-> <action-set>
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// 	Register a pre action callback
 | 	// 	Register a pre action callback
 | ||||||
| 	// 	.on('action.pre', <function>)
 | 	// 	.on('action.pre', [<tag>, ]<function>)
 | ||||||
| 	// 		-> <action-set>
 | 	// 		-> <action-set>
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// Modes:
 | 	// Modes:
 | ||||||
| @ -350,8 +350,17 @@ module.MetaActions = { | |||||||
| 	// 	'post'		- the handler is fired after the action is finished.
 | 	// 	'post'		- the handler is fired after the action is finished.
 | ||||||
| 	// 					this is the default.
 | 	// 					this is the default.
 | ||||||
| 	//
 | 	//
 | ||||||
|  | 	// The optional tag marks the handler to enable group removal via 
 | ||||||
|  | 	// .off(..)
 | ||||||
|  | 	//
 | ||||||
| 	// NOTE: 'post' mode is the default.
 | 	// NOTE: 'post' mode is the default.
 | ||||||
| 	on: function(action, handler){ | 	//
 | ||||||
|  | 	// XXX add something like text tags to events (extra arg) to enable
 | ||||||
|  | 	// 		simple and fast handler removal...
 | ||||||
|  | 	on: function(action, b, c){ | ||||||
|  | 		var handler = typeof(c) == 'function' ? c : b | ||||||
|  | 		var tag = typeof(c) == 'function' ? b : c | ||||||
|  | 
 | ||||||
| 		// prepare the handler...
 | 		// prepare the handler...
 | ||||||
| 		var mode = action.split('.') | 		var mode = action.split('.') | ||||||
| 		action = mode[0] | 		action = mode[0] | ||||||
| @ -367,9 +376,12 @@ module.MetaActions = { | |||||||
| 
 | 
 | ||||||
| 		// mot pre mode...
 | 		// mot pre mode...
 | ||||||
| 		} else if(mode != 'pre') { | 		} else if(mode != 'pre') { | ||||||
|  | 			// XXX
 | ||||||
| 			throw 'Unknown action mode: '+action+'.'+mode | 			throw 'Unknown action mode: '+action+'.'+mode | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		handler.tag = tag | ||||||
|  | 
 | ||||||
| 		// register handlers locally only...
 | 		// register handlers locally only...
 | ||||||
| 		if(!this.hasOwnProperty('_action_handlers')){ | 		if(!this.hasOwnProperty('_action_handlers')){ | ||||||
| 			this._action_handlers = {} | 			this._action_handlers = {} | ||||||
| @ -387,22 +399,31 @@ module.MetaActions = { | |||||||
| 
 | 
 | ||||||
| 	// Remove an action callback...
 | 	// Remove an action callback...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	// XXX this will not work for explicit <action>.post...
 | 	// XXX needs more testing...
 | ||||||
| 	off: function(action, handler){ | 	off: function(action, handler){ | ||||||
| 		if(this.hasOwnProperty('_action_handlers')){ | 		if(this.hasOwnProperty('_action_handlers')){ | ||||||
|  | 			if(action == '*'){ | ||||||
|  | 				var actions = Object.keys(this._action_handlers) | ||||||
|  | 			} else { | ||||||
|  | 				var actions = [action] | ||||||
|  | 			} | ||||||
|  | 			var that = this | ||||||
|  | 			actions.forEach(function(action){ | ||||||
| 				var mode = action.split('.') | 				var mode = action.split('.') | ||||||
| 				action = mode[0] | 				action = mode[0] | ||||||
| 				mode = mode[1] | 				mode = mode[1] | ||||||
| 
 | 
 | ||||||
| 				// get the handlers...
 | 				// get the handlers...
 | ||||||
| 			var h = this._action_handlers[action] | 				var h = that._action_handlers[action] | ||||||
| 
 | 
 | ||||||
|  | 				// remove explicit handler...
 | ||||||
|  | 				if(typeof(handler) == 'function'){ | ||||||
| 					var i = -1 | 					var i = -1 | ||||||
| 					if(mode == null || mode == 'post'){ | 					if(mode == null || mode == 'post'){ | ||||||
| 						// XXX find via e.orig_handler == handler && e.mode == 'post'
 | 						// XXX find via e.orig_handler == handler && e.mode == 'post'
 | ||||||
| 						h.forEach(function(e, j){ | 						h.forEach(function(e, j){ | ||||||
| 							// NOTE: we will only get the first match...
 | 							// NOTE: we will only get the first match...
 | ||||||
| 					if(e.orig_handler == handler && i == -1){ | 							if(e.orig_handler === handler && i == -1){ | ||||||
| 								i = j | 								i = j | ||||||
| 							} | 							} | ||||||
| 						}) | 						}) | ||||||
| @ -415,6 +436,16 @@ module.MetaActions = { | |||||||
| 					if(i >= 0){ | 					if(i >= 0){ | ||||||
| 						h.splice(i, 1) | 						h.splice(i, 1) | ||||||
| 					} | 					} | ||||||
|  | 
 | ||||||
|  | 				// remove handlers by tag...
 | ||||||
|  | 				} else { | ||||||
|  | 					// filter out everything that mathches a tag in-place...
 | ||||||
|  | 					h.splice.apply(h,  | ||||||
|  | 							[0, h.length] | ||||||
|  | 								.concat(h.filter(function(e){  | ||||||
|  | 									return e.tag != handler }))) | ||||||
|  | 				} | ||||||
|  | 			}) | ||||||
| 		} | 		} | ||||||
| 		return this | 		return this | ||||||
| 	}, | 	}, | ||||||
|  | |||||||
| @ -278,6 +278,8 @@ module.RibbonsPrototype = { | |||||||
| 		return this | 		return this | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
|  | 	// XXX make this work for multiple targets...
 | ||||||
|  | 	// XXX avoid ardcoded delays...
 | ||||||
| 	makeShadow: function(target, animate){ | 	makeShadow: function(target, animate){ | ||||||
| 		var img = this.getImage(target) | 		var img = this.getImage(target) | ||||||
| 		var gid = this.getElemGID(img) | 		var gid = this.getElemGID(img) | ||||||
|  | |||||||
| @ -163,7 +163,7 @@ $(function(){ | |||||||
| 
 | 
 | ||||||
| 	window.a = testing.setupActions() | 	window.a = testing.setupActions() | ||||||
| 
 | 
 | ||||||
| 	viewer.setupAnimation(a) | 	viewer.Animation.setup(a) | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -549,9 +549,16 @@ actions.Actions(Client, { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| var setupAnimation = | /*********************************************************************/ | ||||||
| module.setupAnimation = | // XXX do a simple feature framework...
 | ||||||
| function setupAnimation(actions){ | // 		...need something like:
 | ||||||
|  | // 			Features(['feature_a', 'feature_b'], action).setup()
 | ||||||
|  | 
 | ||||||
|  | var Animation = | ||||||
|  | module.Animation = { | ||||||
|  | 	tag: 'animation_handler', | ||||||
|  | 
 | ||||||
|  | 	setup: function(actions){ | ||||||
| 		var animate = function(target){ | 		var animate = function(target){ | ||||||
| 				var s = this.ribbons.makeShadow(target, true) | 				var s = this.ribbons.makeShadow(target, true) | ||||||
| 				return function(){ s() } | 				return function(){ s() } | ||||||
| @ -560,14 +567,20 @@ function setupAnimation(actions){ | |||||||
| 				var s = this.ribbons.makeShadow(target) | 				var s = this.ribbons.makeShadow(target) | ||||||
| 				return function(){ s() } | 				return function(){ s() } | ||||||
| 			} | 			} | ||||||
|  | 		var tag = this.tag | ||||||
| 		return actions | 		return actions | ||||||
| 		.on('shiftImageUp.pre', animate) | 			.on('shiftImageUp.pre', tag, animate) | ||||||
| 		.on('shiftImageDown.pre', animate) | 			.on('shiftImageDown.pre', tag, animate) | ||||||
| 		.on('shiftImageLeft.pre', noanimate) | 			.on('shiftImageLeft.pre', tag, noanimate) | ||||||
| 		.on('shiftImageRight.pre', noanimate) | 			.on('shiftImageRight.pre', tag, noanimate) | ||||||
|  | 	}, | ||||||
|  | 	remove: function(actions){ | ||||||
|  | 		return actions.off('*', this.tag) | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| /********************************************************************** | /********************************************************************** | ||||||
| * vim:set ts=4 sw=4 :                                                */ | * vim:set ts=4 sw=4 :                                                */ | ||||||
| return module }) | return module }) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user