mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	some cleanup + added .sortViaOrder(..)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									b6e12a804e
								
							
						
					
					
						commit
						88f1d0bc0e
					
				| @ -231,7 +231,7 @@ var ImageMarkActions = actions.Actions({ | |||||||
| 	get marked(){ | 	get marked(){ | ||||||
| 		return this.data == null ? | 		return this.data == null ? | ||||||
| 			[] | 			[] | ||||||
| 			: this.data.tagQuery('marked') }, | 			: this.data.sortViaOrder(this.data.tagQuery('marked')) }, | ||||||
| 
 | 
 | ||||||
| 	markedInRibbon: ['- Mark|Ribbon/', | 	markedInRibbon: ['- Mark|Ribbon/', | ||||||
| 		function(ribbon){ | 		function(ribbon){ | ||||||
| @ -503,7 +503,7 @@ var ImageBookmarkActions = actions.Actions({ | |||||||
| 	get bookmarked(){ | 	get bookmarked(){ | ||||||
| 		return this.data == null ? | 		return this.data == null ? | ||||||
| 			[] | 			[] | ||||||
| 			: this.data.tagQuery('bookmark') }, | 			: this.data.sortViaOrder(this.data.tagQuery('bookmark')) }, | ||||||
| 
 | 
 | ||||||
| 	prevBookmarked: ['Bookmark|Navigate/Previous bookmarked image', | 	prevBookmarked: ['Bookmark|Navigate/Previous bookmarked image', | ||||||
| 		{browseMode: function(target){  | 		{browseMode: function(target){  | ||||||
|  | |||||||
| @ -248,32 +248,12 @@ var DataPrototype = { | |||||||
| 			this.getRibbon(value) | 			this.getRibbon(value) | ||||||
| 			: value }, | 			: value }, | ||||||
| 
 | 
 | ||||||
| 	// XXX need to figure out how to both reset the .order_index in a safe
 |  | ||||||
| 	// 		way and keep it to speed things up in consecutive calls that 
 |  | ||||||
| 	// 		do not touch the order...
 |  | ||||||
| 	get order(){ | 	get order(){ | ||||||
| 		return this.__order }, | 		return this.__order }, | ||||||
| 	set order(value){ | 	set order(value){ | ||||||
| 		var that = this | 		var that = this | ||||||
| 		delete this.__order_index | 		delete this.__order_index | ||||||
| 
 |  | ||||||
| 		//*
 |  | ||||||
| 		this.__order = value | 		this.__order = value | ||||||
| 		/*/  |  | ||||||
| 		// XXX this makes things substantially slower...
 |  | ||||||
| 		this.__order = value.isOrderProxy ? |  | ||||||
| 			value |  | ||||||
| 			: new Proxy(value, { |  | ||||||
| 				get: function(target, name){ |  | ||||||
| 					return name == 'isOrderProxy'  |  | ||||||
| 						|| target[name] }, |  | ||||||
| 				set: function(target, name, value){ |  | ||||||
| 					that.order_index[value] = name |  | ||||||
| 					target[name] = value |  | ||||||
| 					return true |  | ||||||
| 				},  |  | ||||||
| 			}) |  | ||||||
| 		//*/
 |  | ||||||
| 	}, | 	}, | ||||||
| 	get order_index(){ | 	get order_index(){ | ||||||
| 		return this.__order_index = this.__order_index || this.order.toKeys() }, | 		return this.__order_index = this.__order_index || this.order.toKeys() }, | ||||||
| @ -317,6 +297,22 @@ var DataPrototype = { | |||||||
| 			.map(function(gid){ return that.getImage(gid) }) | 			.map(function(gid){ return that.getImage(gid) }) | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
|  | 	// Sort images via .order...
 | ||||||
|  | 	//
 | ||||||
|  | 	// NOTE: this will place non-gids at the end of the list...
 | ||||||
|  | 	//
 | ||||||
|  | 	// XXX is this faster than .makeSparseImages(gids).compact() ???
 | ||||||
|  | 	// 		...though this will not remove non-gids... 
 | ||||||
|  | 	sortViaOrder: function(gids){ | ||||||
|  | 		var idx = this.order_index | ||||||
|  | 		return gids.sort(function(a, b){  | ||||||
|  | 			return a in idx && b in idx ? | ||||||
|  | 					idx[a] - idx[b] | ||||||
|  | 				: a in idx ? | ||||||
|  | 					-1 | ||||||
|  | 				: b in idx ? | ||||||
|  | 					1 | ||||||
|  | 				: gids.indexOf(a) - gids.indexOf(b) }) }, | ||||||
| 
 | 
 | ||||||
| 	// Make a sparse list of image gids...
 | 	// Make a sparse list of image gids...
 | ||||||
| 	//
 | 	//
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user