mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	some cleanup and refactoring + started work on history...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									e61f0c3365
								
							
						
					
					
						commit
						90174366f7
					
				| @ -60,6 +60,10 @@ dev: css | ||||
| 	unzip -uj $(wildcard targets/node-webkit/node-webkit-*-win-ia32.zip) -d . | ||||
| 	chmod +x *.{exe,dll} | ||||
| 
 | ||||
| dev-targets: | ||||
| 	mkdir -p targets/node-webkit | ||||
| 	wget  | ||||
| 
 | ||||
| 
 | ||||
| # build targets...
 | ||||
| 
 | ||||
|  | ||||
| @ -1025,6 +1025,8 @@ function zoomOut(){ | ||||
| 
 | ||||
| 
 | ||||
| /************************************************** Editor Actions ***/ | ||||
| // NOTE: for shiftImageRight/shiftImageLeft see data.js, as they depend
 | ||||
| // 		on data ordering...
 | ||||
| 
 | ||||
| function shiftImageTo(image, direction, moving, force_create_ribbon, mode){ | ||||
| 	if(image == null){ | ||||
| @ -1061,11 +1063,6 @@ function shiftImageDownNewRibbon(image, moving){ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // TODO manual image ordering (shiftLeft/shiftRight functions)
 | ||||
| // XXX
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * vim:set sw=4 ts=4 :												 */ | ||||
|  | ||||
							
								
								
									
										97
									
								
								ui/data.js
									
									
									
									
									
								
							
							
						
						
									
										97
									
								
								ui/data.js
									
									
									
									
									
								
							| @ -113,6 +113,8 @@ var SETTINGS = { | ||||
| } | ||||
| 
 | ||||
| var BASE_URL = '.' | ||||
| var BASE_URL_HISTORY = [] | ||||
| var BASE_URL_LIMIT = 10 | ||||
| 
 | ||||
| var IMAGE_CACHE = [] | ||||
| 
 | ||||
| @ -394,6 +396,19 @@ Array.prototype.binSearch = function(target, cmp, get){ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Base URL interface...
 | ||||
| //
 | ||||
| // NOTE: changing a base URL will trigger a baseURLChanged event...
 | ||||
| function setBaseURL(url){ | ||||
| 	var old_url = BASE_URL | ||||
| 	BASE_URL = url | ||||
| 	$('.viewer').trigger('baseURLChanged', [old_url, url]) | ||||
| } | ||||
| function getBaseURL(){ | ||||
| 	return BASE_URL | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Normalize the path...
 | ||||
| //
 | ||||
| // This will:
 | ||||
| @ -411,7 +426,7 @@ Array.prototype.binSearch = function(target, cmp, get){ | ||||
| // NOTE: mode can be either 'absolute' (default) or 'relative'...
 | ||||
| function normalizePath(url, base, mode){ | ||||
| 	mode = mode == null ? 'absolute' : mode | ||||
| 	base = base == null ? BASE_URL : base | ||||
| 	base = base == null ? getBaseURL() : base | ||||
| 
 | ||||
| 	// windows path...
 | ||||
| 	//	- replace all '\\' with '/'...
 | ||||
| @ -624,60 +639,6 @@ function dataFromImages(images){ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Construct a ribbons hierarchy from the fav dirs structure
 | ||||
| //
 | ||||
| // NOTE: this depends on listDir(...)
 | ||||
| // NOTE: this assumes that images contain ALL the images...
 | ||||
| function ribbonsFromFavDirs(path, images, cmp){ | ||||
| 	path = path == null ? BASE_URL : path | ||||
| 	images = images == null ? IMAGES : images | ||||
| 
 | ||||
| 	// build a reverse name-gid index for fast access...
 | ||||
| 	var index = {} | ||||
| 	var name | ||||
| 	for(var gid in images){ | ||||
| 		name = images[gid].path.split('/').pop() | ||||
| 		// XXX we assume that names are unique...
 | ||||
| 		index[name] = gid | ||||
| 	} | ||||
| 
 | ||||
| 	var ribbons = [] | ||||
| 	// add the base row...
 | ||||
| 	var base = Object.keys(images) | ||||
| 	ribbons.push(base) | ||||
| 
 | ||||
| 	var files = listDir(path)	 | ||||
| 	var cur_path = path | ||||
| 	while(files.indexOf('fav') >= 0){ | ||||
| 		cur_path += '/fav' | ||||
| 		files = listDir(cur_path) | ||||
| 		ribbon = [] | ||||
| 		// collect the images...
 | ||||
| 		$.each(files, function(i, e){ | ||||
| 			var _gid = index[e] | ||||
| 			// filter out non-image files...
 | ||||
| 			if(/.*\.(jpg|jpeg)$/i.test(e)){ | ||||
| 				ribbon.push(_gid) | ||||
| 			}  | ||||
| 			// remove the found item from each of the below ribbons...
 | ||||
| 			$.each(ribbons, function(i ,e){ | ||||
| 				if(e.indexOf(_gid) != -1){ | ||||
| 					e.splice(e.indexOf(_gid), 1) | ||||
| 				} | ||||
| 			}) | ||||
| 		}) | ||||
| 		ribbons.push(ribbon) | ||||
| 	} | ||||
| 
 | ||||
| 	// remove empty ribbons and sort the rest...
 | ||||
| 	ribbons = $.map(ribbons, function(e){  | ||||
| 		return e.length > 0 ? [cmp == null ? e : e.sort(cmp)] : null  | ||||
| 	}) | ||||
| 
 | ||||
| 	return ribbons.reverse() | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * Format conversion | ||||
| @ -1092,6 +1053,30 @@ function preCacheAllRibbons(){ | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * URL history... | ||||
| */ | ||||
| 
 | ||||
| function setupBaseURLHistory(){ | ||||
| 	$('.viewer') | ||||
| 		.on('baseURLChanged', function(evt, old_url, new_url){ | ||||
| 			BASE_URL_HISTORY.splice(0, 0, old_url) | ||||
| 
 | ||||
| 			// truncate the history if needed...
 | ||||
| 			if(BASE_URL_HISTORY.length > BASE_URL_LIMIT){ | ||||
| 				BASE_URL_HISTORY.splice(BASE_URL_LIMIT, BASE_URL_HISTORY.length) | ||||
| 			} | ||||
| 		}) | ||||
| } | ||||
| 
 | ||||
| // XXX...
 | ||||
| function getNextLocation(){ | ||||
| } | ||||
| function getPrevLocation(){ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /********************************************************************** | ||||
| * Actions... | ||||
| */ | ||||
| @ -1107,7 +1092,7 @@ function openImage(){ | ||||
| 		return  | ||||
| 	} | ||||
| 	// XXX if path is not present try and open the biggest preview...
 | ||||
| 	return runSystem(normalizePath(IMAGES[getImageGID()].path, BASE_URL)) | ||||
| 	return runSystem(normalizePath(IMAGES[getImageGID()].path, getBaseURL())) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										60
									
								
								ui/files.js
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								ui/files.js
									
									
									
									
									
								
							| @ -167,6 +167,60 @@ function loadLatestFile(path, dfl, pattern, diff_pattern){ | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // Construct a ribbons hierarchy from the fav dirs structure
 | ||||
| //
 | ||||
| // NOTE: this depends on listDir(...)
 | ||||
| // NOTE: this assumes that images contain ALL the images...
 | ||||
| function ribbonsFromFavDirs(path, images, cmp){ | ||||
| 	path = path == null ? getBaseURL() : path | ||||
| 	images = images == null ? IMAGES : images | ||||
| 
 | ||||
| 	// build a reverse name-gid index for fast access...
 | ||||
| 	var index = {} | ||||
| 	var name | ||||
| 	for(var gid in images){ | ||||
| 		name = images[gid].path.split('/').pop() | ||||
| 		// XXX we assume that names are unique...
 | ||||
| 		index[name] = gid | ||||
| 	} | ||||
| 
 | ||||
| 	var ribbons = [] | ||||
| 	// add the base row...
 | ||||
| 	var base = Object.keys(images) | ||||
| 	ribbons.push(base) | ||||
| 
 | ||||
| 	var files = listDir(path)	 | ||||
| 	var cur_path = path | ||||
| 	while(files.indexOf('fav') >= 0){ | ||||
| 		cur_path += '/fav' | ||||
| 		files = listDir(cur_path) | ||||
| 		ribbon = [] | ||||
| 		// collect the images...
 | ||||
| 		$.each(files, function(i, e){ | ||||
| 			var _gid = index[e] | ||||
| 			// filter out non-image files...
 | ||||
| 			if(/.*\.(jpg|jpeg)$/i.test(e)){ | ||||
| 				ribbon.push(_gid) | ||||
| 			}  | ||||
| 			// remove the found item from each of the below ribbons...
 | ||||
| 			$.each(ribbons, function(i ,e){ | ||||
| 				if(e.indexOf(_gid) != -1){ | ||||
| 					e.splice(e.indexOf(_gid), 1) | ||||
| 				} | ||||
| 			}) | ||||
| 		}) | ||||
| 		ribbons.push(ribbon) | ||||
| 	} | ||||
| 
 | ||||
| 	// remove empty ribbons and sort the rest...
 | ||||
| 	ribbons = $.map(ribbons, function(e){  | ||||
| 		return e.length > 0 ? [cmp == null ? e : e.sort(cmp)] : null  | ||||
| 	}) | ||||
| 
 | ||||
| 	return ribbons.reverse() | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| /*********************************************************************/ | ||||
| 
 | ||||
| @ -307,7 +361,7 @@ function loadFileState(path, prefix){ | ||||
| 				DATA_FILE_DEFAULT,  | ||||
| 				DATA_FILE_PATTERN), res, true) | ||||
| 		.done(function(json){ | ||||
| 			BASE_URL = base | ||||
| 			setBaseURL(base) | ||||
| 
 | ||||
| 			// legacy format...
 | ||||
| 			if(json.version == null){ | ||||
| @ -325,7 +379,7 @@ function loadFileState(path, prefix){ | ||||
| 						// XXX load config...
 | ||||
| 						// load images...
 | ||||
| 						bubbleProgress(prefix, | ||||
| 							loadFileImages(DATA.image_file == null ? | ||||
| 							loadFileImages(DATA.image_file != null ? | ||||
| 									normalizePath(DATA.image_file, base)  | ||||
| 									: null), res, true), | ||||
| 						// load marks if available...
 | ||||
| @ -405,7 +459,7 @@ function loadRawDir(path, prefix){ | ||||
| 		return res.reject() | ||||
| 	} | ||||
| 
 | ||||
| 	BASE_URL = path | ||||
| 	setBaseURL(path) | ||||
| 
 | ||||
| 	IMAGES = imagesFromUrls(image_paths) | ||||
| 	res.notify(prefix, 'Loaded', 'Images.') | ||||
|  | ||||
| @ -169,6 +169,7 @@ $(function(){ | ||||
| 			centerView() | ||||
| 		}) | ||||
| 		 | ||||
| 	setupBaseURLHistory() | ||||
| 	setupDataBindings() | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -13,6 +13,26 @@ | ||||
| * XXX should we use jStorage here? | ||||
| */ | ||||
| 
 | ||||
| function loadLocalStorageBaseURL(attr){ | ||||
| 	attr = attr == null ? DATA_ATTR : attr | ||||
| 	setBaseURL(localStorage[attr + '_BASE_URL']) | ||||
| } | ||||
| function saveLocalStorageBaseURL(attr){ | ||||
| 	attr = attr == null ? DATA_ATTR : attr | ||||
| 	localStorage[attr + '_BASE_URL'] = getBaseURL() | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| function loadLocalStorageBaseURLHistory(attr){ | ||||
| 	attr = attr == null ? DATA_ATTR : attr | ||||
| 	BASE_URL_HISTORY = JSON.parse(localStorage[attr + '_BASE_URL_HISTORY']) | ||||
| } | ||||
| function saveLocalStorageBaseURLHistory(attr){ | ||||
| 	attr = attr == null ? DATA_ATTR : attr | ||||
| 	localStorage[attr + '_BASE_URL_HISTORY'] = JSON.stringify(BASE_URL_HISTORY) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| function loadLocalStorageData(attr){ | ||||
| 	attr = attr == null ? DATA_ATTR : attr | ||||
| 	var data = localStorage[attr] | ||||
| @ -29,7 +49,7 @@ function loadLocalStorageData(attr){ | ||||
| function saveLocalStorageData(attr){ | ||||
| 	attr = attr == null ? DATA_ATTR : attr | ||||
| 	localStorage[attr] = JSON.stringify(DATA) | ||||
| 	localStorage[attr + '_BASE_URL'] = BASE_URL | ||||
| 	saveLocalStorageBaseURL(attr) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| @ -84,7 +104,7 @@ function saveLocalStorageSettings(attr){ | ||||
| function loadLocalStorage(attr){ | ||||
| 	attr = attr == null ? DATA_ATTR : attr | ||||
| 	var d = loadLocalStorageData(attr) | ||||
| 	BASE_URL = d.base_url | ||||
| 	setBaseURL(d.base_url) | ||||
| 	DATA = d.data | ||||
| 	IMAGES = loadLocalStorageImages(attr) | ||||
| 	return reloadViewer() | ||||
|  | ||||
| @ -304,6 +304,11 @@ function setupDataBindings(viewer){ | ||||
| 				indicator.removeClass('shown') | ||||
| 			} | ||||
| 		}) | ||||
| 
 | ||||
| 		.on('baseURLChanged', function(evt, url){ | ||||
| 			saveLocalStorageBaseURL() | ||||
| 			saveLocalStorageBaseURLHistory() | ||||
| 		}) | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user