| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | **********************************************************************/ | 
					
						
							| 
									
										
										
										
											2016-08-21 02:19:24 +03:00
										 |  |  | ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) | 
					
						
							|  |  |  | (function(require){ var module={} // make module AMD/node compatible...
 | 
					
						
							| 
									
										
										
										
											2016-08-20 22:49:36 +03:00
										 |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-31 10:37:21 +03:00
										 |  |  | var toggler = require('lib/toggler') | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | var actions = require('lib/actions') | 
					
						
							|  |  |  | var features = require('lib/features') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-01 16:12:10 +03:00
										 |  |  | var data = require('imagegrid/data') | 
					
						
							|  |  |  | var images = require('imagegrid/images') | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | var core = require('features/core') | 
					
						
							|  |  |  | var base = require('features/base') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX should we rename this to "select"???
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // target can be:
 | 
					
						
							|  |  |  | // 		'all'
 | 
					
						
							|  |  |  | // 		'loaded'
 | 
					
						
							|  |  |  | // 		'ribbon'	- current ribbon
 | 
					
						
							|  |  |  | // 		ribbon		- specific ribbon (gid)
 | 
					
						
							|  |  |  | // 		Array
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2016-04-02 16:28:53 +03:00
										 |  |  | // NOTE: of no data is defined this will not have any effect...
 | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | // NOTE: we are not using the vanilla toggler here as it can't handle 
 | 
					
						
							|  |  |  | // 		toggling independently multiple elements...
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | function makeTagTogglerAction(tag){ | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 	// get actual target gids...
 | 
					
						
							|  |  |  | 	var _getTarget = function(target){ | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		target = target || 'current' | 
					
						
							|  |  |  | 		target = target == 'all'  | 
					
						
							|  |  |  | 				|| target == 'loaded'  | 
					
						
							|  |  |  | 				|| target in this.data.ribbons  | 
					
						
							|  |  |  | 					? this.data.getImages(target) | 
					
						
							|  |  |  | 			: target == 'ribbon' ? this.data.getImages('current') | 
					
						
							|  |  |  | 			: target | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 		return target.constructor !== Array ? [target] : target | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 	// the toggler...
 | 
					
						
							|  |  |  | 	var _tagToggler = toggler.Toggler('current', | 
					
						
							|  |  |  | 		function(target, action){ | 
					
						
							|  |  |  | 			target = _getTarget.call(this, target) | 
					
						
							|  |  |  | 			// get state...
 | 
					
						
							|  |  |  | 			if(action == null){ | 
					
						
							|  |  |  | 				var res = this.data.toggleTag(tag, target, '?') | 
					
						
							|  |  |  | 				return res.length == 1 ? res[0] : res | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 			} else if(action == 'on'){ | 
					
						
							|  |  |  | 				this.tag(tag, target) | 
					
						
							|  |  |  | 			} else if(action == 'off'){ | 
					
						
							|  |  |  | 				this.untag(tag, target) | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		},  | 
					
						
							|  |  |  | 		['off', 'on']) | 
					
						
							| 
									
										
										
										
											2016-04-22 19:26:22 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 	// the action...
 | 
					
						
							|  |  |  | 	var action = function(target, action){ | 
					
						
							|  |  |  | 		// special case: no data...
 | 
					
						
							|  |  |  | 		if(this.data == null){ | 
					
						
							|  |  |  | 			return action == '??' ? ['off', 'on'] : 'off' | 
					
						
							| 
									
										
										
										
											2016-04-22 19:26:22 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 		// special case: multiple targets and toggle action...
 | 
					
						
							|  |  |  | 		} else if((target == 'all' || target == 'loaded' || target == 'ribbon'  | 
					
						
							|  |  |  | 					|| target instanceof Array)  | 
					
						
							|  |  |  | 				&& (action == null || action == 'next' || action == 'prev'  | 
					
						
							|  |  |  | 					|| action == '!')){ | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 			var res = [] | 
					
						
							|  |  |  | 			var that = this | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 			target = _getTarget.call(this, target) | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 			target.forEach(function(t){ | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 				if((that.data.getTags(t).indexOf(tag) < 0)  | 
					
						
							|  |  |  | 						// invert check if action is '!'...
 | 
					
						
							|  |  |  | 						+ (action == '!' ? -1 : 0)){ | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 					that.tag(tag, t) | 
					
						
							|  |  |  | 					res.push('on') | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 				} else { | 
					
						
							|  |  |  | 					that.untag(tag, t) | 
					
						
							|  |  |  | 					res.push('off') | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 			return res.length == 1 ? res[0] : res | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 		// normal case...
 | 
					
						
							|  |  |  | 		return _tagToggler.call(this, target, action) | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// cheating a bit...
 | 
					
						
							| 
									
										
										
										
											2016-11-28 17:56:14 +03:00
										 |  |  | 	action.__proto__ = toggler.Toggler.prototype | 
					
						
							|  |  |  | 	action.constructor = toggler.Toggler | 
					
						
							|  |  |  | 	return action | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX .toggleMarkBlock(..) not done yet...
 | 
					
						
							|  |  |  | var ImageMarkActions = actions.Actions({ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// a shorthand...
 | 
					
						
							|  |  |  | 	// NOTE: this will return a copy...
 | 
					
						
							|  |  |  | 	get marked(){ | 
					
						
							|  |  |  | 		if(this.data == null  | 
					
						
							|  |  |  | 				|| this.data.tags == null | 
					
						
							|  |  |  | 				|| !('selected' in this.data.tags)){ | 
					
						
							|  |  |  | 			return [] | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return this.data.tags['selected'].slice() | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Common use-cases:
 | 
					
						
							|  |  |  | 	// 	Toggle mark on current image
 | 
					
						
							|  |  |  | 	// 	.toggleMark()
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Mark current ribbon
 | 
					
						
							|  |  |  | 	// 	.toggleMark('ribbon', 'on')
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Unmark all loaded images
 | 
					
						
							|  |  |  | 	// 	.toggleMark('loaded', 'off')
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							|  |  |  | 	// 	Invert marks on current ribbon
 | 
					
						
							|  |  |  | 	// 	.toggleMark('ribbon')
 | 
					
						
							|  |  |  | 	//
 | 
					
						
							| 
									
										
										
										
											2016-01-08 04:25:54 +03:00
										 |  |  | 	toggleMark: ['Mark|Image/Toggle image mark', | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		makeTagTogglerAction('selected')], | 
					
						
							|  |  |  | 	// XXX
 | 
					
						
							|  |  |  | 	toggleMarkBlock: ['Mark/Toggle block marks', | 
					
						
							|  |  |  | 		'A block is a set of adjacent images either marked on unmarked ' | 
					
						
							|  |  |  | 			+'in the same way', | 
					
						
							|  |  |  | 		function(target){ | 
					
						
							|  |  |  | 			var cur = this.toggleMark(target, '?') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// get all the next/prev gids until we get a state other than cur...
 | 
					
						
							|  |  |  | 			// XXX
 | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	markTagged: ['- Mark/Mark images by tags', | 
					
						
							|  |  |  | 		function(tags, mode){ | 
					
						
							|  |  |  | 			var selector = mode == 'any' ? 'getTaggedByAny' : 'getTaggedByAll' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var that = this | 
					
						
							|  |  |  | 			this.data[selector](tags).forEach(function(gid){ | 
					
						
							|  |  |  | 				that.toggleMark(gid, 'on') | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XXX do we need first/last marked???
 | 
					
						
							|  |  |  | 	prevMarked: ['Mark|Navigate/Previous marked image', | 
					
						
							|  |  |  | 		function(mode){ this.prevTagged('selected', mode) }], | 
					
						
							|  |  |  | 	nextMarked: ['Mark|Navigate/Next marked image', | 
					
						
							|  |  |  | 		function(mode){ this.nextTagged('selected', mode) }], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cropMarked: ['Mark|Crop/Crop marked images', | 
					
						
							|  |  |  | 		function(flatten){ this.cropTagged('selected', 'any', flatten) }], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NOTE: this is usable without ribbons...
 | 
					
						
							|  |  |  | var ImageMarks =  | 
					
						
							|  |  |  | module.ImageMarks = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'image-marks', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	depends: ['base'], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	actions: ImageMarkActions, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	handlers: [ | 
					
						
							|  |  |  | 		// XXX is this the right way to go???
 | 
					
						
							|  |  |  | 		['updateImage', function(_, gid, img){ | 
					
						
							|  |  |  | 			// update only when ribbons are preset... 
 | 
					
						
							|  |  |  | 			if(this.ribbons != null){ | 
					
						
							|  |  |  | 				if(this.toggleMark(gid, '?') == 'on'){ | 
					
						
							|  |  |  | 					this.ribbons.toggleImageMark(gid, 'selected', 'on') | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					this.ribbons.toggleImageMark(gid, 'selected', 'off') | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var ImageBookmarkActions = actions.Actions({ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// a shorthand...
 | 
					
						
							|  |  |  | 	// NOTE: this will return a copy...
 | 
					
						
							|  |  |  | 	get bookmarked(){ | 
					
						
							|  |  |  | 		if(this.data == null  | 
					
						
							|  |  |  | 				|| this.data.tags == null | 
					
						
							|  |  |  | 				|| !('bookmark' in this.data.tags)){ | 
					
						
							|  |  |  | 			return [] | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return this.data.tags['bookmark'].slice() | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-08 04:25:54 +03:00
										 |  |  | 	toggleBookmark: ['Bookmark|Image/Toggle image bookmark', | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | 		makeTagTogglerAction('bookmark')], | 
					
						
							|  |  |  | 	// action can be:
 | 
					
						
							|  |  |  | 	// 	'on'	- toggle all on
 | 
					
						
							|  |  |  | 	// 	'off'	- toggle all off
 | 
					
						
							|  |  |  | 	// 	'next'	- toggle each image to next state
 | 
					
						
							|  |  |  | 	toggleBookmarkOnMarked: ['Bookmark|Mark/Toggle bookmark on maked images', | 
					
						
							|  |  |  | 		function(action){  | 
					
						
							|  |  |  | 			return this.toggleBookmark(this.data.getTaggedByAny('selected'), action)  | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	prevBookmarked: ['Bookmark|Navigate/Previous bookmarked image', | 
					
						
							|  |  |  | 		function(mode){ this.prevTagged('bookmark', mode) }], | 
					
						
							|  |  |  | 	nextBookmarked: ['Bookmark|Navigate/Next bookmarked image', | 
					
						
							|  |  |  | 		function(mode){ this.nextTagged('bookmark', mode) }], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cropBookmarked: ['Bookmark|Crop/Crop bookmarked images', | 
					
						
							|  |  |  | 		function(flatten){ this.cropTagged('bookmark', 'any', flatten) }], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NOTE: this is usable without ribbons...
 | 
					
						
							|  |  |  | var ImageBookmarks =  | 
					
						
							|  |  |  | module.ImageBookmarks = core.ImageGridFeatures.Feature({ | 
					
						
							|  |  |  | 	title: '', | 
					
						
							|  |  |  | 	doc: '', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tag: 'image-bookmarks', | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	depends: ['base'], | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	actions: ImageBookmarkActions, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	handlers: [ | 
					
						
							|  |  |  | 		// XXX is this the right way to go???
 | 
					
						
							|  |  |  | 		['updateImage', function(_, gid, img){ | 
					
						
							|  |  |  | 			// update only when ribbons are preset... 
 | 
					
						
							|  |  |  | 			if(this.ribbons != null){ | 
					
						
							|  |  |  | 				if(this.toggleBookmark(gid, '?') == 'on'){ | 
					
						
							|  |  |  | 					this.ribbons.toggleImageMark(gid, 'bookmark', 'on') | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					this.ribbons.toggleImageMark(gid, 'bookmark', 'off') | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}], | 
					
						
							|  |  |  | 	], | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-02 19:30:48 +03:00
										 |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | core.ImageGridFeatures.Feature('marks', [ | 
					
						
							|  |  |  | 	'image-marks', | 
					
						
							|  |  |  | 	'image-bookmarks', | 
					
						
							|  |  |  | ]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 03:34:20 +03:00
										 |  |  | /********************************************************************** | 
					
						
							| 
									
										
										
										
											2016-08-20 22:49:36 +03:00
										 |  |  | * vim:set ts=4 sw=4 :                               */ return module }) |