mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-11-04 05:10:07 +00:00 
			
		
		
		
	still working to simplify the action architecture...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									9ed14ba3b8
								
							
						
					
					
						commit
						b9e25f0c03
					
				@ -17,20 +17,36 @@ data = require('data')
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/*********************************************************************/
 | 
					/*********************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// attr can be:
 | 
				
			||||||
 | 
					// 	"name"		- attribute name
 | 
				
			||||||
 | 
					// 	"name, name, ..."
 | 
				
			||||||
 | 
					// 				- string containign coma separated attribute names
 | 
				
			||||||
 | 
					// 	list 		- list of attribute names
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
// XXX add a callback here...
 | 
					// XXX add a callback here...
 | 
				
			||||||
function proxy(attr, name){
 | 
					function proxy(attr, name){
 | 
				
			||||||
 | 
						// we can proxy multiple attrs...
 | 
				
			||||||
 | 
						attr = typeof(attr) == typeof('str') 
 | 
				
			||||||
 | 
							? attr.split(',').map(function(e){ return e.trim() })
 | 
				
			||||||
 | 
							: attr
 | 
				
			||||||
	return function(){
 | 
						return function(){
 | 
				
			||||||
		attr = this[attr]
 | 
							var that = this
 | 
				
			||||||
		attr[name].apply(attr, arguments)
 | 
							var args = arguments
 | 
				
			||||||
 | 
							attr.forEach(function(a){
 | 
				
			||||||
 | 
								a = that[a]
 | 
				
			||||||
 | 
								a[name].apply(a, args)
 | 
				
			||||||
 | 
							})
 | 
				
			||||||
		return this
 | 
							return this
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function proxyMethods(obj, map){
 | 
					function proxyMethods(obj, map){
 | 
				
			||||||
	var txt = ''
 | 
						var txt = ''
 | 
				
			||||||
 | 
						map = map == null ? obj : map
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for(var attr in map){
 | 
						for(var attr in map){
 | 
				
			||||||
		var methods = map[attr]
 | 
							var methods = map[attr]
 | 
				
			||||||
 | 
							methods = typeof(methods) == typeof('str') ? {attr: methods} : methods
 | 
				
			||||||
		for(var name in methods){
 | 
							for(var name in methods){
 | 
				
			||||||
			var txt = methods[name]
 | 
								var txt = methods[name]
 | 
				
			||||||
			if(txt == null){
 | 
								if(txt == null){
 | 
				
			||||||
@ -45,6 +61,7 @@ function proxyMethods(obj, map){
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*********************************************************************/
 | 
					/*********************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This will:
 | 
					// This will:
 | 
				
			||||||
@ -63,44 +80,58 @@ var ClientPrototype = {
 | 
				
			|||||||
	// 	.data
 | 
						// 	.data
 | 
				
			||||||
	//
 | 
						//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// XXX client-specific API...
 | 
						// direct proxy methods...
 | 
				
			||||||
	// XXX
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// setup the proxy methods...
 | 
					 | 
				
			||||||
var ClientPrototype = proxyMethods(
 | 
					 | 
				
			||||||
	ClientPrototype,
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		data: {
 | 
					 | 
				
			||||||
	focusImage: 'Focus image',
 | 
						focusImage: 'Focus image',
 | 
				
			||||||
	focusRibbon: 'Focus ribbon',
 | 
						focusRibbon: 'Focus ribbon',
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	firstImage: 'Focus first image in current ribbon',
 | 
						firstImage: 'Focus first image in current ribbon',
 | 
				
			||||||
	lastImage: 'Focus last image in current ribbon',
 | 
						lastImage: 'Focus last image in current ribbon',
 | 
				
			||||||
		},
 | 
					
 | 
				
			||||||
	})
 | 
						// XXX client-specific API...
 | 
				
			||||||
 | 
						// XXX
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					// XXX this is temporary...
 | 
				
			||||||
 | 
					// 		...this will messup actual methods...
 | 
				
			||||||
 | 
					proxyMethods(ClientPrototype)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*********************************************************************/
 | 
					// XXX auto apply this...
 | 
				
			||||||
 | 
					function chainSelfAttrMethods(cls, attr, meth){
 | 
				
			||||||
 | 
							return function(){
 | 
				
			||||||
 | 
								// NOTE: this is super, python-style but without multiple 
 | 
				
			||||||
 | 
								// 		inheritance...
 | 
				
			||||||
 | 
								// 		...that last part makes this more of a code reuse 
 | 
				
			||||||
 | 
								// 		than a programming tool...
 | 
				
			||||||
 | 
								cls.__proto__[meth].apply(this, arguments)
 | 
				
			||||||
 | 
								// call the encapsulated method...
 | 
				
			||||||
 | 
								this[attr][meth].apply(this[attr], arguments)
 | 
				
			||||||
 | 
								return this
 | 
				
			||||||
 | 
							}),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var ViewerPrototype = {
 | 
				
			||||||
 | 
						// this expects the folowing attrs:
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
						// 	.ribbons
 | 
				
			||||||
 | 
						//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						focusImage: doc('Focus image', 
 | 
				
			||||||
 | 
							chainSelfAttrMethods(ViewerPrototype, 'ribbons', 'focusImage')),
 | 
				
			||||||
 | 
						focusRibbon: doc('Focus ribbon',
 | 
				
			||||||
 | 
							chainSelfAttrMethods(ViewerPrototype, 'ribbons', 'focusRibbon')),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					ViewerPrototype.__proto__ = ClientPrototype
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var Client =
 | 
					var Client =
 | 
				
			||||||
module.Client =
 | 
					module.Client = Object.create(ClientPrototype)
 | 
				
			||||||
function Client(){
 | 
					 | 
				
			||||||
	// in case this is called as a function (without new)...
 | 
					 | 
				
			||||||
	if(this.constructor.name != 'Client'){
 | 
					 | 
				
			||||||
		return new Client()
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// XXX setup initial state...
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return this
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
Client.__proto__ = ClientClassPrototype
 | 
					 | 
				
			||||||
Client.prototype = ClientPrototype
 | 
					 | 
				
			||||||
Client.prototype.constructor = Client
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var Viewer =
 | 
				
			||||||
 | 
					module.Viewer = Object.create(ViewerPrototype)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user