mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-11-04 05:10:07 +00:00 
			
		
		
		
	adde .one(..) to actions + minor tweaks and changes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									49cc0c723d
								
							
						
					
					
						commit
						26c9b8db2f
					
				@ -357,7 +357,7 @@ module.MetaActions = {
 | 
				
			|||||||
	//
 | 
						//
 | 
				
			||||||
	// NOTE: 'post' mode is the default.
 | 
						// NOTE: 'post' mode is the default.
 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
	// XXX document tags...
 | 
						// XXX should we have multiple tags per handler???
 | 
				
			||||||
	on: function(actions, 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
 | 
				
			||||||
@ -377,7 +377,7 @@ module.MetaActions = {
 | 
				
			|||||||
				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.orig_handler || old_handler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// mot pre mode...
 | 
								// mot pre mode...
 | 
				
			||||||
			} else if(mode != 'pre') {
 | 
								} else if(mode != 'pre') {
 | 
				
			||||||
@ -406,12 +406,27 @@ module.MetaActions = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Remove an action callback...
 | 
						// Remove an action callback...
 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
	// XXX document tags...
 | 
						//	Remove all handlers from action:
 | 
				
			||||||
 | 
						//	.off('action')
 | 
				
			||||||
 | 
						//	.off('action', '*')
 | 
				
			||||||
 | 
						//	.off('action', 'all')
 | 
				
			||||||
 | 
						// 		-> <action-set>
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						//	Remove specific handler from action:
 | 
				
			||||||
 | 
						//	.off('action', <handler>)
 | 
				
			||||||
 | 
						// 		-> <action-set>
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						//	Remove handlers from action by tag:
 | 
				
			||||||
 | 
						//	.off('action', <tag>)
 | 
				
			||||||
 | 
						// 		-> <action-set>
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						// NOTE: the handler passed to .off(..) for removal must be the same
 | 
				
			||||||
 | 
						// 		as the handler passed to .on(..) / .one(..)
 | 
				
			||||||
	off: function(actions, handler){
 | 
						off: function(actions, handler){
 | 
				
			||||||
		if(this.hasOwnProperty('_action_handlers')){
 | 
							if(this.hasOwnProperty('_action_handlers')){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			actions = actions == '*' ? Object.keys(this._action_handlers)
 | 
								actions = actions == '*' ? Object.keys(this._action_handlers)
 | 
				
			||||||
				: typeof(actions) == 'string' ?  action.split(' ')
 | 
									: typeof(actions) == 'string' ?  actions.split(' ')
 | 
				
			||||||
				: actions
 | 
									: actions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			var that = this
 | 
								var that = this
 | 
				
			||||||
@ -444,6 +459,10 @@ module.MetaActions = {
 | 
				
			|||||||
						h.splice(i, 1)
 | 
											h.splice(i, 1)
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// remove all handlers...
 | 
				
			||||||
 | 
									} else if(handler == null || handler == 'all' || handler == '*'){
 | 
				
			||||||
 | 
										h.splice(0, h.length)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// remove handlers by tag...
 | 
									// remove handlers by tag...
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					// filter out everything that mathches a tag in-place...
 | 
										// filter out everything that mathches a tag in-place...
 | 
				
			||||||
@ -454,6 +473,30 @@ module.MetaActions = {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
			})
 | 
								})
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return this
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Register an action callback that will only fire once per event...
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						// This is signature compatible with .on(..)
 | 
				
			||||||
 | 
						one: function(actions, b, c){
 | 
				
			||||||
 | 
							var handler = typeof(c) == 'function' ? c : b
 | 
				
			||||||
 | 
							var tag = typeof(c) == 'function' ? b : c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							actions = typeof(actions) == 'string' ? actions.split(' ') : actions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var that = this
 | 
				
			||||||
 | 
							actions.forEach(function(action){
 | 
				
			||||||
 | 
								var _handler = function(){
 | 
				
			||||||
 | 
									// remove handler... 
 | 
				
			||||||
 | 
									that.off(action, handler)
 | 
				
			||||||
 | 
									return handler.apply(this, arguments)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								_handler.orig_handler = handler
 | 
				
			||||||
 | 
								that.on(action, tag, _handler)
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return this
 | 
							return this
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -487,6 +530,7 @@ module.MetaActions = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Mixin a set of local actions into an object...
 | 
						// Mixin a set of local actions into an object...
 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
 | 
						// XXX test
 | 
				
			||||||
	mixinTo: function(to, all, all_attr_types){
 | 
						mixinTo: function(to, all, all_attr_types){
 | 
				
			||||||
		return this.mixin.call(to, this, all, all_attr_types)
 | 
							return this.mixin.call(to, this, all, all_attr_types)
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
@ -527,6 +571,7 @@ module.MetaActions = {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Remove a set of local mixed in actions from object...
 | 
						// Remove a set of local mixed in actions from object...
 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
 | 
						// XXX test
 | 
				
			||||||
	mixoutFrom: function(to, all, all_attr_types){
 | 
						mixoutFrom: function(to, all, all_attr_types){
 | 
				
			||||||
		return this.mixout.call(to, this, all, all_attr_types)
 | 
							return this.mixout.call(to, this, all, all_attr_types)
 | 
				
			||||||
	},
 | 
						},
 | 
				
			||||||
@ -569,6 +614,8 @@ module.MetaActions = {
 | 
				
			|||||||
// NOTE: if <prototype> is not given, MetaActions will be used as default.
 | 
					// NOTE: if <prototype> is not given, MetaActions will be used as default.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// For more documentation see: Action(..).
 | 
					// For more documentation see: Action(..).
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// XXX add doc, ldoc, tags and save them to each action...
 | 
				
			||||||
var Actions =
 | 
					var Actions =
 | 
				
			||||||
module.Actions =
 | 
					module.Actions =
 | 
				
			||||||
function Actions(a, b){
 | 
					function Actions(a, b){
 | 
				
			||||||
 | 
				
			|||||||
@ -450,6 +450,14 @@ var Viewer =
 | 
				
			|||||||
module.Viewer = 
 | 
					module.Viewer = 
 | 
				
			||||||
actions.Actions(Client, {
 | 
					actions.Actions(Client, {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						get screenwidth(){
 | 
				
			||||||
 | 
							return this.ribbons != null ? this.ribbons.getScreenWidthImages() : null
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
						set screenwidth(n){
 | 
				
			||||||
 | 
							this.fitImage(n)
 | 
				
			||||||
 | 
						},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ready: [
 | 
						ready: [
 | 
				
			||||||
		function(){
 | 
							function(){
 | 
				
			||||||
			// XXX setup empty state...
 | 
								// XXX setup empty state...
 | 
				
			||||||
@ -479,10 +487,12 @@ actions.Actions(Client, {
 | 
				
			|||||||
		function(){
 | 
							function(){
 | 
				
			||||||
			this.ribbons.preventTransitions()
 | 
								this.ribbons.preventTransitions()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			this.ribbons.updateData(this.data)
 | 
								return function(){
 | 
				
			||||||
			this.focusImage()
 | 
									this.ribbons.updateData(this.data)
 | 
				
			||||||
 | 
									this.focusImage()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			this.ribbons.restoreTransitions()
 | 
									this.ribbons.restoreTransitions()
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}],
 | 
							}],
 | 
				
			||||||
	clear: [
 | 
						clear: [
 | 
				
			||||||
		// XXX do we need to delete the ribbons???
 | 
							// XXX do we need to delete the ribbons???
 | 
				
			||||||
@ -642,6 +652,10 @@ actions.Actions(Client, {
 | 
				
			|||||||
		}],
 | 
							}],
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	// XXX an ideologically different version of .focusImage(..)
 | 
						// XXX an ideologically different version of .focusImage(..)
 | 
				
			||||||
 | 
						// 		This version aligns the ribbons internally while the above
 | 
				
			||||||
 | 
						// 		version does not align at all, and all alignment is handled
 | 
				
			||||||
 | 
						// 		by a feature.
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
	//		The main question here is: 
 | 
						//		The main question here is: 
 | 
				
			||||||
	//			should we split out aligning to a feature?
 | 
						//			should we split out aligning to a feature?
 | 
				
			||||||
	//		The differences/trade-off's in this version:
 | 
						//		The differences/trade-off's in this version:
 | 
				
			||||||
@ -824,6 +838,29 @@ actions.Actions(Client, {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	crop: [ reloadAfter() ],
 | 
						crop: [ reloadAfter() ],
 | 
				
			||||||
	uncrop: [ reloadAfter() ],
 | 
						uncrop: [ reloadAfter() ],
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// XXX experimental: not sure if this is the right way to go...
 | 
				
			||||||
 | 
						// XXX make this play nice with crops...
 | 
				
			||||||
 | 
						toggleRibbonList: ['Toggle ribbons as images view',
 | 
				
			||||||
 | 
							function(){
 | 
				
			||||||
 | 
								if(this._full_data == null){
 | 
				
			||||||
 | 
									// XXX do a better name here...
 | 
				
			||||||
 | 
									this._full_data = this.data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// generate the view...
 | 
				
			||||||
 | 
									this.data = this.data.cropRibbons()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									this.reload()
 | 
				
			||||||
 | 
								} else {
 | 
				
			||||||
 | 
									var data = this._full_data
 | 
				
			||||||
 | 
									delete this._full_data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									// restore...
 | 
				
			||||||
 | 
									this.data = data.mergeRibbonCrop(this.data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									this.reload()
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}],
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user