mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 19:30:07 +00:00 
			
		
		
		
	made the previews load in a async maner, making the general response faster and less laggy when multiple ribbons get aligned...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									416dab37f0
								
							
						
					
					
						commit
						a719079472
					
				
							
								
								
									
										66
									
								
								ui/data.js
									
									
									
									
									
								
							
							
						
						
									
										66
									
								
								ui/data.js
									
									
									
									
									
								
							| @ -1097,13 +1097,32 @@ function convertDataGen1(data, cmp){ | |||||||
| * Loaders | * Loaders | ||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
|  | // helper...
 | ||||||
|  | function _loadImageURL(image, url){ | ||||||
|  | 	// pre-cache and load image...
 | ||||||
|  | 	// NOTE: this will make images load without a blackout...
 | ||||||
|  | 	var img = new Image() | ||||||
|  | 	img.onload = function(){ | ||||||
|  | 		image.css({ | ||||||
|  | 				'background-image': 'url("'+ url +'")', | ||||||
|  | 			}) | ||||||
|  | 	} | ||||||
|  | 	img.src = url | ||||||
|  | 	return img | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | var SYNC_IMG_LOADER = true | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| // Update an image element
 | // Update an image element
 | ||||||
| //
 | //
 | ||||||
| // NOTE: care must be taken to reset ALL attributes an image can have,
 | // NOTE: care must be taken to reset ALL attributes an image can have,
 | ||||||
| // 		a common bug if this is not done correctly, is that some settings
 | // 		a common bug if this is not done correctly, is that some settings
 | ||||||
| // 		may leak to newly loaded images...
 | // 		may leak to newly loaded images...
 | ||||||
| // XXX do a pre-caching framework...
 | // XXX do a pre-caching framework...
 | ||||||
| function updateImage(image, gid, size){ | function updateImage(image, gid, size, sync){ | ||||||
|  | 	sync = sync == null ? SYNC_IMG_LOADER : sync | ||||||
| 	image = $(image) | 	image = $(image) | ||||||
| 	var oldgid = getImageGID(image) | 	var oldgid = getImageGID(image) | ||||||
| 
 | 
 | ||||||
| @ -1137,33 +1156,25 @@ function updateImage(image, gid, size){ | |||||||
| 
 | 
 | ||||||
| 	// preview...
 | 	// preview...
 | ||||||
| 	var p_url = getBestPreview(gid, size).url | 	var p_url = getBestPreview(gid, size).url | ||||||
| 	// NOTE: due to the fact that loading/caching the image might be at 
 | 	// sync load...
 | ||||||
| 	// 		a different pace than calling updateImage(...) and .onload
 | 	if(sync){ | ||||||
| 	// 		events may trigger in any sequence, we need to update the
 | 		_loadImageURL(image, p_url) | ||||||
| 	// 		url in a persistent way so as to load the last call's image
 |  | ||||||
| 	// 		regardless of actual handler call sequence...
 |  | ||||||
| 	image.data().loading = p_url |  | ||||||
| 
 | 
 | ||||||
| 	// pre-cache and load image...
 | 	// async load...
 | ||||||
| 	// NOTE: this will make images load without a blackout...
 | 	} else { | ||||||
| 	// XXX add a cache of the form:
 | 		// NOTE: storing the url in .data() makes the image load the 
 | ||||||
| 	// 			{
 | 		// 		last preview and last preview only in the case that we
 | ||||||
| 	// 				[<gid>, <size>]: Image,
 | 		// 		manage to call updateImage(...) on the same element 
 | ||||||
| 	// 				...
 | 		// 		multiple times before the previews get loaded...
 | ||||||
| 	// 			}
 | 		// 		...setting the data().loading is sync while loading an 
 | ||||||
| 	// 		- sort by use...
 | 		// 		image is not and if several loads are done in sequence
 | ||||||
| 	// 		- limit length...
 | 		// 		there is no guarantee that they will happen in the same
 | ||||||
| 	//
 | 		// 		order as requested...
 | ||||||
| 	// 		...might also be a good idea to split cache to sizes and have
 | 		image.data().loading = p_url | ||||||
| 	// 		different  but as limits for different sizes, but as sizes 
 | 		setTimeout(function(){  | ||||||
| 	// 		can differ between images this is not trivial...
 | 			_loadImageURL(image, image.data().loading) | ||||||
| 	var img = new Image() | 		}, 0) | ||||||
| 	img.onload = function(){ |  | ||||||
| 		image.css({ |  | ||||||
| 				'background-image': 'url("'+ image.data().loading +'")', |  | ||||||
| 			}) |  | ||||||
| 	} | 	} | ||||||
| 	img.src = p_url |  | ||||||
| 
 | 
 | ||||||
| 	// main attrs...
 | 	// main attrs...
 | ||||||
| 	image | 	image | ||||||
| @ -1185,6 +1196,9 @@ function updateImage(image, gid, size){ | |||||||
| 		image.removeClass('marked') | 		image.removeClass('marked') | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	// XXX load filter settings...
 | ||||||
|  | 	// XXX
 | ||||||
|  | 
 | ||||||
| 	return image | 	return image | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -20,12 +20,15 @@ var toggleEditor = createCSSClassToggler( | |||||||
| 				if(ed.length == 0){ | 				if(ed.length == 0){ | ||||||
| 					$('.viewer') | 					$('.viewer') | ||||||
| 						.append(makeEditorControls('.current.image') | 						.append(makeEditorControls('.current.image') | ||||||
|  | 							//.draggable('option', 'snap', '.viewer')
 | ||||||
| 							.addClass('noScroll') | 							.addClass('noScroll') | ||||||
| 							.css({ | 							.css({ | ||||||
| 								// prevent the editor from moving under 
 | 								// prevent the editor from moving under 
 | ||||||
| 								// the title bar, that will prevent us from
 | 								// the title bar, that will prevent us from
 | ||||||
| 								// ever moving it away or closing it...
 | 								// ever moving it away or closing it...
 | ||||||
| 								'margin-top': '20px', | 								'margin-top': '20px', | ||||||
|  | 								top: '50px', | ||||||
|  | 								left: '5px', | ||||||
| 							}) | 							}) | ||||||
| 							// make clicks on unfocusable elements remove focus...
 | 							// make clicks on unfocusable elements remove focus...
 | ||||||
| 							.click(function(){ | 							.click(function(){ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user