| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-17 04:41:40 +04:00
										 |  |  | // NOTE: this is a sparse list, i.e. all elements are in the same 
 | 
					
						
							|  |  |  | // 		position as they are in DATA.order, and the unmarked elements
 | 
					
						
							|  |  |  | // 		are undefined.
 | 
					
						
							|  |  |  | // 		This is done because:
 | 
					
						
							|  |  |  | // 			- it drasticly simplifies adding, removing and access as 
 | 
					
						
							|  |  |  | // 				there is no searching and checking involved, just insert
 | 
					
						
							|  |  |  | // 				to the same spot as in order and you are safe.
 | 
					
						
							|  |  |  | // 			- trivial sorting
 | 
					
						
							|  |  |  | // 			- less maintenance and sync
 | 
					
						
							|  |  |  | // 		The tradeoff being:
 | 
					
						
							|  |  |  | // 			- load/save conversion to keep the json	data "packed".
 | 
					
						
							|  |  |  | // NOTE: it would appear that JS is designed with sparse lists in mind:
 | 
					
						
							|  |  |  | // 		- all iterators (map, filter, forEach, ..) skip undefined values
 | 
					
						
							|  |  |  | // 		- really fast
 | 
					
						
							| 
									
										
										
										
											2013-12-15 18:56:21 +04:00
										 |  |  | var MARKED = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | * helpers... | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-04 23:18:23 +04:00
										 |  |  | function _addMark(cls, gid, image){ | 
					
						
							|  |  |  | 	gid = gid == null ? getImageGID() : gid | 
					
						
							|  |  |  | 	image = image == null ? getImage() : $(image) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-13 06:36:40 +04:00
										 |  |  | 	// no image is loaded...
 | 
					
						
							|  |  |  | 	if(image.length == 0){ | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-04 23:18:23 +04:00
										 |  |  | 	var mark = $('.mark.'+cls+'.'+gid) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(mark.length == 0){ | 
					
						
							| 
									
										
										
										
											2013-12-13 03:39:23 +04:00
										 |  |  | 		mark = $('<div class="mark"/>') | 
					
						
							| 
									
										
										
										
											2013-12-04 23:18:23 +04:00
										 |  |  | 			.addClass(gid) | 
					
						
							| 
									
										
										
										
											2013-12-13 03:39:23 +04:00
										 |  |  | 			.addClass(cls) | 
					
						
							| 
									
										
										
										
											2014-01-01 07:41:53 +04:00
										 |  |  | 			//.insertAfter(image)
 | 
					
						
							| 
									
										
										
										
											2013-12-04 23:18:23 +04:00
										 |  |  | 	}  | 
					
						
							| 
									
										
										
										
											2014-01-01 07:41:53 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// make sure the mark is explicitly after the image...
 | 
					
						
							|  |  |  | 	// XXX think of an eficient way to test if we need to re-insert...
 | 
					
						
							| 
									
										
										
										
											2014-01-20 09:40:36 +04:00
										 |  |  | 	mark.insertAfter(image) | 
					
						
							| 
									
										
										
										
											2014-01-01 07:41:53 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-04 23:18:23 +04:00
										 |  |  | 	return mark | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function _removeMark(cls, gid, image){ | 
					
						
							|  |  |  | 	gid = gid == null ? getImageGID() : gid | 
					
						
							|  |  |  | 	image = image == null ? getImage() : $(image) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-13 06:36:40 +04:00
										 |  |  | 	// no image is loaded...
 | 
					
						
							|  |  |  | 	if(image.length == 0){ | 
					
						
							|  |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-04 23:18:23 +04:00
										 |  |  | 	var mark = $('.mark.'+cls+'.'+gid) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(mark.length != 0){ | 
					
						
							|  |  |  | 		mark.detach() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return mark | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-13 06:37:08 +04:00
										 |  |  | function makeMarkedLister(get_marked){ | 
					
						
							|  |  |  | 	return function(mode){ | 
					
						
							|  |  |  | 		var marked = get_marked() | 
					
						
							|  |  |  | 		mode = mode == null ? 'all' : mode | 
					
						
							| 
									
										
										
										
											2014-01-16 15:43:30 +04:00
										 |  |  | 		return mode == 'all' ? getLoadedGIDs(marked)  | 
					
						
							| 
									
										
										
										
											2014-01-13 06:37:08 +04:00
										 |  |  | 			: mode.constructor.name == 'Array' ? getLoadedGIDs(mode) | 
					
						
							| 
									
										
										
										
											2014-01-16 15:43:30 +04:00
										 |  |  | 			: typeof(mode) == typeof(123) ? getRibbonGIDs(marked, mode) | 
					
						
							|  |  |  | 			: getRibbonGIDs(marked) | 
					
						
							| 
									
										
										
										
											2014-01-13 06:37:08 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Make lister of unmarked images...
 | 
					
						
							| 
									
										
										
										
											2014-01-02 06:59:06 +04:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-01-17 04:49:02 +04:00
										 |  |  | // The resulting function can take one argument (mode) which can be:
 | 
					
						
							|  |  |  | // 	- null			- default, same as 'all'
 | 
					
						
							|  |  |  | // 	- 'all'			- process all loaded gids
 | 
					
						
							|  |  |  | // 	- 'ribbon'		- process curent ribbon
 | 
					
						
							|  |  |  | // 	- number		- ribbon index to process
 | 
					
						
							|  |  |  | // 	- Array			- list of gids to filter
 | 
					
						
							|  |  |  | function makeUnmarkedLister(get_marked){ | 
					
						
							| 
									
										
										
										
											2014-01-13 06:37:08 +04:00
										 |  |  | 	return function(mode){ | 
					
						
							| 
									
										
										
										
											2014-01-16 15:43:30 +04:00
										 |  |  | 		mode = mode == null ? 'all' : mode | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-13 06:37:08 +04:00
										 |  |  | 		var marked = get_marked() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var gids = mode == 'all' ? getLoadedGIDs()  | 
					
						
							|  |  |  | 			: mode.constructor.name == 'Array' ? getLoadedGIDs(mode) | 
					
						
							| 
									
										
										
										
											2014-01-16 15:43:30 +04:00
										 |  |  | 			: typeof(mode) == typeof(123) ? getRibbonGIDs(marked, mode) | 
					
						
							|  |  |  | 			: getRibbonGIDs(marked) | 
					
						
							| 
									
										
										
										
											2014-01-13 06:37:08 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// calculate the set...
 | 
					
						
							|  |  |  | 		var res = gids.filter(function(e){ | 
					
						
							|  |  |  | 			// keep only unmarked...
 | 
					
						
							|  |  |  | 			return marked.indexOf(e) < 0 | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2014-01-02 06:59:06 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-13 06:37:08 +04:00
										 |  |  | 		return res | 
					
						
							| 
									
										
										
										
											2014-01-02 06:59:06 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-17 04:49:02 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // The same as makeUnmarkedLister(..) but designed for sparse lists...
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:43:30 +04:00
										 |  |  | // NOTE: this is about an order of magnitude faster than the non-sparse
 | 
					
						
							|  |  |  | // 		version...
 | 
					
						
							| 
									
										
										
										
											2014-01-18 04:42:11 +04:00
										 |  |  | //
 | 
					
						
							|  |  |  | // XXX if this gets used often, add caching -- this may get quite slow
 | 
					
						
							|  |  |  | // 		for very large image sets...
 | 
					
						
							| 
									
										
										
										
											2014-01-17 04:49:02 +04:00
										 |  |  | function makeUnmarkedSparseLister(get_marked){ | 
					
						
							| 
									
										
										
										
											2014-01-16 15:43:30 +04:00
										 |  |  | 	return function(mode){ | 
					
						
							|  |  |  | 		mode = mode == null ? 'all' : mode | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var marked = get_marked() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var res = mode == 'all' ?  | 
					
						
							|  |  |  | 				DATA.order.slice() | 
					
						
							|  |  |  | 			: mode == 'ribbon' ?  | 
					
						
							| 
									
										
										
										
											2014-03-06 05:49:14 +04:00
										 |  |  | 				populateSparseGIDList(getRibbonGIDs()) | 
					
						
							| 
									
										
										
										
											2014-01-16 15:43:30 +04:00
										 |  |  | 			: typeof(mode) == typeof(123) ?  | 
					
						
							| 
									
										
										
										
											2014-03-06 05:49:14 +04:00
										 |  |  | 				populateSparseGIDList(getRibbonGIDs(mode)) | 
					
						
							| 
									
										
										
										
											2014-01-16 15:43:30 +04:00
										 |  |  | 			: mode | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// for ribbon modes, remove non-ribbon marks...
 | 
					
						
							|  |  |  | 		if(mode == 'ribbon'){ | 
					
						
							|  |  |  | 			marked = getRibbonGIDs(marked) | 
					
						
							|  |  |  | 		} else if(typeof(mode) == typeof(123)){ | 
					
						
							|  |  |  | 			marked = getRibbonGIDs(marked, mode) | 
					
						
							|  |  |  | 			mode = 'ribbon' | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// negate the list...
 | 
					
						
							|  |  |  | 		marked.forEach(function(e, i){ | 
					
						
							|  |  |  | 			delete res[i] | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return getLoadedGIDs(compactSparceList(res)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-02 06:59:06 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-13 06:37:08 +04:00
										 |  |  | var getMarked = makeMarkedLister(function(){ return MARKED }) | 
					
						
							| 
									
										
										
										
											2014-01-17 04:49:02 +04:00
										 |  |  | var getUnmarked = makeUnmarkedSparseLister(function(){ return MARKED }) | 
					
						
							| 
									
										
										
										
											2014-01-13 06:37:08 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-16 01:49:47 +04:00
										 |  |  | var getMarkedGIDBefore = makeGIDBeforeGetterFromList( | 
					
						
							|  |  |  | 		function(){  | 
					
						
							| 
									
										
										
										
											2014-01-16 06:36:59 +04:00
										 |  |  | 			return compactSparceList(MARKED) | 
					
						
							| 
									
										
										
										
											2013-12-16 01:49:47 +04:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-02 06:59:06 +04:00
										 |  |  | // NOTE: this is not too fast as it will filter the marked images...
 | 
					
						
							|  |  |  | // NOTE: this is restricted to current ribbon...
 | 
					
						
							|  |  |  | var getUnmarkedGIDBefore = makeGIDBeforeGetterFromList( | 
					
						
							|  |  |  | 		function(ribbon){  | 
					
						
							|  |  |  | 			return getUnmarked(ribbon) | 
					
						
							|  |  |  | 		}, true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 19:35:13 +04:00
										 |  |  | // Make a mark toggler
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // The toggler will:
 | 
					
						
							|  |  |  | // 	- toggle img_class on the target image
 | 
					
						
							|  |  |  | // 	- add/remove a mark element after the image
 | 
					
						
							|  |  |  | // 	- toggle mark_class on the mark element
 | 
					
						
							| 
									
										
										
										
											2013-12-17 21:26:57 +04:00
										 |  |  | // 	- call the callback, if defined, passing it:
 | 
					
						
							|  |  |  | // 		- gid
 | 
					
						
							| 
									
										
										
										
											2013-12-18 05:09:47 +04:00
										 |  |  | // 		- action ('on' or 'off')
 | 
					
						
							| 
									
										
										
										
											2013-12-12 19:35:13 +04:00
										 |  |  | // 	- trigger the evt_name on the viewer passing it:
 | 
					
						
							| 
									
										
										
										
											2013-12-17 21:26:57 +04:00
										 |  |  | // 		- gid
 | 
					
						
							| 
									
										
										
										
											2013-12-18 05:09:47 +04:00
										 |  |  | // 		- action ('on' or 'off')
 | 
					
						
							| 
									
										
										
										
											2013-12-12 19:35:13 +04:00
										 |  |  | //
 | 
					
						
							|  |  |  | // The actual toggler is built with createCSSClassToggler(..), see its
 | 
					
						
							|  |  |  | // docs for protocol descrittion.
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2013-12-18 05:09:47 +04:00
										 |  |  | // The resulting toggler, by default, marks the current image 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 19:35:13 +04:00
										 |  |  | // (.current.image), but can be passed a different image as first 
 | 
					
						
							|  |  |  | // argument.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // NOTE: when passing an alternative image as an argument, the second 
 | 
					
						
							|  |  |  | // 		argument MUST also be passed. it can be one of:
 | 
					
						
							|  |  |  | // 			- 'on'		: force create mark
 | 
					
						
							|  |  |  | // 			- 'off'		: force remove mark
 | 
					
						
							|  |  |  | // 			- 'next'	: toggle next state (default)
 | 
					
						
							| 
									
										
										
										
											2013-12-13 06:36:40 +04:00
										 |  |  | // NOTE: when passing this a gid, the 'next' action is not supported
 | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | function makeMarkToggler(img_class, mark_class, evt_name, callback){ | 
					
						
							| 
									
										
										
										
											2013-12-11 02:47:44 +04:00
										 |  |  | 	return createCSSClassToggler( | 
					
						
							|  |  |  | 		'.current.image',  | 
					
						
							|  |  |  | 		img_class, | 
					
						
							|  |  |  | 		function(action, elem){ | 
					
						
							| 
									
										
										
										
											2013-12-30 03:15:09 +04:00
										 |  |  | 			toggleMarksView('on') | 
					
						
							| 
									
										
										
										
											2013-12-13 06:36:40 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// we got a gid...
 | 
					
						
							|  |  |  | 			if(elem.length == 0 && elem.selector in IMAGES){ | 
					
						
							|  |  |  | 				var gid = elem.selector | 
					
						
							|  |  |  | 				elem = getImage(gid) | 
					
						
							|  |  |  | 				elem = elem.length == 0 ? null : elem | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// we are given an image...
 | 
					
						
							| 
									
										
										
										
											2013-12-11 02:47:44 +04:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2013-12-13 06:36:40 +04:00
										 |  |  | 				var gid = getImageGID(elem) | 
					
						
							| 
									
										
										
										
											2013-12-11 02:47:44 +04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-13 06:36:40 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// do this only of the image is loaded...
 | 
					
						
							|  |  |  | 			if(elem != null){ | 
					
						
							|  |  |  | 				if(action == 'on'){ | 
					
						
							|  |  |  | 					_addMark(mark_class, gid, elem) | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					_removeMark(mark_class, gid, elem) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 21:26:57 +04:00
										 |  |  | 			if(callback != null){ | 
					
						
							|  |  |  | 				callback(gid, action) | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-13 06:36:40 +04:00
										 |  |  | 			$('.viewer').trigger(evt_name, [gid, action]) | 
					
						
							| 
									
										
										
										
											2013-12-11 02:47:44 +04:00
										 |  |  | 		}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-30 03:15:09 +04:00
										 |  |  | // Generate an image updater function...
 | 
					
						
							| 
									
										
										
										
											2013-12-14 04:29:51 +04:00
										 |  |  | //
 | 
					
						
							|  |  |  | // the resulting function will update image mark state by adding or 
 | 
					
						
							|  |  |  | // removing the mark the specific mark object.
 | 
					
						
							| 
									
										
										
										
											2013-12-13 03:39:23 +04:00
										 |  |  | function makeMarkUpdater(img_class, mark_class, test){ | 
					
						
							| 
									
										
										
										
											2013-12-14 06:58:13 +04:00
										 |  |  | 	var _updater = function(gid, image){ | 
					
						
							| 
									
										
										
										
											2013-12-13 03:39:23 +04:00
										 |  |  | 		// marks...
 | 
					
						
							|  |  |  | 		if(test(gid)){ | 
					
						
							|  |  |  | 			image.addClass(img_class) | 
					
						
							|  |  |  | 			_addMark(mark_class, gid, image) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			image.removeClass(img_class) | 
					
						
							|  |  |  | 			_removeMark(mark_class, gid, image) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return image | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-14 06:58:13 +04:00
										 |  |  | 	IMAGE_UPDATERS.push(_updater) | 
					
						
							|  |  |  | 	return _updater | 
					
						
							| 
									
										
										
										
											2013-12-13 03:39:23 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-15 06:19:21 +04:00
										 |  |  | // NOTE: this supports only shifts by one position...
 | 
					
						
							| 
									
										
										
										
											2014-01-16 04:52:11 +04:00
										 |  |  | // XXX this is similar to insertGIDToPosition(..) do we need both?
 | 
					
						
							|  |  |  | // 		...this one is a special case and insertGIDToPosition(..) is 
 | 
					
						
							|  |  |  | // 		general, the later uses search to find the position, here we 
 | 
					
						
							|  |  |  | // 		know the aproximate location, the question is if this speedup
 | 
					
						
							|  |  |  | // 		is worth the effort of maintaining a special case function...
 | 
					
						
							| 
									
										
										
										
											2014-01-15 06:19:21 +04:00
										 |  |  | function shiftGIDToOrderInList(gid, direction, list){ | 
					
						
							|  |  |  | 	var gid_o = DATA.order.indexOf(gid) | 
					
						
							|  |  |  | 	var gid_m = list.indexOf(gid) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var a_m = gid_m + (direction == 'next' ? 1 : -1) | 
					
						
							|  |  |  | 	if(a_m < 0 || a_m >= list.length){ | 
					
						
							|  |  |  | 		return false | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var a_gid = list[a_m] | 
					
						
							|  |  |  | 	var a_o = DATA.order.indexOf(a_gid) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// if relative positions of cur and adjacent gids in list 
 | 
					
						
							|  |  |  | 	// are different to that in DATA.order, then replace the gids
 | 
					
						
							|  |  |  | 	// in list...
 | 
					
						
							|  |  |  | 	if(sign(a_m - gid_m) != sign(a_o - gid_o)){ | 
					
						
							|  |  |  | 		list[a_m] = gid | 
					
						
							|  |  |  | 		list[gid_m] = a_gid | 
					
						
							|  |  |  | 		return true | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-28 06:56:26 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:58:58 +04:00
										 |  |  | // a sparse version of shiftGIDToOrderInList(..)...
 | 
					
						
							| 
									
										
										
										
											2014-01-28 06:56:26 +04:00
										 |  |  | //
 | 
					
						
							|  |  |  | // returns true if list is updated....
 | 
					
						
							|  |  |  | function shiftGIDInSparseList(gid, from, to, list){ | 
					
						
							| 
									
										
										
										
											2014-01-29 07:27:07 +04:00
										 |  |  | 	// XXX do we need this???
 | 
					
						
							|  |  |  | 	if(list[from] == null  | 
					
						
							|  |  |  | 			&& list[to] == null  | 
					
						
							|  |  |  | 			// NOTE: if there is something between 'from' and 'to' it must 
 | 
					
						
							|  |  |  | 			// 		be shifted...
 | 
					
						
							|  |  |  | 			&& compactSparceList(list.slice(from, to)).length == 0){ | 
					
						
							| 
									
										
										
										
											2014-01-28 06:56:26 +04:00
										 |  |  | 		return false | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-16 15:58:58 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 07:27:07 +04:00
										 |  |  | 	// if gid was never in list, we must it and remove leave things as 
 | 
					
						
							|  |  |  | 	// we got them, and remove it again...
 | 
					
						
							| 
									
										
										
										
											2014-01-28 06:56:26 +04:00
										 |  |  | 	var cleanup = list.indexOf(gid) < 0 | 
					
						
							| 
									
										
										
										
											2014-01-16 15:58:58 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-28 06:56:26 +04:00
										 |  |  | 	// move the marked gid...
 | 
					
						
							|  |  |  | 	list.splice(from, 1) | 
					
						
							|  |  |  | 	list.splice(to, 0, gid) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// NOTE: essentially, we are using gid as a marker, as we can't 
 | 
					
						
							|  |  |  | 	// 		.splice(..) an undefined into a list...
 | 
					
						
							|  |  |  | 	if(cleanup){ | 
					
						
							|  |  |  | 		delete list[to] | 
					
						
							| 
									
										
										
										
											2014-01-16 15:58:58 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-28 06:56:26 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return true | 
					
						
							| 
									
										
										
										
											2014-01-16 15:58:58 +04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-15 06:19:21 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | // NOTE: this is sparse-only...
 | 
					
						
							|  |  |  | function setAllMarks(action, mode, list, toggler){ | 
					
						
							|  |  |  | 	action = action == null ? toggler('?') : action | 
					
						
							|  |  |  | 	mode = mode == null ? 'ribbon' : mode | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var updated = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(action == 'on'){ | 
					
						
							|  |  |  | 		var _update = function(e){ | 
					
						
							|  |  |  | 			if(list.indexOf(e) < 0){ | 
					
						
							|  |  |  | 				list[DATA.order.indexOf(e)] = e | 
					
						
							|  |  |  | 				updated.push(e) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		var _update = function(e){ | 
					
						
							|  |  |  | 			var i = list.indexOf(e) | 
					
						
							|  |  |  | 			if(i >= 0){ | 
					
						
							|  |  |  | 				delete list[i] | 
					
						
							|  |  |  | 				updated.push(e) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// marks from current ribbon (default)...
 | 
					
						
							|  |  |  | 	if(mode == 'ribbon'){ | 
					
						
							|  |  |  | 		var res = getRibbonGIDs() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// all marks...
 | 
					
						
							|  |  |  | 	} else if(mode == 'all'){ | 
					
						
							|  |  |  | 		var res = getLoadedGIDs() | 
					
						
							|  |  |  | 	}  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	res.forEach(_update) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updateImages(updated) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-10 05:10:55 +04:00
										 |  |  | 	//return res
 | 
					
						
							|  |  |  | 	return updated | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 21:26:57 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-13 03:39:23 +04:00
										 |  |  | /********************************************************************** | 
					
						
							| 
									
										
										
										
											2013-12-18 05:09:47 +04:00
										 |  |  | *  | 
					
						
							| 
									
										
										
										
											2013-12-13 03:39:23 +04:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var updateSelectedImageMark = makeMarkUpdater( | 
					
						
							|  |  |  | 		'marked', | 
					
						
							|  |  |  | 		'selected',  | 
					
						
							|  |  |  | 		function(gid){  | 
					
						
							|  |  |  | 			return MARKED.indexOf(gid) > -1  | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-24 19:35:03 +04:00
										 |  |  | // NOTE: to disable MARKED cleanout set no_cleanout_marks to true.
 | 
					
						
							|  |  |  | // NOTE: MARKED may contain both gids that are not loaded and that do 
 | 
					
						
							|  |  |  | // 		not exist, as there is no way to distinguish between the two 
 | 
					
						
							|  |  |  | // 		situations the cleanup is optional...
 | 
					
						
							| 
									
										
										
										
											2013-12-20 06:10:45 +04:00
										 |  |  | function cropMarkedImages(keep_ribbons, keep_unloaded_gids){ | 
					
						
							| 
									
										
										
										
											2014-01-20 09:40:36 +04:00
										 |  |  | 	cropDataTo(MARKED, keep_ribbons, keep_unloaded_gids) | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	return DATA | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * Modes | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-03 06:28:55 +04:00
										 |  |  | var toggleMarkedOnlyView = makeCropModeToggler(cropMarkedImages) | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-16 02:21:07 +04:00
										 |  |  | var toggleMarkedOnlyWithRibbonsView = makeCropModeToggler( | 
					
						
							|  |  |  | 		function(){ | 
					
						
							| 
									
										
										
										
											2013-12-20 06:10:45 +04:00
										 |  |  | 			cropMarkedImages(true) | 
					
						
							| 
									
										
										
										
											2013-11-16 02:21:07 +04:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-30 03:15:09 +04:00
										 |  |  | var toggleMarksView = createCSSClassToggler( | 
					
						
							| 
									
										
										
										
											2013-06-03 21:10:42 +04:00
										 |  |  | 	'.viewer',  | 
					
						
							|  |  |  | 	'marks-visible', | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	function(){ | 
					
						
							| 
									
										
										
										
											2013-05-28 21:59:38 +04:00
										 |  |  | 		var cur = getImage() | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 		// current is marked...
 | 
					
						
							|  |  |  | 		if(cur.hasClass('marked')){ | 
					
						
							|  |  |  | 			centerView(null, 'css') | 
					
						
							|  |  |  | 			return | 
					
						
							|  |  |  | 		}  | 
					
						
							|  |  |  | 		// there is a marked image in this ribbon...
 | 
					
						
							|  |  |  | 		var target = getImageBefore(cur, null) | 
					
						
							|  |  |  | 		if(target.length > 0){ | 
					
						
							|  |  |  | 			centerView(focusImage(target), 'css') | 
					
						
							|  |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// get marked image from other ribbons...
 | 
					
						
							|  |  |  | 		prevRibbon() | 
					
						
							| 
									
										
										
										
											2013-05-28 21:59:38 +04:00
										 |  |  | 		if(getImage().hasClass('marked')){ | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		nextRibbon() | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 06:59:04 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | * Actions | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | var toggleMark = makeMarkToggler( | 
					
						
							|  |  |  | 		'marked',  | 
					
						
							|  |  |  | 		'selected',  | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | 		'togglingMarks', | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 		function(gid, action){ | 
					
						
							|  |  |  | 			// add marked image to list...
 | 
					
						
							|  |  |  | 			if(action == 'on'){ | 
					
						
							|  |  |  | 				if(MARKED.indexOf(gid) == -1){ | 
					
						
							| 
									
										
										
										
											2014-01-16 06:36:59 +04:00
										 |  |  | 					MARKED[DATA.order.indexOf(gid)] = gid | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 				}  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// remove marked image from list...
 | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2014-01-16 06:36:59 +04:00
										 |  |  | 				delete MARKED[MARKED.indexOf(gid)] | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-24 05:23:51 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			marksUpdated() | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | function markAllImagesTo(action, mode){ | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 	mode = mode == null ? 'ribbon' : mode | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | 	var res = setAllMarks(action, mode, MARKED, toggleMark) | 
					
						
							|  |  |  | 	$('.viewer') | 
					
						
							|  |  |  | 		.trigger('togglingMarks', [res, action]) | 
					
						
							|  |  |  | 		.trigger('removingMarks', [res, mode]) | 
					
						
							| 
									
										
										
										
											2013-12-24 05:23:51 +04:00
										 |  |  | 	marksUpdated() | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 	return res | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | // Mark/Unmark images...
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | // mode can be:
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | //	- 'ribbon' (default)
 | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | //	- 'all'
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | function markAll(mode){ markAllImagesTo('on', mode) } | 
					
						
							| 
									
										
										
										
											2014-01-20 09:40:36 +04:00
										 |  |  | function unmarkAll(mode){ markAllImagesTo('off', mode) } | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | // Invert marks on images...
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // mode can be:
 | 
					
						
							|  |  |  | //	- 'ribbon' (default)
 | 
					
						
							|  |  |  | //	- 'all'
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | function invertImageMarks(mode, gids){ | 
					
						
							|  |  |  | 	mode = mode == null ? 'ribbon' : mode | 
					
						
							|  |  |  | 	gids = gids != null ? gids  | 
					
						
							|  |  |  | 			: mode == 'ribbon' ? getRibbonGIDs() | 
					
						
							|  |  |  | 			: getLoadedGIDs() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 	var on = [] | 
					
						
							|  |  |  | 	var off = [] | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 	var order = DATA.order | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 	$.each(gids, function(_, e){ | 
					
						
							|  |  |  | 		var i = order.indexOf(e) | 
					
						
							|  |  |  | 		if(MARKED[i] === undefined){ | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 			on.push(e) | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 			MARKED[i] = e | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			off.push(e) | 
					
						
							| 
									
										
										
										
											2014-01-16 06:36:59 +04:00
										 |  |  | 			delete MARKED[i] | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}) | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 	updateImages(gids) | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	$('.viewer') | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 		.trigger('invertingMarks', [gids]) | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 		.trigger('togglingMarks', [on, 'on']) | 
					
						
							|  |  |  | 		.trigger('togglingMarks', [off, 'off']) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-24 05:23:51 +04:00
										 |  |  | 	marksUpdated() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 	return gids | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Toggle marks in the current continuous section of marked or unmarked
 | 
					
						
							|  |  |  | // images...
 | 
					
						
							| 
									
										
										
										
											2013-12-14 06:29:22 +04:00
										 |  |  | function toggleMarkBlock(image){ | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 	image = image == null ? getImage() : image | 
					
						
							|  |  |  | 	var gid = typeof(image) == typeof('str') ? image : getImageGID(image) | 
					
						
							|  |  |  | 	image = typeof(image) == typeof('str') ? getImage(gid) : image | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var state = toggleMark(image, 'next') == 'off' ? false : true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var ribbon = DATA.ribbons[getRibbonIndex(image)] | 
					
						
							|  |  |  | 	var i = ribbon.indexOf(gid) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var updated = [gid] | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 	var order = DATA.order | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var _convert = function(_, e){ | 
					
						
							|  |  |  | 		// break if state differs from current...
 | 
					
						
							|  |  |  | 		if((MARKED.indexOf(e) >= 0) == state){ | 
					
						
							|  |  |  | 			return false | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// do the toggle...
 | 
					
						
							|  |  |  | 		if(state){ | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 			MARKED[order.indexOf(e)] = e | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-01-16 06:36:59 +04:00
										 |  |  | 			delete MARKED[MARKED.indexOf(e)] | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 		updated.push(e) | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-13 06:36:40 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 	// go left...
 | 
					
						
							|  |  |  | 	var left = ribbon.slice(0, i) | 
					
						
							|  |  |  | 	left.reverse() | 
					
						
							|  |  |  | 	$.each(left, _convert) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// go right...
 | 
					
						
							|  |  |  | 	var right = ribbon.slice(i+1) | 
					
						
							|  |  |  | 	$.each(right, _convert) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updateImages(updated) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$('.viewer') | 
					
						
							|  |  |  | 		.trigger('togglingImageBlockMarks', [image, updated, state]) | 
					
						
							|  |  |  | 		.trigger('togglingMarks', [updated, state ? 'on' : 'off']) | 
					
						
							| 
									
										
										
										
											2013-12-13 06:36:40 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-24 05:23:51 +04:00
										 |  |  | 	marksUpdated() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	return state | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | // XXX need to account for empty ribbons...
 | 
					
						
							|  |  |  | function shiftMarkedImages(direction, mode, new_ribbon){ | 
					
						
							|  |  |  | 	mode = mode == null ? 'ribbon' : mode | 
					
						
							|  |  |  | 	var cur = getRibbonIndex() | 
					
						
							| 
									
										
										
										
											2013-12-17 04:55:02 +04:00
										 |  |  | 	var orig_ribbon = cur | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ribbon only...
 | 
					
						
							|  |  |  | 	if(mode == 'ribbon'){ | 
					
						
							|  |  |  | 		var ribbon = DATA.ribbons[cur] | 
					
						
							| 
									
										
										
										
											2013-12-28 06:17:05 +04:00
										 |  |  | 		// remove all the marked images form the current ribbon...
 | 
					
						
							|  |  |  | 		// NOTE: this builds a list of marked images ONLY in current 
 | 
					
						
							|  |  |  | 		// 		ribbon...
 | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | 		var marked = $.map(MARKED, function(e){ | 
					
						
							|  |  |  | 			var i = ribbon.indexOf(e) | 
					
						
							|  |  |  | 			if(i >= 0){ | 
					
						
							|  |  |  | 				ribbon.splice(i, 1) | 
					
						
							|  |  |  | 				return e | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return null | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// shift all marked images...
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		var marked = MARKED.slice() | 
					
						
							| 
									
										
										
										
											2013-12-21 09:49:15 +04:00
										 |  |  | 		// remove all the marked images form all other ribbons...
 | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | 		$.each(DATA.ribbons, function(ribbon){ | 
					
						
							|  |  |  | 			$.each(marked, function(e){ | 
					
						
							|  |  |  | 				var i = ribbon.indexOf(e) | 
					
						
							|  |  |  | 				i >= 0 ? ribbon.splice(i, 1) : null | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// if we are at the top or bottom ribbons we need to create a new 
 | 
					
						
							|  |  |  | 	// ribbon regardless...
 | 
					
						
							|  |  |  | 	if((cur == 0 && direction == 'prev')  | 
					
						
							|  |  |  | 			|| (cur == DATA.ribbons.length-1 && direction == 'next')){ | 
					
						
							|  |  |  | 		new_ribbon = true | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// add marked to new ribbon...
 | 
					
						
							|  |  |  | 	if(new_ribbon){ | 
					
						
							|  |  |  | 		cur += direction == 'next' ? 1 : 0 | 
					
						
							|  |  |  | 		DATA.ribbons.splice(cur, 0, marked) | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// add marked to existing ribbon...
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		cur += direction == 'next' ? 1 : -1 | 
					
						
							| 
									
										
										
										
											2013-12-21 09:49:15 +04:00
										 |  |  | 		DATA.ribbons[cur] = fastSortGIDsByOrder(DATA.ribbons[cur].concat(marked)) | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2014-06-01 17:35:38 +04:00
										 |  |  | 	dataUpdated() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 06:17:05 +04:00
										 |  |  | 	// remove empty ribbons and reload...
 | 
					
						
							|  |  |  | 	dropEmptyRibbons() | 
					
						
							|  |  |  | 	reloadViewer() | 
					
						
							| 
									
										
										
										
											2013-12-17 04:55:02 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	$('.viewer').trigger('shiftedImages', [marked, orig_ribbon, cur]) | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | } | 
					
						
							|  |  |  | function shiftMarkedImagesUp(mode, new_ribbon){ | 
					
						
							|  |  |  | 	return shiftMarkedImages('prev', mode, new_ribbon) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function shiftMarkedImagesDown(mode, new_ribbon){ | 
					
						
							|  |  |  | 	return shiftMarkedImages('next', mode, new_ribbon) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 09:40:36 +04:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | // XXX these are ribbon wise only (???)
 | 
					
						
							|  |  |  | // XXX this on first step this must pack all marked images
 | 
					
						
							|  |  |  | function horizontalShiftMarkedImages(direction){ | 
					
						
							| 
									
										
										
										
											2013-06-03 04:09:32 +04:00
										 |  |  | 	// XXX
 | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | } | 
					
						
							|  |  |  | function shiftMarkedImagesLeft(){ | 
					
						
							| 
									
										
										
										
											2013-12-17 04:37:20 +04:00
										 |  |  | 	return horizontalShiftMarkedImages('prev') | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | } | 
					
						
							|  |  |  | function shiftMarkedImagesRight(){ | 
					
						
							| 
									
										
										
										
											2013-12-17 04:37:20 +04:00
										 |  |  | 	return horizontalShiftMarkedImages('next') | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-01-20 09:40:36 +04:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2013-06-03 00:01:49 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 09:40:36 +04:00
										 |  |  | // Focus next/prev marked image...
 | 
					
						
							| 
									
										
										
										
											2013-12-16 01:49:47 +04:00
										 |  |  | //
 | 
					
						
							|  |  |  | // NOTE: these will not jump to marks on other ribbons... to prevent this
 | 
					
						
							|  |  |  | // 		add true as the final argument (see restrict_to_ribbon argument 
 | 
					
						
							|  |  |  | // 		of makeNextFromListAction(..) for more info)
 | 
					
						
							|  |  |  | var nextMark = makeNextFromListAction( | 
					
						
							|  |  |  | 		getMarkedGIDBefore,  | 
					
						
							| 
									
										
										
										
											2014-01-16 06:36:59 +04:00
										 |  |  | 		function(){ return compactSparceList(MARKED) }) | 
					
						
							| 
									
										
										
										
											2013-12-16 01:49:47 +04:00
										 |  |  | var prevMark = makePrevFromListAction( | 
					
						
							|  |  |  | 		getMarkedGIDBefore,  | 
					
						
							| 
									
										
										
										
											2014-01-16 06:36:59 +04:00
										 |  |  | 		function(){ return compactSparceList(MARKED) }) | 
					
						
							| 
									
										
										
										
											2013-12-16 01:49:47 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 09:40:36 +04:00
										 |  |  | // Focus next/prev unmarked image..
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-01-02 06:59:06 +04:00
										 |  |  | var nextUnmarked = makeNextFromListAction( | 
					
						
							|  |  |  | 		getUnmarkedGIDBefore,  | 
					
						
							|  |  |  | 		function(ribbon){  | 
					
						
							|  |  |  | 			return getUnmarked(ribbon == null ? 'ribbon' : ribbon)  | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | var prevUnmarked = makePrevFromListAction( | 
					
						
							|  |  |  | 		getUnmarkedGIDBefore,  | 
					
						
							|  |  |  | 		function(ribbon){  | 
					
						
							|  |  |  | 			return getUnmarked(ribbon == null ? 'ribbon' : ribbon)  | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-16 01:49:47 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | * Dialogs...  | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function markImagesDialog(){ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updateStatus('Mark...').show() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-05 05:55:14 +04:00
										 |  |  | 	var alg = 'Mark images:' | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-14 06:29:22 +04:00
										 |  |  | 	var cur = toggleMark('?') == 'on' ? 'Unmark' : 'Mark' | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cfg = {} | 
					
						
							|  |  |  | 	cfg[alg] = [ | 
					
						
							|  |  |  | 		cur + ' current image', | 
					
						
							|  |  |  | 		cur + ' current block | '+ | 
					
						
							|  |  |  | 			'A block is a set of similarly marked images\n'+ | 
					
						
							|  |  |  | 			'to the left and right of the current image,\n'+ | 
					
						
							|  |  |  | 			'up until the closest images marked differently', | 
					
						
							|  |  |  | 		'Invert marks in current ribbon', | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 		'Invert all marks', | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 		'Mark all in current ribbon', | 
					
						
							|  |  |  | 		'Unmark all in current ribbon', | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 		'Mark all images', | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 		'Unmark all images' | 
					
						
							|  |  |  | 	] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	formDialog(null, '',  | 
					
						
							|  |  |  | 			cfg, | 
					
						
							|  |  |  | 			'OK',  | 
					
						
							|  |  |  | 			'markImagesDialog') | 
					
						
							|  |  |  | 		.done(function(res){ | 
					
						
							|  |  |  | 			res = res[alg] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// NOTE: these must be in order of least-specific last...
 | 
					
						
							|  |  |  | 			if(/current image/.test(res)){ | 
					
						
							| 
									
										
										
										
											2013-12-14 06:29:22 +04:00
										 |  |  | 				toggleMark() | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 				var msg = (cur + ' image').toLowerCase() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} else if(/current block/.test(res)){ | 
					
						
							| 
									
										
										
										
											2013-12-14 06:29:22 +04:00
										 |  |  | 				toggleMarkBlock() | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 				var msg = 'toggled block marks' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 			} else if(/Invert .* ribbon/.test(res)){ | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 				invertImageMarks() | 
					
						
							|  |  |  | 				var msg = 'inverted ribbon marks' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-20 06:45:41 +04:00
										 |  |  | 			} else if(/Invert all/.test(res)){ | 
					
						
							|  |  |  | 				invertImageMarks('all') | 
					
						
							|  |  |  | 				var msg = 'inverted all marks' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 			} else if(/Mark all.*current ribbon/.test(res)){ | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | 				markAll('ribbon') | 
					
						
							| 
									
										
										
										
											2013-12-17 21:16:10 +04:00
										 |  |  | 				var msg = 'marked ribbon' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 			} else if(/Mark all/.test(res)){ | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | 				markAll('all') | 
					
						
							|  |  |  | 				var msg = 'marked all' | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			} else if(/Unmark all in/.test(res)){ | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | 				unmarkAll('ribbon') | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 				var msg = 'unmarked ribbon' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			} else if(/Unmark all images/.test(res)){ | 
					
						
							| 
									
										
										
										
											2014-01-20 06:18:36 +04:00
										 |  |  | 				unmarkAll('all') | 
					
						
							| 
									
										
										
										
											2013-12-05 03:58:13 +04:00
										 |  |  | 				var msg = 'unmarked all' | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			showStatusQ('Mark: '+msg+'...') | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 		.fail(function(){ | 
					
						
							|  |  |  | 			showStatusQ('Marking: canceled.') | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-14 05:07:57 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * Files... | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Load image marks form file
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // NOTE: if no marks are found then set them to []
 | 
					
						
							|  |  |  | var loadFileMarks = makeFileLoader( | 
					
						
							|  |  |  | 		'Marks',  | 
					
						
							| 
									
										
										
										
											2014-01-20 09:40:36 +04:00
										 |  |  | 		CONFIG.marked_file,  | 
					
						
							| 
									
										
										
										
											2013-12-28 08:57:11 +04:00
										 |  |  | 		[], | 
					
						
							| 
									
										
										
										
											2013-12-14 05:07:57 +04:00
										 |  |  | 		function(data){  | 
					
						
							| 
									
										
										
										
											2014-03-06 05:49:14 +04:00
										 |  |  | 			MARKED = populateSparseGIDList(data) | 
					
						
							| 
									
										
										
										
											2013-12-20 06:10:45 +04:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2014-01-30 08:25:00 +04:00
										 |  |  | 		null, | 
					
						
							| 
									
										
										
										
											2013-12-20 06:10:45 +04:00
										 |  |  | 		'marksLoaded') | 
					
						
							| 
									
										
										
										
											2013-12-14 05:07:57 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Save image marks to file
 | 
					
						
							|  |  |  | var saveFileMarks = makeFileSaver( | 
					
						
							| 
									
										
										
										
											2013-12-24 05:23:51 +04:00
										 |  |  | 		'Marks', | 
					
						
							| 
									
										
										
										
											2014-01-20 09:40:36 +04:00
										 |  |  | 		CONFIG.marked_file,  | 
					
						
							| 
									
										
										
										
											2013-12-14 05:07:57 +04:00
										 |  |  | 		function(){  | 
					
						
							| 
									
										
										
										
											2014-01-16 06:36:59 +04:00
										 |  |  | 			return compactSparceList(MARKED) | 
					
						
							| 
									
										
										
										
											2013-12-14 05:07:57 +04:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-24 05:23:51 +04:00
										 |  |  | function marksUpdated(){ | 
					
						
							|  |  |  | 	fileUpdated('Marks') | 
					
						
							| 
									
										
										
										
											2014-01-02 06:59:06 +04:00
										 |  |  | 	$('.viewer').trigger('marksUpdated') | 
					
						
							| 
									
										
										
										
											2013-12-24 05:23:51 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-14 05:07:57 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * Setup... | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 19:35:13 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | function setupMarks(viewer){ | 
					
						
							|  |  |  | 	console.log('Marks: setup...') | 
					
						
							| 
									
										
										
										
											2013-12-14 06:58:13 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// XXX make this viewer specific...
 | 
					
						
							|  |  |  | 	makeContextIndicatorUpdater('marked') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XXX make these viewer specific...
 | 
					
						
							|  |  |  | 	showGlobalIndicator( | 
					
						
							|  |  |  | 			'marks-visible',  | 
					
						
							|  |  |  | 			'Marks visible (F2)') | 
					
						
							| 
									
										
										
										
											2013-12-30 03:15:09 +04:00
										 |  |  | 		.click(function(){ toggleMarksView() }) | 
					
						
							| 
									
										
										
										
											2013-12-14 06:58:13 +04:00
										 |  |  | 	showGlobalIndicator( | 
					
						
							|  |  |  | 			'marked-only-visible',  | 
					
						
							|  |  |  | 			'Marked only images visible (shift-F2)') | 
					
						
							|  |  |  | 		.click(function(){ toggleMarkedOnlyView() }) | 
					
						
							|  |  |  | 	showContextIndicator( | 
					
						
							|  |  |  | 			'current-image-marked',  | 
					
						
							| 
									
										
										
										
											2013-12-15 02:55:05 +04:00
										 |  |  | 			'Marked (Ins)') | 
					
						
							| 
									
										
										
										
											2013-12-14 06:58:13 +04:00
										 |  |  | 		.click(function(){ toggleMark() }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-12 19:35:13 +04:00
										 |  |  | 	return viewer | 
					
						
							| 
									
										
										
										
											2014-01-13 11:21:49 +04:00
										 |  |  | 		.on('sortedImages', function(){ | 
					
						
							| 
									
										
										
										
											2014-03-06 05:49:14 +04:00
										 |  |  | 			MARKED = populateSparseGIDList(MARKED) | 
					
						
							| 
									
										
										
										
											2014-01-13 11:21:49 +04:00
										 |  |  | 			marksUpdated() | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2014-01-28 06:56:26 +04:00
										 |  |  | 		.on('horizontalShiftedImage', function(evt, gid, direction, from, to){ | 
					
						
							|  |  |  | 			if(shiftGIDInSparseList(gid, from, to, MARKED)){ | 
					
						
							| 
									
										
										
										
											2014-01-15 06:19:21 +04:00
										 |  |  | 				marksUpdated() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2014-02-05 02:51:43 +04:00
										 |  |  | 		// when the gid is swapped update the cache...
 | 
					
						
							| 
									
										
										
										
											2014-02-03 07:37:42 +04:00
										 |  |  | 		.on('updatedImageGID', function(evt, was, is){ | 
					
						
							|  |  |  | 			var i = MARKED.indexOf(was) | 
					
						
							|  |  |  | 			if(i >= 0){ | 
					
						
							|  |  |  | 				MARKED[i] = is | 
					
						
							|  |  |  | 				marksUpdated() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							| 
									
										
										
										
											2013-12-12 19:35:13 +04:00
										 |  |  | } | 
					
						
							|  |  |  | SETUP_BINDINGS.push(setupMarks) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ |