mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-11-04 05:10:07 +00:00 
			
		
		
		
	not actions .on(..) / .off(..) support multiple space-seporated events in a singe call (a-la jQuery .on(..) )...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									79a555aba6
								
							
						
					
					
						commit
						df43ed4ea3
					
				@ -359,43 +359,47 @@ module.MetaActions = {
 | 
				
			|||||||
	//
 | 
						//
 | 
				
			||||||
	// XXX add something like text tags to events (extra arg) to enable
 | 
						// XXX add something like text tags to events (extra arg) to enable
 | 
				
			||||||
	// 		simple and fast handler removal...
 | 
						// 		simple and fast handler removal...
 | 
				
			||||||
	on: function(action, b, c){
 | 
						on: function(actions, b, c){
 | 
				
			||||||
		var handler = typeof(c) == 'function' ? c : b
 | 
							var handler = typeof(c) == 'function' ? c : b
 | 
				
			||||||
		var tag = typeof(c) == 'function' ? b : c
 | 
							var tag = typeof(c) == 'function' ? b : c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// prepare the handler...
 | 
							var that = this
 | 
				
			||||||
		var mode = action.split('.')
 | 
							actions.split(' ').forEach(function(action){
 | 
				
			||||||
		action = mode[0]
 | 
								// prepare the handler...
 | 
				
			||||||
		mode = mode[1]
 | 
								var mode = action.split('.')
 | 
				
			||||||
 | 
								action = mode[0]
 | 
				
			||||||
 | 
								mode = mode[1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// a post handler (default)...
 | 
								// a post handler (default)...
 | 
				
			||||||
		if(mode == null || mode == 'post'){
 | 
								if(mode == null || mode == 'post'){
 | 
				
			||||||
			var old_handler = handler
 | 
									var old_handler = handler
 | 
				
			||||||
			handler = function(){ return old_handler }
 | 
									handler = function(){ return old_handler }
 | 
				
			||||||
			// NOTE: this is set so as to identify the handler for removal
 | 
									// NOTE: this is set so as to identify the handler for removal
 | 
				
			||||||
			// 		via. .off(..)
 | 
									// 		via. .off(..)
 | 
				
			||||||
			handler.orig_handler = old_handler
 | 
									handler.orig_handler = old_handler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// mot pre mode...
 | 
								// mot pre mode...
 | 
				
			||||||
		} else if(mode != 'pre') {
 | 
								} else if(mode != 'pre') {
 | 
				
			||||||
			// XXX
 | 
									// XXX
 | 
				
			||||||
			throw 'Unknown action mode: '+action+'.'+mode
 | 
									throw 'Unknown action mode: '+action+'.'+mode
 | 
				
			||||||
		}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		handler.tag = tag
 | 
								handler.tag = tag
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// register handlers locally only...
 | 
				
			||||||
 | 
								if(!that.hasOwnProperty('_action_handlers')){
 | 
				
			||||||
 | 
									that._action_handlers = {}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if(!(action in that._action_handlers)){
 | 
				
			||||||
 | 
									that._action_handlers[action] = []
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// register a handler only once...
 | 
				
			||||||
 | 
								if(that._action_handlers[action].indexOf(handler) < 0){
 | 
				
			||||||
 | 
									// NOTE: last registered is first...
 | 
				
			||||||
 | 
									that._action_handlers[action].splice(0, 0, handler)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// register handlers locally only...
 | 
					 | 
				
			||||||
		if(!this.hasOwnProperty('_action_handlers')){
 | 
					 | 
				
			||||||
			this._action_handlers = {}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if(!(action in this._action_handlers)){
 | 
					 | 
				
			||||||
			this._action_handlers[action] = []
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		// register a handler only once...
 | 
					 | 
				
			||||||
		if(this._action_handlers[action].indexOf(handler) < 0){
 | 
					 | 
				
			||||||
			// NOTE: last registered is first...
 | 
					 | 
				
			||||||
			this._action_handlers[action].splice(0, 0, handler)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return this
 | 
							return this
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -407,7 +411,7 @@ module.MetaActions = {
 | 
				
			|||||||
			if(action == '*'){
 | 
								if(action == '*'){
 | 
				
			||||||
				var actions = Object.keys(this._action_handlers)
 | 
									var actions = Object.keys(this._action_handlers)
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				var actions = [action]
 | 
									var actions = action.split(' ')
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			var that = this
 | 
								var that = this
 | 
				
			||||||
			actions.forEach(function(action){
 | 
								actions.forEach(function(action){
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user