| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //var DEBUG = DEBUG != null ? DEBUG : true
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | * helpers... | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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...
 | 
					
						
							|  |  |  | function loadMarkedOnlyData(cmp, no_cleanout_marks){ | 
					
						
							| 
									
										
										
										
											2013-06-02 01:55:12 +04:00
										 |  |  | 	cmp = cmp == null ? imageOrderCmp : cmp | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	var cur = DATA.current | 
					
						
							|  |  |  | 	var marked = MARKED.slice().sort(cmp) | 
					
						
							| 
									
										
										
										
											2013-05-24 19:35:03 +04:00
										 |  |  | 	// this will ignore any gid in marks that is not in IMAGES...
 | 
					
						
							|  |  |  | 	// NOTE: if IMAGES contains only part of the data loadable this will 
 | 
					
						
							|  |  |  | 	// 		be wrong...
 | 
					
						
							|  |  |  | 	if(!no_cleanout_marks){ | 
					
						
							| 
									
										
										
										
											2013-05-25 14:24:29 +04:00
										 |  |  | 		for(var i=0; i < marked.length;){ | 
					
						
							|  |  |  | 			if(marked[i] in IMAGES){ | 
					
						
							| 
									
										
										
										
											2013-05-24 19:35:03 +04:00
										 |  |  | 				i++ | 
					
						
							|  |  |  | 				continue | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			// NOTE: we do not need to advance i here...
 | 
					
						
							| 
									
										
										
										
											2013-05-25 14:24:29 +04:00
										 |  |  | 			marked.splice(i, 1) | 
					
						
							| 
									
										
										
										
											2013-05-24 19:35:03 +04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	ALL_DATA = DATA | 
					
						
							|  |  |  | 	DATA = { | 
					
						
							|  |  |  | 		varsion: '2.0', | 
					
						
							|  |  |  | 		current: null, | 
					
						
							|  |  |  | 		ribbons: [ | 
					
						
							|  |  |  | 			marked | 
					
						
							|  |  |  | 		], | 
					
						
							|  |  |  | 		//order: marked.slice(),
 | 
					
						
							|  |  |  | 		order: DATA.order, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	DATA.current = getGIDBefore(cur, 0) | 
					
						
							| 
									
										
										
										
											2013-06-02 20:14:39 +04:00
										 |  |  | 	reloadViewer() | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	toggleMarkesView('off') | 
					
						
							|  |  |  | 	return DATA | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX name this in a better way...
 | 
					
						
							|  |  |  | function loadAllImages(){ | 
					
						
							| 
									
										
										
										
											2013-06-03 04:09:32 +04:00
										 |  |  | 	var cur = DATA.current | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	DATA = ALL_DATA | 
					
						
							| 
									
										
										
										
											2013-06-03 04:09:32 +04:00
										 |  |  | 	// NOTE: if we do not do this the user will lose context every time
 | 
					
						
							|  |  |  | 	// 		returning from marks only view...
 | 
					
						
							|  |  |  | 	DATA.current = cur | 
					
						
							| 
									
										
										
										
											2013-06-02 20:14:39 +04:00
										 |  |  | 	reloadViewer() | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	return DATA | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * Modes | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-03 21:10:42 +04:00
										 |  |  | var toggleMarkedOnlyView = createCSSClassToggler( | 
					
						
							|  |  |  | 		'.viewer',  | 
					
						
							| 
									
										
										
										
											2013-05-18 01:16:56 +04:00
										 |  |  | 		'marked-only-view', | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 		function(action){ | 
					
						
							|  |  |  | 			if(action == 'on'){ | 
					
						
							|  |  |  | 				loadMarkedOnlyData() | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				loadAllImages() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX shifting images and unmarking in this mode do not work correctly...
 | 
					
						
							| 
									
										
										
										
											2013-06-03 21:10:42 +04:00
										 |  |  | var toggleMarkesView = createCSSClassToggler( | 
					
						
							|  |  |  | 	'.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-06-03 21:10:42 +04:00
										 |  |  | var toggleImageMark = createCSSClassToggler( | 
					
						
							|  |  |  | 	'.current.image',  | 
					
						
							|  |  |  | 	'marked', | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	function(action){ | 
					
						
							|  |  |  | 		toggleMarkesView('on') | 
					
						
							| 
									
										
										
										
											2013-05-28 21:59:38 +04:00
										 |  |  | 		$('.viewer').trigger('togglingMark', [getImage(), action]) | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // mode can be:
 | 
					
						
							|  |  |  | //	- 'ribbon'
 | 
					
						
							|  |  |  | //	- 'all'
 | 
					
						
							|  |  |  | function removeImageMarks(mode){ | 
					
						
							|  |  |  | 	// remove marks from current ribbon (default)...
 | 
					
						
							|  |  |  | 	if(mode == 'ribbon' || mode == null){ | 
					
						
							|  |  |  | 		var ribbon = getRibbon() | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 		var res = ribbon | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 			.find('.marked') | 
					
						
							|  |  |  | 				.removeClass('marked') | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 		$('.viewer').trigger('removeingRibbonMarks', [ribbon]) | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// remove all marks...
 | 
					
						
							|  |  |  | 	} else if(mode == 'all'){ | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 		var res = $('.marked') | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 			.removeClass('marked') | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 		$('.viewer').trigger('removeingAllMarks') | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	}  | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 	return res | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function markAll(mode){ | 
					
						
							|  |  |  | 	// remove marks from current ribbon (default)...
 | 
					
						
							|  |  |  | 	if(mode == 'ribbon' || mode == null){ | 
					
						
							|  |  |  | 		var ribbon = getRibbon() | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 		var res = ribbon | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 			.find('.image:not(.marked)') | 
					
						
							|  |  |  | 				.addClass('marked') | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 		$('.viewer').trigger('markingRibbon', [ribbon]) | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} else if(mode == 'all'){ | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 		var res = $('.image:not(.marked)').addClass('marked') | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 		$('.viewer').trigger('markingAll') | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 	return res | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NOTE: this only does it's work in the current ribbon...
 | 
					
						
							|  |  |  | function invertImageMarks(){ | 
					
						
							|  |  |  | 	var ribbon = getRibbon() | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 	var res = ribbon | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 		.find('.image') | 
					
						
							|  |  |  | 			.toggleClass('marked') | 
					
						
							| 
									
										
										
										
											2013-05-31 20:10:23 +04:00
										 |  |  | 	$('.viewer').trigger('invertingMarks', [ribbon]) | 
					
						
							|  |  |  | 	return res | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Toggle marks in the current continuous section of marked or unmarked
 | 
					
						
							|  |  |  | // images...
 | 
					
						
							|  |  |  | // XXX need to make this dynamic data compatible...
 | 
					
						
							|  |  |  | function toggleImageMarkBlock(image){ | 
					
						
							|  |  |  | 	if(image == null){ | 
					
						
							| 
									
										
										
										
											2013-05-28 21:59:38 +04:00
										 |  |  | 		image = getImage() | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	//$('.viewer').trigger('togglingImageBlockMarks', [image])
 | 
					
						
							|  |  |  | 	// we need to invert this...
 | 
					
						
							|  |  |  | 	var state = toggleImageMark() | 
					
						
							|  |  |  | 	var _convert = function(){ | 
					
						
							|  |  |  | 		if(toggleImageMark(this, '?') == state){ | 
					
						
							|  |  |  | 			return false | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		toggleImageMark(this, state) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	image.nextAll('.image').each(_convert) | 
					
						
							|  |  |  | 	image.prevAll('.image').each(_convert) | 
					
						
							|  |  |  | 	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() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// ribbon only...
 | 
					
						
							|  |  |  | 	if(mode == 'ribbon'){ | 
					
						
							|  |  |  | 		var ribbon = DATA.ribbons[cur] | 
					
						
							|  |  |  | 		// remove all the marked images form current ribbon...
 | 
					
						
							|  |  |  | 		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() | 
					
						
							|  |  |  | 		// remove all the marked images form all the ribbons...
 | 
					
						
							|  |  |  | 		$.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 | 
					
						
							|  |  |  | 		DATA.ribbons[cur] = DATA.ribbons[cur].concat(marked).sort(cmp) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// remove empty ribbons...
 | 
					
						
							|  |  |  | 	DATA.ribbons = DATA.ribbons.filter(function(e){ return e.length > 0 ? true : false }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updateRibbonOrder() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function shiftMarkedImagesUp(mode, new_ribbon){ | 
					
						
							|  |  |  | 	return shiftMarkedImages('prev', mode, new_ribbon) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function shiftMarkedImagesDown(mode, new_ribbon){ | 
					
						
							|  |  |  | 	return shiftMarkedImages('next', mode, new_ribbon) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // 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(){ | 
					
						
							|  |  |  | 	return shiftMarkedImages('prev') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | function shiftMarkedImagesRight(){ | 
					
						
							|  |  |  | 	return shiftMarkedImages('next') | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-17 06:57:35 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                                                */ |