mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	more code rearangement...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									bb636f9c91
								
							
						
					
					
						commit
						e2192aef84
					
				
							
								
								
									
										112
									
								
								ui/ImageGrid.js
									
									
									
									
									
								
							
							
						
						
									
										112
									
								
								ui/ImageGrid.js
									
									
									
									
									
								
							| @ -18,62 +18,6 @@ | ||||
| **********************************************************************/ | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * Constructors | ||||
| */ | ||||
| 
 | ||||
| // NOTE: to avoid state sync problems this should clone an image if 
 | ||||
| //		one is available...
 | ||||
| function createImage(n){ | ||||
| 	if(n == null){ | ||||
| 		if(window._n == null){ | ||||
| 			window._n = 0 | ||||
| 		} | ||||
| 		n = _n | ||||
| 		_n += 1 | ||||
| 	} | ||||
| 	var img = $('.image') | ||||
| 	if(img.length > 0){ | ||||
| 		return img.first().clone() | ||||
| 					.attr({ | ||||
| 						'order': n, | ||||
| 						// need to strip extra classes...
 | ||||
| 						'class': 'image' | ||||
| 					}) | ||||
| 	} else { | ||||
| 		return $('<div order="'+n+'" class="image"/>') | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // This will create a set of new images, reusing a list of existing 
 | ||||
| // elements if given.
 | ||||
| // XXX do we need this???
 | ||||
| function createImages(need, have){ | ||||
| 	have = have == null ? [] : have | ||||
| 
 | ||||
| 	// we have enough elements in the cache...
 | ||||
| 	if(have.length >= need){ | ||||
| 		return $(have.splice(0, need)) | ||||
| 
 | ||||
| 	// need to create additional elements...
 | ||||
| 	} else { | ||||
| 		return $(have.toArray().concat(new Array(need - have.length))) | ||||
| 			.map(function(i, elem){ | ||||
| 				if(elem != null){ | ||||
| 					return elem | ||||
| 				} | ||||
| 				return createImage()[0] | ||||
| 			}) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| function createRibbon(){ | ||||
| 	return $('<div class="ribbon"/>') | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * Helpers | ||||
| */ | ||||
| @ -163,6 +107,62 @@ function shiftImage(direction, image, force_create_ribbon){ | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * Constructors | ||||
| */ | ||||
| 
 | ||||
| // NOTE: to avoid state sync problems this should clone an image if 
 | ||||
| //		one is available...
 | ||||
| function createImage(n){ | ||||
| 	if(n == null){ | ||||
| 		if(window._n == null){ | ||||
| 			window._n = 0 | ||||
| 		} | ||||
| 		n = _n | ||||
| 		_n += 1 | ||||
| 	} | ||||
| 	var img = $('.image') | ||||
| 	if(img.length > 0){ | ||||
| 		return img.first().clone() | ||||
| 					.attr({ | ||||
| 						'order': n, | ||||
| 						// need to strip extra classes...
 | ||||
| 						'class': 'image' | ||||
| 					}) | ||||
| 	} else { | ||||
| 		return $('<div order="'+n+'" class="image"/>') | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // This will create a set of new images, reusing a list of existing 
 | ||||
| // elements if given.
 | ||||
| // XXX do we need this???
 | ||||
| function createImages(need, have){ | ||||
| 	have = have == null ? [] : have | ||||
| 
 | ||||
| 	// we have enough elements in the cache...
 | ||||
| 	if(have.length >= need){ | ||||
| 		return $(have.splice(0, need)) | ||||
| 
 | ||||
| 	// need to create additional elements...
 | ||||
| 	} else { | ||||
| 		return $(have.toArray().concat(new Array(need - have.length))) | ||||
| 			.map(function(i, elem){ | ||||
| 				if(elem != null){ | ||||
| 					return elem | ||||
| 				} | ||||
| 				return createImage()[0] | ||||
| 			}) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| function createRibbon(){ | ||||
| 	return $('<div class="ribbon"/>') | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * Modes | ||||
| */ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user