mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-30 19:00:09 +00:00 
			
		
		
		
	some cleanup, bugfixes and minor refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									8d446609fd
								
							
						
					
					
						commit
						6bd356755e
					
				
							
								
								
									
										89
									
								
								ui/data.js
									
									
									
									
									
								
							
							
						
						
									
										89
									
								
								ui/data.js
									
									
									
									
									
								
							| @ -716,9 +716,11 @@ function loadLocalStorageData(attr){ | ||||
| 	if(data == null){ | ||||
| 		data = '{}' | ||||
| 	} | ||||
| 	var base = localStorage[attr + '_BASE_URL'] | ||||
| 	base = base == null ? '.' : base | ||||
| 	return { | ||||
| 		data: JSON.parse(data), | ||||
| 		base_url: localStorage[attr + '_BASE_URL'], | ||||
| 		base_url: base, | ||||
| 	} | ||||
| } | ||||
| function saveLocalStorageData(attr){ | ||||
| @ -815,12 +817,16 @@ if(window.CEF_dumpJSON != null){ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Load images from file
 | ||||
| //
 | ||||
| // This will also merge all diff files.
 | ||||
| function loadFileImages(path, no_load_diffs, callback){ | ||||
| 
 | ||||
| 	if(window.listDir == null){ | ||||
| 		no_load_diffs = true | ||||
| 	} | ||||
| 
 | ||||
| 	// find the latest images file...
 | ||||
| 	if(path == null){ | ||||
| 		var base = normalizePath(CACHE_DIR) | ||||
| 		var path = $.map(listDir(base), function(e){  | ||||
| @ -836,30 +842,33 @@ function loadFileImages(path, no_load_diffs, callback){ | ||||
| 		path = normalizePath(path) | ||||
| 		// XXX need to account for paths without a CACHE_DIR
 | ||||
| 		var base = path.split(CACHE_DIR)[0] | ||||
| 		// XXX what are we going to do if base == path, i.e. no cache dir???
 | ||||
| 		base += '/'+ CACHE_DIR | ||||
| 	} | ||||
| 
 | ||||
| 	var diff_data = {} | ||||
| 	var diff = true | ||||
| 
 | ||||
| 	// XXX what are we going to do if base == path, i.e. no cache dir???
 | ||||
| 
 | ||||
| 
 | ||||
| 	// collect and merge image diffs...
 | ||||
| 	// XXX no error handling if one of the diff loads fail...
 | ||||
| 	if(!no_load_diffs){ | ||||
| 		var diffs = [diff_data] | ||||
| 		var diff_data = [diff_data] | ||||
| 		var diffs_names = $.map(listDir(base), function(e){  | ||||
| 			return /.*-images-diff.json$/.test(e) ? e : null | ||||
| 		}).sort() | ||||
| 		diff = $.when.apply(null, $.map(diffs_names, function(e, i){ | ||||
| 					return $.getJSON(normalizePath(base +'/'+ e)) | ||||
| 						// XXX this is ugly, had to do it this way as .then(...)
 | ||||
| 						// 		handlers get different argument sets depending on 
 | ||||
| 						// 		whether we have one or more deffereds here...
 | ||||
| 						.done(function(data){ | ||||
| 							diffs[i+1] = data | ||||
| 							diff_data[i+1] = data | ||||
| 							console.log('Loaded:', e) | ||||
| 						}) | ||||
| 				})) | ||||
| 			.then(function(){ | ||||
| 				$.extend.apply(null, diffs) | ||||
| 				$.extend.apply(null, diff_data) | ||||
| 				diff_data = diff_data[0] | ||||
| 			}) | ||||
| 	}  | ||||
| 
 | ||||
| @ -869,8 +878,6 @@ function loadFileImages(path, no_load_diffs, callback){ | ||||
| 			$.extend(json, diff_data) | ||||
| 			IMAGES = json | ||||
| 
 | ||||
| 			//localStorage[DATA_ATTR + '_IMAGES_FILE'] = path
 | ||||
| 
 | ||||
| 			console.log('Loaded IMAGES...') | ||||
| 
 | ||||
| 			callback != null && callback() | ||||
| @ -883,13 +890,16 @@ function loadFileImages(path, no_load_diffs, callback){ | ||||
| 
 | ||||
| // XXX make this load a default data filename...
 | ||||
| // XXX look into the CACHE_DIR if not explicitly given...
 | ||||
| function loadFileState(data_path, image_path, callback){ | ||||
| function loadFileState(data_path, callback){ | ||||
| 	var base = data_path.split(CACHE_DIR)[0] | ||||
| 	base = base == data_path ? '.' : base | ||||
| 
 | ||||
| 	return $.getJSON(data_path) | ||||
| 	var res = $.Deferred() | ||||
| 
 | ||||
| 	$.getJSON(data_path) | ||||
| 		.done(function(json){ | ||||
| 			BASE_URL = base | ||||
| 
 | ||||
| 			// legacy format...
 | ||||
| 			if(json.version == null){ | ||||
| 				json = convertDataGen1(json) | ||||
| @ -900,22 +910,15 @@ function loadFileState(data_path, image_path, callback){ | ||||
| 				loadData() | ||||
| 
 | ||||
| 			// version 2.0
 | ||||
| 			// XXX needs a more flexible protocol...
 | ||||
| 			} else if(json.version == '2.0') { | ||||
| 				DATA = json | ||||
| 				if(image_path != null){ | ||||
| 					loadFileImages(normalizePath(image_path, base)) | ||||
| 						.done(function(){ | ||||
| 							loadData() | ||||
| 
 | ||||
| 							callback != null && callback() | ||||
| 						}) | ||||
| 				} else if(DATA.image_file != null) { | ||||
| 				if(DATA.image_file != null) { | ||||
| 					loadFileImages(normalizePath(DATA.image_file, base)) | ||||
| 						.done(function(){ | ||||
| 							loadData() | ||||
| 
 | ||||
| 							callback != null && callback() | ||||
| 							res.resolve() | ||||
| 						}) | ||||
| 				} else { | ||||
| 					loadFileImages(null) | ||||
| @ -923,6 +926,7 @@ function loadFileState(data_path, image_path, callback){ | ||||
| 							loadData() | ||||
| 
 | ||||
| 							callback != null && callback() | ||||
| 							res.resolve() | ||||
| 						}) | ||||
| 				} | ||||
| 
 | ||||
| @ -935,6 +939,8 @@ function loadFileState(data_path, image_path, callback){ | ||||
| 		.fail(function(){ | ||||
| 			console.error('ERROR LOADING:', data_path) | ||||
| 		}) | ||||
| 
 | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| @ -999,35 +1005,7 @@ function saveFileState(name, no_normalize_path){ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Open image in an external editor/viewer
 | ||||
| //
 | ||||
| // NOTE: this will open the default editor/viewer.
 | ||||
| function openImage(){ | ||||
| 	// CEF
 | ||||
| 	if(window.runSystem == null){ | ||||
| 		console.error('Can\'t run external programs.') | ||||
| 		return  | ||||
| 	} | ||||
| 
 | ||||
| 	// XXX if path is not present try and open the biggest preview...
 | ||||
| 	return runSystem(normalizePath(IMAGES[getImageGID()].path, BASE_URL)) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // XXX need revision...
 | ||||
| function loadDir(path){ | ||||
| 
 | ||||
| 	if(window.CEF_listDir != null){ | ||||
| 		var listDir = CEF_listDir | ||||
| 
 | ||||
| 	// PhoneGap
 | ||||
| 	} else if(false) { | ||||
| 		// XXX
 | ||||
| 		 | ||||
| 	} else { | ||||
| 		no_load_diffs = true | ||||
| 	} | ||||
| 
 | ||||
| 	path = normalizePath(path) | ||||
| 
 | ||||
| 	var files = listDir(path) | ||||
| @ -1055,6 +1033,21 @@ function loadDir(path){ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Open image in an external editor/viewer
 | ||||
| //
 | ||||
| // NOTE: this will open the default editor/viewer.
 | ||||
| function openImage(){ | ||||
| 	// CEF
 | ||||
| 	if(window.runSystem == null){ | ||||
| 		console.error('Can\'t run external programs.') | ||||
| 		return  | ||||
| 	} | ||||
| 
 | ||||
| 	// XXX if path is not present try and open the biggest preview...
 | ||||
| 	return runSystem(normalizePath(IMAGES[getImageGID()].path, BASE_URL)) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * Setup | ||||
|  | ||||
| @ -457,16 +457,12 @@ $(function(){ | ||||
| 
 | ||||
| 	//setElementOrigin($('.ribbon-set'), 'top', 'left') | ||||
| 
 | ||||
| 
 | ||||
| 	// we have an image file... | ||||
| 	if((DATA_ATTR + '_BASE_URL') in localStorage){ | ||||
| 		BASE_URL = localStorage[DATA_ATTR + '_BASE_URL'] | ||||
| 		var loading = loadFileImages() | ||||
| 			.done(function(){ | ||||
| 				var d = loadLocalStorageData() | ||||
| 				DATA = d.data | ||||
| 				BASE_URL = d.base_url | ||||
| 				loadData() | ||||
| 			}) | ||||
| 
 | ||||
| 		var loading = loadDir(BASE_URL) | ||||
| 
 | ||||
| 	} else { | ||||
| 		// everything is in localStorage... | ||||
| @ -485,17 +481,15 @@ $(function(){ | ||||
| 
 | ||||
| 	loading | ||||
| 		.done(function(){ | ||||
| 			console.log('Loading settings...') | ||||
| 			loadLocalStorageSettings() | ||||
| 
 | ||||
| 			// XXX this will reload everything... | ||||
| 			if('MARKED' in localStorage){ | ||||
| 				loadLocalStorageMarks() | ||||
| 			} | ||||
| 
 | ||||
| 			loadLocalStorageSettings() | ||||
| 
 | ||||
| 			// XXX stub... | ||||
| 			//centerView(focusImage($('.image').first()), 'css') | ||||
| 			updateImages() | ||||
| 
 | ||||
| 		}) | ||||
| 
 | ||||
| }) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user