| 
									
										
										
										
											2012-08-14 23:40:26 +04:00
										 |  |  | /******************************************* Actions (EXPERIMENTAL) **/ | 
					
						
							|  |  |  | // XXX this set of features is experimental...
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | // this gives us:
 | 
					
						
							|  |  |  | // 	- namespace cleanup
 | 
					
						
							|  |  |  | // 	- auto-generated help
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2012-08-14 23:40:26 +04:00
										 |  |  | // the main questions are:
 | 
					
						
							|  |  |  | // 	- is this overcomplicating things?
 | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | // 	- are the benefits worth the code bloat?
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2012-08-14 23:40:26 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | var ImageGrid = { | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	// this can be serialized...
 | 
					
						
							|  |  |  | 	// NOTE: to load a serialized set of options use ImageGrid.set(options)...
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	actions: {}, | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	option: {}, | 
					
						
							|  |  |  | 	option_props: {}, | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	option_groups: [], | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// define an action...
 | 
					
						
							|  |  |  | 	// the two values that are obligatory are:
 | 
					
						
							| 
									
										
										
										
											2012-08-15 03:03:00 +04:00
										 |  |  | 	// 		title	- name of the action
 | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	// 		call	- callable
 | 
					
						
							|  |  |  | 	// XXX revise...
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	ACTION: function(obj, func){ | 
					
						
							|  |  |  | 		if(func != null){ | 
					
						
							|  |  |  | 			obj = $.extend(obj, { | 
					
						
							|  |  |  | 				id: func.name != '' ? func.name : obj.id, | 
					
						
							|  |  |  | 				call: func  | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 		// add all the attrs to the function...
 | 
					
						
							| 
									
										
										
										
											2012-08-15 03:30:35 +04:00
										 |  |  | 		if(this._type_handler[obj.type] != null){ | 
					
						
							|  |  |  | 			this._type_handler[obj.type](obj) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		var call = obj.call | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 		for(i in obj){ | 
					
						
							|  |  |  | 			if(i == 'doc' && call.doc != null){ | 
					
						
							|  |  |  | 				call.func_doc = call.doc  | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			call[i] = obj[i] | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | 		this[obj.id] = call | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 		this.actions[obj.id] = call | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 		return call | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	// shorthand: each argument is an action, the group of each will be set the same...
 | 
					
						
							|  |  |  | 	GROUP: function(group){ | 
					
						
							|  |  |  | 		for(var i=1; i<arguments.length; i++){ | 
					
						
							|  |  |  | 			var obj = arguments[i] | 
					
						
							|  |  |  | 			obj.group = group | 
					
						
							|  |  |  | 			// if we have an option for this prop then fix it's group too...
 | 
					
						
							|  |  |  | 			if(this.option_props[obj.id] != null){ | 
					
						
							|  |  |  | 				this.option_props[obj.id].group = group | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(this.option_groups.indexOf(obj.group) < 0 && obj.group != null){ | 
					
						
							|  |  |  | 				this.option_groups.push(obj.group) | 
					
						
							|  |  |  | 				this.option_groups.sort() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	// define an option...
 | 
					
						
							|  |  |  | 	OPTION: function(obj){ | 
					
						
							|  |  |  | 		this.option[obj.name] = obj.value | 
					
						
							|  |  |  | 		this.option_props[obj.name] = obj | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | 		if(this.option_groups.indexOf(obj.group) < 0 && obj.group != null){ | 
					
						
							|  |  |  | 			this.option_groups.push(obj.group) | 
					
						
							|  |  |  | 			this.option_groups.sort() | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 		return obj | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2012-08-15 03:30:35 +04:00
										 |  |  | 	TYPE: function(name, handler){ | 
					
						
							|  |  |  | 		this._type_handler[name] = handler | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2012-08-15 03:02:27 +04:00
										 |  |  | 	_type_handler: { | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | // system actions and handlers...
 | 
					
						
							|  |  |  | ImageGrid.GROUP('API', | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			doc: 'Set option(s) value(s), calling apropriate callbacks.', | 
					
						
							|  |  |  | 			group: 'API' | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function set(obj){ | 
					
						
							|  |  |  | 			for(var n in obj){ | 
					
						
							|  |  |  | 				this.option[n] = obj[n] | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 			// NOTE: this is separate so as to exclude the posibility of race 
 | 
					
						
							|  |  |  | 			// 		 conditions...
 | 
					
						
							|  |  |  | 			// 		 ...thogh there is still a posibility of conflicting 
 | 
					
						
							|  |  |  | 			// 		 modes, especially if one mode sets more modes...
 | 
					
						
							|  |  |  | 			for(var n in obj){ | 
					
						
							|  |  |  | 				// call the callback if it exists...
 | 
					
						
							|  |  |  | 				if(this.option_props[n].callback != null){ | 
					
						
							|  |  |  | 					this.option_props[n].callback() | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			doc: 'Get documentation for name.', | 
					
						
							|  |  |  | 			group: 'API' | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function doc(name){ | 
					
						
							|  |  |  | 			return { | 
					
						
							|  |  |  | 				action: this[name] != null ? this[name].doc : null, | 
					
						
							|  |  |  | 				action_func: this[name] != null ? this[name].func_doc : null, | 
					
						
							|  |  |  | 				option: this.option_props[name] != null ? this.option_props[name].doc : null, | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		})) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-15 03:30:35 +04:00
										 |  |  | ImageGrid.TYPE('toggle', function(obj){ | 
					
						
							|  |  |  | 	var call = obj.call | 
					
						
							|  |  |  | 	// wrap the call to set the option...
 | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | 	// XXX this is context mirroring...
 | 
					
						
							| 
									
										
										
										
											2012-08-15 03:30:35 +04:00
										 |  |  | 	obj.call = function(action){ | 
					
						
							|  |  |  | 		var res = call(action) | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | 		ImageGrid.option[obj.id] = call('?') | 
					
						
							| 
									
										
										
										
											2012-08-15 03:30:35 +04:00
										 |  |  | 		return res | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// add an option to store the state...
 | 
					
						
							|  |  |  | 	ImageGrid.OPTION({ | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | 		name: obj.id, | 
					
						
							|  |  |  | 		title: obj.title, | 
					
						
							|  |  |  | 		group: obj.group, | 
					
						
							|  |  |  | 		display: obj.display, | 
					
						
							|  |  |  | 		doc: obj.doc == null ? 'Stores the state of '+obj.id+' action.' : obj.doc, | 
					
						
							| 
									
										
										
										
											2012-08-15 03:30:35 +04:00
										 |  |  | 		value: obj.call('?'), | 
					
						
							|  |  |  | 		callback: function(){ | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | 			obj.call() | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		click_handler: function(){ | 
					
						
							|  |  |  | 			obj.call() | 
					
						
							| 
									
										
										
										
											2012-08-15 03:30:35 +04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2012-08-14 23:40:26 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-17 22:23:48 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | // XXX don't understand why am I the one who has to write this...
 | 
					
						
							|  |  |  | var SPECIAL_KEYS = { | 
					
						
							|  |  |  | 	9:		'Tab', | 
					
						
							|  |  |  | 	13:		'Enter', | 
					
						
							|  |  |  | 	16:		'Shift', | 
					
						
							|  |  |  | 	17:		'Ctrl', | 
					
						
							|  |  |  | 	18:		'Alt', | 
					
						
							|  |  |  | 	20:		'Caps Lock', | 
					
						
							|  |  |  | 	27:		'Esc', | 
					
						
							|  |  |  | 	32:		'Space', | 
					
						
							|  |  |  | 	33:		'PgUp', | 
					
						
							|  |  |  | 	34:		'PgDown',	 | 
					
						
							|  |  |  | 	35:		'End', | 
					
						
							|  |  |  | 	36:		'Home', | 
					
						
							|  |  |  | 	37:		'Right', | 
					
						
							|  |  |  | 	38:		'Up', | 
					
						
							|  |  |  | 	39:		'Left', | 
					
						
							|  |  |  | 	40:		'Down', | 
					
						
							|  |  |  | 	45:		'Ins', | 
					
						
							|  |  |  | 	46:		'Del', | 
					
						
							|  |  |  | 	80:		'Backspace', | 
					
						
							|  |  |  | 	91:		'Win', | 
					
						
							|  |  |  | 	93:		'Menu', | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	112:	'F1', | 
					
						
							|  |  |  | 	113:	'F2', | 
					
						
							|  |  |  | 	114:	'F3', | 
					
						
							|  |  |  | 	115:	'F4', | 
					
						
							|  |  |  | 	116:	'F5', | 
					
						
							|  |  |  | 	117:	'F6', | 
					
						
							|  |  |  | 	118:	'F7', | 
					
						
							|  |  |  | 	119:	'F8', | 
					
						
							|  |  |  | 	120:	'F9', | 
					
						
							|  |  |  | 	121:	'F10', | 
					
						
							|  |  |  | 	122:	'F11', | 
					
						
							|  |  |  | 	123:	'F12', | 
					
						
							| 
									
										
										
										
											2012-08-17 06:56:54 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | function toKeyName(code){ | 
					
						
							|  |  |  | 	// check for special keys...
 | 
					
						
							|  |  |  | 	var k = SPECIAL_KEYS[code] | 
					
						
							|  |  |  | 	if(k != null){ | 
					
						
							|  |  |  | 		return k | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// chars...
 | 
					
						
							|  |  |  | 	k = String.fromCharCode(code) | 
					
						
							|  |  |  | 	if(k != ''){ | 
					
						
							|  |  |  | 		return k.toLowerCase() | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return null | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-08-17 06:56:54 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | function showKeyboardBindings(){ | 
					
						
							|  |  |  | 	// XXX get all the actions...
 | 
					
						
							|  |  |  | 	// XXX get all the keys bound...
 | 
					
						
							|  |  |  | 	// XXX connect the two together, including:
 | 
					
						
							|  |  |  | 	// 		- unbound actions
 | 
					
						
							|  |  |  | 	// 		- undocumented keys
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// build an action indexed dict (effectively reverse keybindings)...
 | 
					
						
							|  |  |  | 	var res = {} | 
					
						
							|  |  |  | 	for(var k in keybindings){ | 
					
						
							|  |  |  | 		var n = [toKeyName(k)] | 
					
						
							|  |  |  | 		// get the action name...
 | 
					
						
							|  |  |  | 		// XXX need a name here...
 | 
					
						
							|  |  |  | 		var v = keybindings[k] | 
					
						
							|  |  |  | 		// alias...
 | 
					
						
							|  |  |  | 		while(typeof(v) == typeof(3)){ | 
					
						
							|  |  |  | 			// XXX skip for now...
 | 
					
						
							|  |  |  | 			// 		...later we will need to accumolate all the keys in a list...
 | 
					
						
							|  |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 		// function...
 | 
					
						
							|  |  |  | 		if(typeof(v) == typeof(function(){})){ | 
					
						
							|  |  |  | 			// XXX title...
 | 
					
						
							|  |  |  | 			// XXX name...
 | 
					
						
							|  |  |  | 			// XXX ???
 | 
					
						
							|  |  |  | 		// Array...
 | 
					
						
							|  |  |  | 		} else if(typeof(v) == typeof([]) && v.constructor.name == 'Array'){ | 
					
						
							|  |  |  | 			// XXX get the second arg...
 | 
					
						
							|  |  |  | 		// object...
 | 
					
						
							|  |  |  | 		} else if(typeof(v) == typeof({})){ | 
					
						
							|  |  |  | 			// XXX get all the handlers and accumolate the keys...
 | 
					
						
							|  |  |  | 		// XXX unknown...
 | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 			// XXX err...
 | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	var res = {} | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 23:40:26 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-15 14:26:23 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | /******************************************* Setup Data and Globals **/ | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | var DEBUG = true | 
					
						
							| 
									
										
										
										
											2012-08-17 06:33:01 +04:00
										 |  |  | //var DEBUG = false
 | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-17 07:30:03 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | ImageGrid.GROUP('State', | 
					
						
							|  |  |  | 	ImageGrid.OPTION({ | 
					
						
							|  |  |  | 			name: 'BACKGROUND_MODES', | 
					
						
							|  |  |  | 			doc: 'list of available background styles.\n'+ | 
					
						
							|  |  |  | 				'NOTE: there is also a null mode that is what is set in the '+ | 
					
						
							|  |  |  | 				'main CSS.', | 
					
						
							|  |  |  | 			display: false, | 
					
						
							|  |  |  | 			value: [ | 
					
						
							|  |  |  | 				'dark', | 
					
						
							|  |  |  | 				'black', | 
					
						
							|  |  |  | 				// this can be removed but when given it must be last.
 | 
					
						
							|  |  |  | 				null | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.OPTION({ | 
					
						
							|  |  |  | 			name: 'NORMAL_MODE_BG', | 
					
						
							|  |  |  | 			display: false, | 
					
						
							|  |  |  | 			value: null, | 
					
						
							|  |  |  | 			doc: 'Background style in normal (ribbon) mode.\n'+ | 
					
						
							|  |  |  | 				'NOTE: This will get updated on background change in tuntime.\n'+ | 
					
						
							|  |  |  | 				'NOTE: null represents the default style.', | 
					
						
							|  |  |  | 			callback: function(){ | 
					
						
							|  |  |  | 				if(ImageGrid.toggleSingleImageMode('?') == 'off'){ | 
					
						
							|  |  |  | 					setBackgroundMode(ImageGrid.option.NORMAL_MODE_BG) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.OPTION({ | 
					
						
							|  |  |  | 			name: 'SINGLE_IMAGE_MODE_BG', | 
					
						
							|  |  |  | 			display: false, | 
					
						
							|  |  |  | 			value: 'black', | 
					
						
							|  |  |  | 			doc: 'Background style in single image mode.\n'+ | 
					
						
							|  |  |  | 				'NOTE: This will get updated on background change in tuntime.\n'+ | 
					
						
							|  |  |  | 				'NOTE: null represents the default style.', | 
					
						
							|  |  |  | 			callback: function(){ | 
					
						
							|  |  |  | 				if(ImageGrid.toggleSingleImageMode('?') == 'on'){ | 
					
						
							|  |  |  | 					setBackgroundMode(ImageGrid.option.SINGLE_IMAGE_MODE_BG) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.OPTION({ | 
					
						
							|  |  |  | 			name: 'ORIGINAL_FIELD_SCALE', | 
					
						
							|  |  |  | 			display: false, | 
					
						
							|  |  |  | 			value: 1.0, | 
					
						
							|  |  |  | 			doc: 'Scale of view in image mode.\n'+ | 
					
						
							|  |  |  | 				'NOTE: this will change if changed at runtime.', | 
					
						
							|  |  |  | 			callback: function(){ | 
					
						
							|  |  |  | 				if(ImageGrid.toggleSingleImageMode('?') == 'off'){ | 
					
						
							|  |  |  | 					setContainerScale(ImageGrid.option.ORIGINAL_FIELD_SCALE) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		})) | 
					
						
							| 
									
										
										
										
											2012-08-05 21:03:37 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | ImageGrid.GROUP('Mode: All', | 
					
						
							|  |  |  | 	ImageGrid.OPTION({ | 
					
						
							|  |  |  | 			name: 'ZOOM_FACTOR', | 
					
						
							|  |  |  | 			title: 'Zooming factor', | 
					
						
							|  |  |  | 			value: 2, | 
					
						
							|  |  |  | 			doc: 'Sets the zoom factor used for a manual zooming step.' | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.OPTION({ | 
					
						
							|  |  |  | 			name: 'MOVE_DELTA', | 
					
						
							|  |  |  | 			title: 'Move step', | 
					
						
							|  |  |  | 			value: 50, | 
					
						
							|  |  |  | 			doc: 'Sets the move delta in pixels for keyboard view moving.' | 
					
						
							|  |  |  | 		})) | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 23:40:26 +04:00
										 |  |  | /************************************************ jQuery extensions **/ | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:26:46 +04:00
										 |  |  | jQuery.fn.reverseChildren = function(){ | 
					
						
							|  |  |  | 	return $(this).each(function(_, e){ | 
					
						
							|  |  |  | 		return $(e).append($(e).children().detach().get().reverse()) | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 23:40:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:26:46 +04:00
										 |  |  | jQuery.fn.sortChildren = function(func){ | 
					
						
							|  |  |  | 	return $(this).each(function(_, e){ | 
					
						
							|  |  |  | 		return $(e).append($(e).children().detach().get().sort(func)) | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 23:40:26 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | /********************************************************** Helpers **/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | function getImageOrder(img){ | 
					
						
							|  |  |  | 	// XXX HACK need to parseInt this because '13' is less than '2'... 
 | 
					
						
							|  |  |  | 	// 	   ...figure a way out of this!!!
 | 
					
						
							|  |  |  | 	return parseInt($(img).attr('id')) | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-08-14 18:08:45 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | function setImageOrder(img, order){ | 
					
						
							|  |  |  | 	return $(img).attr({'id': order}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:26:46 +04:00
										 |  |  | function cmpImageOrder(a, b){ | 
					
						
							|  |  |  | 	return getImageOrder(a) - getImageOrder(b) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | // show a jQuary opject in viewer overlay...
 | 
					
						
							|  |  |  | function showInOverlay(obj){ | 
					
						
							|  |  |  | 	// clean things up...
 | 
					
						
							|  |  |  | 	$('.overlay .content').children().remove() | 
					
						
							|  |  |  | 	// put it in the overlay...
 | 
					
						
							|  |  |  | 	$('.overlay .content').append(obj) | 
					
						
							|  |  |  | 	// prepare the overlay...
 | 
					
						
							|  |  |  | 	$('.overlay') | 
					
						
							|  |  |  | 		.one('click', function(){ | 
					
						
							|  |  |  | 			$('.overlay') | 
					
						
							|  |  |  | 				.fadeOut(function(){ | 
					
						
							|  |  |  | 					$('.overlay .content') | 
					
						
							|  |  |  | 						.children() | 
					
						
							|  |  |  | 							.remove() | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 		.fadeIn() | 
					
						
							|  |  |  | 	return obj | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | // this will create a function that will add/remove a css_class to elem 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | // calling the optional callbacks before and/or after.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // elem is a jquery compatible object; default use-case: a css selector.
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | // the resulting function understands the folowing arguments:
 | 
					
						
							|  |  |  | // 	- 'on'			: switch mode on
 | 
					
						
							|  |  |  | // 	- 'off'			: switch mode off
 | 
					
						
							|  |  |  | // 	- '?'			: return current state ('on'|'off')
 | 
					
						
							|  |  |  | // 	- no arguments	: toggle the state
 | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | //
 | 
					
						
							|  |  |  | // NOTE: of only one callback is given then it will be called after the 
 | 
					
						
							|  |  |  | // 		 class change...
 | 
					
						
							|  |  |  | // 		 a way around this is to pass an empty function as callback_b
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | function createCSSClassToggler(elem, css_class, callback_a, callback_b){ | 
					
						
							|  |  |  | 	// prepare the pre/post callbacks...
 | 
					
						
							|  |  |  | 	if(callback_b == null){ | 
					
						
							|  |  |  | 		var callback_pre = null | 
					
						
							|  |  |  | 		var callback_post = callback_a | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		var callback_pre = callback_a | 
					
						
							|  |  |  | 		var callback_post = callback_b | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-08 06:21:00 +04:00
										 |  |  | 	// build the acual toggler function...
 | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	var func = function(action){ | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | 		if(action == null || action == '?'){ | 
					
						
							|  |  |  | 			var getter = action == '?' ? true : false | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 			action = 'on' | 
					
						
							|  |  |  | 			// get current state...
 | 
					
						
							|  |  |  | 			if( $(elem).hasClass(css_class) ){ | 
					
						
							|  |  |  | 				action = 'off' | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | 			if(getter){ | 
					
						
							|  |  |  | 				// as the above actions indicate intent and not state, 
 | 
					
						
							|  |  |  | 				// we'll need to swap the values...
 | 
					
						
							|  |  |  | 				return action == 'on' ? 'off' : 'on' | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if(callback_pre != null){ | 
					
						
							|  |  |  | 			callback_pre(action) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// play with the class...
 | 
					
						
							| 
									
										
										
										
											2012-08-08 01:57:04 +04:00
										 |  |  | 		if(action == 'on'){ | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 			$(elem).addClass(css_class) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			$(elem).removeClass(css_class) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(callback_post != null){ | 
					
						
							|  |  |  | 			callback_post(action) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	func.doc = 'With no arguments this will toggle between "on" and '+ | 
					
						
							|  |  |  | 		'"off".\n'+ | 
					
						
							|  |  |  | 		'If either "on" or "off" are given then this will switch '+ | 
					
						
							|  |  |  | 		'to that mode.\n'+ | 
					
						
							|  |  |  | 		'If "?" is given, this will return either "on" or "off" '+ | 
					
						
							|  |  |  | 		'depending on the current state.' | 
					
						
							|  |  |  | 	return func | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // disable transitions on obj, call func then enable transitions back...
 | 
					
						
							|  |  |  | function doWithoutTransitions(obj, func){ | 
					
						
							|  |  |  | 	obj | 
					
						
							|  |  |  | 		.addClass('unanimated') | 
					
						
							|  |  |  | 		.one("webkitTransitionEnd oTransitionEnd msTransitionEnd transitionend", function(){ | 
					
						
							|  |  |  | 			func() | 
					
						
							|  |  |  | 			$('.viewer') | 
					
						
							|  |  |  | 				.one("webkitTransitionEnd oTransitionEnd msTransitionEnd transitionend", function(){ | 
					
						
							|  |  |  | 					obj.removeClass('unanimated') | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | function clickAfterTransitionsDone(img){ | 
					
						
							|  |  |  | 	if(img == null){ | 
					
						
							|  |  |  | 		img = $('.current.image') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	$('.viewer') | 
					
						
							|  |  |  | 		.one("webkitTransitionEnd oTransitionEnd msTransitionEnd transitionend", function(){ | 
					
						
							|  |  |  | 			img.click() | 
					
						
							|  |  |  | 			return true | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | // find an image object after which to position image ID...
 | 
					
						
							|  |  |  | // used for two main tasks:
 | 
					
						
							|  |  |  | // 	- positioning promoted/demoted images
 | 
					
						
							|  |  |  | // 	- centering ribbons
 | 
					
						
							|  |  |  | // returns:
 | 
					
						
							|  |  |  | // 	- null		- empty ribbon or no element greater id should be first
 | 
					
						
							|  |  |  | // 	- element
 | 
					
						
							|  |  |  | // XXX do we need to make ids numbers for this to work?
 | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | function getImageBefore_lin(id, ribbon, get_order){ | 
					
						
							|  |  |  | 	if(get_order == null){ | 
					
						
							|  |  |  | 		get_order = getImageOrder | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 	// walk the ribbon till we find two images one with an ID less and 
 | 
					
						
							|  |  |  | 	// another greater that id...
 | 
					
						
							|  |  |  | 	var images = ribbon.children('.image') | 
					
						
							|  |  |  | 	var prev = null | 
					
						
							|  |  |  | 	for(var i=0; i < images.length; i++){ | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | 		// XXX replace the id attr with a universal getter
 | 
					
						
							|  |  |  | 		if(get_order(images[i]) > id){ | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 			return prev | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		prev = $(images[i]) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return prev | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // generic binery search for element just before the id...
 | 
					
						
							|  |  |  | // NOTE: if id is in lst, this will return the element just before it.
 | 
					
						
							|  |  |  | // NOTE: lst must be sorted.
 | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | function binarySearch(id, lst, get_order){ | 
					
						
							|  |  |  | 	if(get_order == null){ | 
					
						
							|  |  |  | 		get_order = function(o){return o} | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// empty list...
 | 
					
						
							|  |  |  | 	if(lst.length == 0){ | 
					
						
							|  |  |  | 		return null | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	// current section length
 | 
					
						
							|  |  |  | 	var l = Math.round((lst.length-1)/2) | 
					
						
							|  |  |  | 	// current position...
 | 
					
						
							|  |  |  | 	var i = l | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while(true){ | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | 		var i_id = get_order(lst[i]) | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 		// beginning of the array...
 | 
					
						
							|  |  |  | 		if(i == 0){ | 
					
						
							|  |  |  | 			if(id > i_id){ | 
					
						
							|  |  |  | 				return i | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return null | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// we got a hit...
 | 
					
						
							|  |  |  | 		if(i_id == id){ | 
					
						
							|  |  |  | 			return i-1 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// we are at the end...
 | 
					
						
							|  |  |  | 		if(i == lst.length-1 && id > i_id){ | 
					
						
							|  |  |  | 			return i | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | 		var ii_id = get_order(lst[i+1]) | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 		// test if id is between i and i+1...
 | 
					
						
							|  |  |  | 		if( i_id < id && id < ii_id ){ | 
					
						
							|  |  |  | 			return i | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// prepare for next iteration...
 | 
					
						
							|  |  |  | 		// NOTE: we saturate the values so we will never get out of bounds.
 | 
					
						
							|  |  |  | 		l = Math.round(l/2) | 
					
						
							|  |  |  | 		if(id < i_id){ | 
					
						
							|  |  |  | 			// lower half...
 | 
					
						
							|  |  |  | 			i = Math.max(0, i-l) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			// upper half...
 | 
					
						
							|  |  |  | 			i = Math.min(i+l, lst.length-1) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // wrapper around binarySearch.
 | 
					
						
							|  |  |  | // this is here to make binarySearch simpler to test and debug...
 | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | function getImageBefore_bin(id, ribbon, get_order){ | 
					
						
							|  |  |  | 	if(get_order == null){ | 
					
						
							|  |  |  | 		get_order = getImageOrder | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 	var images = ribbon.children('.image')  | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | 	var i = binarySearch(id, images, get_order) | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 	if(i == null){ | 
					
						
							|  |  |  | 		return null | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return $(images[i]) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // set the default search...
 | 
					
						
							|  |  |  | var getImageBefore = getImageBefore_bin | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | /* | 
					
						
							|  |  |  |  * The folowing two functions will get the vertical and horizontal  | 
					
						
							|  |  |  |  * distance components between the points a and A, centers of the small | 
					
						
							|  |  |  |  * and large squares respectively. | 
					
						
							|  |  |  |  * One of the squares is .field and the other is .container,  | 
					
						
							|  |  |  |  * which is small or big is not important. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *      +---------------+-------+ | 
					
						
							|  |  |  |  *      |               |       | | 
					
						
							|  |  |  |  *      |               |       | | 
					
						
							|  |  |  |  *      |       + a . . | . . . | . + | 
					
						
							|  |  |  |  *      |       .       |       |   +- getCurrentVerticalOffset(...) | 
					
						
							|  |  |  |  *      |       .   + A | . . . | . + | 
					
						
							|  |  |  |  *      +---------------+       | | 
					
						
							|  |  |  |  *      |       .   .           | | 
					
						
							|  |  |  |  *      |       .   .           | | 
					
						
							|  |  |  |  *      |       .   .           | | 
					
						
							|  |  |  |  *      +-----------------------+ | 
					
						
							|  |  |  |  *              .   . | 
					
						
							|  |  |  |  *              +-+-+ | 
					
						
							|  |  |  |  *                +------------------- getCurrentHorizontalOffset(...) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Adding this distance to margins of one of the sqares will effectively  | 
					
						
							|  |  |  |  * allign the two points. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * NOTE: neither function accunts for field margins. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | // get the vertical offset of the center of square from center of container
 | 
					
						
							|  |  |  | // NOTE: this does not account for field margins
 | 
					
						
							|  |  |  | function getCurrentVerticalOffset(image){ | 
					
						
							|  |  |  | 	if(image == null){ | 
					
						
							|  |  |  | 		image = $('.image.current') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-06 16:24:20 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	var scale = getElementScale($('.field')) | 
					
						
							| 
									
										
										
										
											2012-08-06 16:24:20 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	var ribbons = $('.ribbon') | 
					
						
							|  |  |  | 	var ribbon = image.parents('.ribbon') | 
					
						
							|  |  |  | 	var images = ribbon.children('.image') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// vertical...
 | 
					
						
							|  |  |  | 	var H = $('.container').height() | 
					
						
							|  |  |  | 	var h = ribbons.outerHeight(true) | 
					
						
							|  |  |  | 	// margin...
 | 
					
						
							|  |  |  | 	var mh = h - ribbons.outerHeight() | 
					
						
							|  |  |  | 	// current ribbon position (1-based)
 | 
					
						
							|  |  |  | 	var rn = ribbons.index(ribbon) + 1 | 
					
						
							|  |  |  | 	// relative position to field... 
 | 
					
						
							|  |  |  | 	// XXX is there a better way to get this?
 | 
					
						
							|  |  |  | 	var t = rn * (h - mh/2) | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return -t + H/2 + h/2 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | // get the horizontal offset of the center of square from center of container
 | 
					
						
							|  |  |  | // NOTE: this does not account for field margins
 | 
					
						
							|  |  |  | function getCurrentHorizontalOffset(image){ | 
					
						
							|  |  |  | 	if(image == null){ | 
					
						
							|  |  |  | 		image = $('.image.current') | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	var ribbon = image.parents('.ribbon') | 
					
						
							|  |  |  | 	var images = ribbon.children('.image') | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	var W = $('.container').width() | 
					
						
							|  |  |  | 	var w = images.outerWidth(true) | 
					
						
							|  |  |  | 	// margin...
 | 
					
						
							|  |  |  | 	var mw = w - images.outerWidth() | 
					
						
							|  |  |  | 	// current square position (1-based)
 | 
					
						
							|  |  |  | 	var sn = images.index(image) + 1 | 
					
						
							|  |  |  | 	var l = sn * (w - mw/2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return -l + W/2 + w/2 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function centerSquare(){ | 
					
						
							|  |  |  | 	$('.field').css({ | 
					
						
							|  |  |  | 		'margin-top': getCurrentVerticalOffset() | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 	// horizontal...
 | 
					
						
							|  |  |  | 	alignRibbon() | 
					
						
							|  |  |  | 	ImageGrid.centerCurrentImage() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function alignRibbon(image, position){ | 
					
						
							|  |  |  | 	// default values...
 | 
					
						
							|  |  |  | 	if(image == null){ | 
					
						
							|  |  |  | 		image = $('.image.current') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if(position == null){ | 
					
						
							|  |  |  | 		position = 'center' | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var ribbon = image.parents('.ribbon') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// account for margined field...
 | 
					
						
							|  |  |  | 	// NOTE: this enables us to cheat and shift all the ribbons just
 | 
					
						
							|  |  |  | 	//       by changing field margin-left...
 | 
					
						
							|  |  |  | 	var cml = parseFloat($('.field').css('margin-left')) | 
					
						
							|  |  |  | 	if(!cml){ | 
					
						
							|  |  |  | 		cml = 0 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	var h_offset = getCurrentHorizontalOffset(image) - cml | 
					
						
							|  |  |  | 	var w = $('.image').outerWidth(true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch(position){ | 
					
						
							|  |  |  | 		case 'before': | 
					
						
							|  |  |  | 			ribbon.css({'margin-left': h_offset - w/2}) | 
					
						
							|  |  |  | 			return true | 
					
						
							|  |  |  | 		case 'center': | 
					
						
							|  |  |  | 			ribbon.css({'margin-left': h_offset}) | 
					
						
							|  |  |  | 			return true | 
					
						
							|  |  |  | 		case 'after': | 
					
						
							|  |  |  | 			ribbon.css({'margin-left': h_offset + w/2}) | 
					
						
							|  |  |  | 			return true | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // center other ribbons relative to current image...
 | 
					
						
							|  |  |  | // NOTE: only two ribbons are positioned at this point...
 | 
					
						
							|  |  |  | function alignRibbons(get_order){ | 
					
						
							|  |  |  | 	if(get_order == null){ | 
					
						
							|  |  |  | 		get_order = getImageOrder | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// XXX might be good to move this to a more generic location...
 | 
					
						
							|  |  |  | 	var id = get_order($('.current.image')) | 
					
						
							|  |  |  | 	var directions = ['prev', 'next'] | 
					
						
							|  |  |  | 	for(var i in directions){ | 
					
						
							|  |  |  | 		var ribbon = $('.current.ribbon')[directions[i]]('.ribbon') | 
					
						
							|  |  |  | 		if(ribbon.length == 1){ | 
					
						
							|  |  |  | 			var img = getImageBefore(id, ribbon) | 
					
						
							|  |  |  | 			if(img != null){ | 
					
						
							|  |  |  | 				alignRibbon(img, 'before') | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				// there are no images before...
 | 
					
						
							|  |  |  | 				alignRibbon(ribbon.children('.image').first(), 'after') | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /************************************************** Setup Functions **/ | 
					
						
							|  |  |  | // XXX is this a correct place for these?
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setDefaultInitialState(){ | 
					
						
							|  |  |  | 	if($('.current.ribbon').length == 0){ | 
					
						
							|  |  |  | 		$('.ribbon').first().addClass('current') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if($('.current.image').length == 0){ | 
					
						
							|  |  |  | 		$('.current.ribbon').children('.image').first().addClass('current') | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setupEvents(){ | 
					
						
							|  |  |  | 	// resize...
 | 
					
						
							|  |  |  | 	$(window).resize(function() { | 
					
						
							|  |  |  | 		// XXX HACK
 | 
					
						
							|  |  |  | 		$('.current.image').click() | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 	// keyboard...
 | 
					
						
							|  |  |  | 	if(DEBUG){ | 
					
						
							|  |  |  | 		$(document) | 
					
						
							|  |  |  | 			.keydown(makeKeyboardHandler(keybindings, function(k){alert(k)})) | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		$(document) | 
					
						
							|  |  |  | 			.keydown(makeKeyboardHandler(keybindings)) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// swipe...
 | 
					
						
							|  |  |  | 	$('.viewer') | 
					
						
							|  |  |  | 		.swipe({ | 
					
						
							|  |  |  | 			swipeLeft: ImageGrid.nextImage, | 
					
						
							|  |  |  | 			swipeRight: ImageGrid.prevImage, | 
					
						
							|  |  |  | 			swipeUp: shiftImageUp, | 
					
						
							|  |  |  | 			swipeDown: shiftImageDown | 
					
						
							|  |  |  | 		}) | 
					
						
							|  |  |  | 	// dragging...
 | 
					
						
							|  |  |  | 	// XXX make this work seamlessly with touchSwipe...
 | 
					
						
							|  |  |  | 	// XXX cancel clicks while dragging...
 | 
					
						
							|  |  |  | 	// XXX this does not work on android...
 | 
					
						
							|  |  |  | 	$('.field').draggable() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setupControlElements(){ | 
					
						
							|  |  |  | 	// images...
 | 
					
						
							|  |  |  | 	$(".image").click(handleImageClick) | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 	// buttons...
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	$('.screen-button.next-image').click(ImageGrid.nextImage) | 
					
						
							|  |  |  | 	$('.screen-button.prev-image').click(ImageGrid.prevImage) | 
					
						
							| 
									
										
										
										
											2012-08-08 01:45:22 +04:00
										 |  |  | 	// XXX rename classes to "shift-image-up" and "shift-image-down"...
 | 
					
						
							| 
									
										
										
										
											2012-08-04 16:07:08 +04:00
										 |  |  | 	$('.screen-button.demote').click(shiftImageUp) | 
					
						
							|  |  |  | 	$('.screen-button.promote').click(shiftImageDown) | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	$('.screen-button.zoom-in').click(function(){scaleContainerBy(ImageGrid.option.ZOOM_FACTOR)}) | 
					
						
							|  |  |  | 	$('.screen-button.zoom-out').click(function(){scaleContainerBy(1/ImageGrid.option.ZOOM_FACTOR)}) | 
					
						
							| 
									
										
										
										
											2012-08-15 04:03:11 +04:00
										 |  |  | 	// XXX
 | 
					
						
							|  |  |  | 	$('.screen-button.toggle-wide').click(function(){scaleContainerBy(0.2)}) | 
					
						
							| 
									
										
										
										
											2012-08-14 23:40:26 +04:00
										 |  |  | 	$('.screen-button.toggle-single').click(ImageGrid.toggleSingleImageMode) | 
					
						
							| 
									
										
										
										
											2012-08-04 16:07:08 +04:00
										 |  |  | 	$('.screen-button.fit-three').click(fitThreeImages) | 
					
						
							| 
									
										
										
										
											2012-08-15 04:03:11 +04:00
										 |  |  | 	$('.screen-button.show-controls').click(function(){ImageGrid.toggleControls('on')}) | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	$('.screen-button.settings').click(ImageGrid.showSetup) | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | /**************************************************** Serialization **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | function loadImages(json){ | 
					
						
							|  |  |  | 	var images = json.images | 
					
						
							|  |  |  | 	var ribbon = $('.ribbon').last() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	$('.image').remove() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(var i = 0; i < images.length; i++){ | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | 		setImageOrder($('<div class="image"></div>') | 
					
						
							|  |  |  | 			.css({ 'background-image': 'url('+images[i]+')' }), i) | 
					
						
							|  |  |  | 				.click(handleImageClick) | 
					
						
							|  |  |  | 				.appendTo(ribbon) | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	ribbon.children().first().click() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-09 17:53:07 +04:00
										 |  |  | /* bulid a JSON object from current state... | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  |  * format: | 
					
						
							|  |  |  |  * 	{ | 
					
						
							|  |  |  |  * 		ribbons: [ | 
					
						
							| 
									
										
										
										
											2012-08-09 17:53:07 +04:00
										 |  |  |  * 			<image-id>: { | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  |  * 				url: <image-URL>, | 
					
						
							|  |  |  |  * 			},				 | 
					
						
							|  |  |  |  * 			... | 
					
						
							|  |  |  |  * 		] | 
					
						
							|  |  |  |  * 	} | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-08-11 03:38:42 +04:00
										 |  |  | // XXX add incremental or partial updates...
 | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | function buildJSON(get_order){ | 
					
						
							|  |  |  | 	if(get_order == null){ | 
					
						
							|  |  |  | 		get_order = getImageOrder | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | 	var ribbons = $('.ribbon') | 
					
						
							|  |  |  | 	res = { | 
					
						
							|  |  |  | 		ribbons: [] | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for(var i=0; i < ribbons.length; i++){ | 
					
						
							|  |  |  | 		var images = $(ribbons[i]).children('.image') | 
					
						
							| 
									
										
										
										
											2012-08-09 17:53:07 +04:00
										 |  |  | 		var ribbon = {} | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | 		res.ribbons[res.ribbons.length] = ribbon | 
					
						
							|  |  |  | 		for(var j=0; j < images.length; j++){ | 
					
						
							|  |  |  | 			var image = $(images[j]) | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | 			var id = get_order(image) | 
					
						
							| 
									
										
										
										
											2012-08-09 06:29:29 +04:00
										 |  |  | 			ribbon[id] = { | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | 				// unwrap the url...
 | 
					
						
							| 
									
										
										
										
											2012-08-11 03:38:42 +04:00
										 |  |  | 				// XXX would be nice to make this a relative path... (???)
 | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | 				url: /url\((.*)\)/.exec(image.css('background-image'))[1], | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return res | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | // XXX use this instead of loadImages(...)
 | 
					
						
							| 
									
										
										
										
											2012-08-09 17:53:07 +04:00
										 |  |  | // XXX might be good to add images in packs here, not one by one...
 | 
					
						
							| 
									
										
										
										
											2012-08-11 02:59:11 +04:00
										 |  |  | function loadJSON(data, set_order){ | 
					
						
							|  |  |  | 	if(set_order == null){ | 
					
						
							|  |  |  | 		set_order = setImageOrder | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | 	var ribbons = data.ribbons | 
					
						
							|  |  |  | 	var field = $('.field') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// drop all old content...
 | 
					
						
							|  |  |  | 	field.children().remove() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(var i=0; i < ribbons.length; i++){ | 
					
						
							|  |  |  | 		var images = ribbons[i] | 
					
						
							|  |  |  | 		// create ribbon...
 | 
					
						
							|  |  |  | 		var ribbon = $('<div class="ribbon"></div>') | 
					
						
							|  |  |  | 			.appendTo(field) | 
					
						
							| 
									
										
										
										
											2012-08-09 17:53:07 +04:00
										 |  |  | 		for(var j in images){ | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | 			var image = $(images[j]) | 
					
						
							|  |  |  | 			// create image...
 | 
					
						
							| 
									
										
										
										
											2012-08-11 02:59:11 +04:00
										 |  |  | 			set_order($('<div class="image"></div>') | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | 				.css({ 'background-image': 'url('+image.attr('url')+')' }), j) | 
					
						
							|  |  |  | 					.click(handleImageClick) | 
					
						
							|  |  |  | 					.appendTo(ribbon) | 
					
						
							| 
									
										
										
										
											2012-08-09 06:25:09 +04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	$('.image').first().click() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | /*************************************************** Event Handlers **/ | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | // handle click for images...
 | 
					
						
							|  |  |  | function handleImageClick(){ | 
					
						
							| 
									
										
										
										
											2012-07-24 15:38:54 +04:00
										 |  |  | 	// set classes...
 | 
					
						
							|  |  |  | 	$('.current').removeClass('current') | 
					
						
							|  |  |  | 	$(this) | 
					
						
							|  |  |  | 		.addClass('current') | 
					
						
							|  |  |  | 		.parents('.ribbon') | 
					
						
							|  |  |  | 			.addClass('current') | 
					
						
							|  |  |  | 	// position the field and ribbons...
 | 
					
						
							|  |  |  | 	centerSquare() | 
					
						
							| 
									
										
										
										
											2012-07-31 17:41:54 +04:00
										 |  |  | 	alignRibbons() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 23:19:40 +04:00
										 |  |  | /* | 
					
						
							|  |  |  |  * Basic key format: | 
					
						
							|  |  |  |  * 		<key-code> : <callback>, | 
					
						
							|  |  |  |  * 		<key-code> : { | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  |  * 			'default': <callback>, | 
					
						
							| 
									
										
										
										
											2012-08-08 23:19:40 +04:00
										 |  |  |  *			// a modifier can be any single modifier, like shift or a 
 | 
					
						
							|  |  |  |  *			// combination of modifers like 'ctrl+shift', given in order 
 | 
					
						
							|  |  |  |  *			// of priority.
 | 
					
						
							|  |  |  |  *			// supported modifiers are (in order of priority):
 | 
					
						
							|  |  |  |  *			//	- ctrl
 | 
					
						
							|  |  |  |  *			//	- alt
 | 
					
						
							|  |  |  |  *			//	- shift
 | 
					
						
							|  |  |  |  * 			<modifer>: [...] | 
					
						
							|  |  |  |  * 		}, | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  |  * 		<key-code> : [ | 
					
						
							|  |  |  |  *			// this can be any type of handler except for an alias...
 | 
					
						
							|  |  |  |  * 			<handler>,  | 
					
						
							|  |  |  |  * 			<doc> | 
					
						
							|  |  |  |  * 		], | 
					
						
							| 
									
										
										
										
											2012-08-08 23:19:40 +04:00
										 |  |  |  *		// alias...
 | 
					
						
							|  |  |  |  * 		<key-code-a> : <key-code-b>, | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * XXX might need to add meta information to generate sensible help... | 
					
						
							| 
									
										
										
										
											2012-08-08 23:19:40 +04:00
										 |  |  |  */ | 
					
						
							|  |  |  | function makeKeyboardHandler(keybindings, unhandled){ | 
					
						
							|  |  |  | 	if(unhandled == null){ | 
					
						
							|  |  |  | 		unhandled = function(){return false} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return function(evt){ | 
					
						
							|  |  |  | 		var key = evt.keyCode | 
					
						
							|  |  |  | 		// XXX ugly...
 | 
					
						
							|  |  |  | 		var modifers = evt.ctrlKey ? 'ctrl' : '' | 
					
						
							|  |  |  | 		modifers += evt.altKey ? (modifers != '' ? '+alt' : 'alt') : '' | 
					
						
							|  |  |  | 		modifers += evt.shiftKey ? (modifers != '' ? '+shift' : 'shift') : '' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var handler = keybindings[key] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// alias...
 | 
					
						
							|  |  |  | 		while (typeof(handler) == typeof(123)) { | 
					
						
							|  |  |  | 			handler = keybindings[handler] | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// no handler...
 | 
					
						
							|  |  |  | 		if(handler == null){ | 
					
						
							|  |  |  | 			return unhandled(key) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 		// Array, lisp style with docs...
 | 
					
						
							|  |  |  | 		// XXX for some odd reason in chrome typeof([]) == typeof({})!!!
 | 
					
						
							|  |  |  | 		if(typeof(handler) == typeof([]) && handler.constructor.name == 'Array'){ | 
					
						
							|  |  |  | 			// we do not care about docs here, so just get the handler...
 | 
					
						
							|  |  |  | 			handler = handler[0] | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-08-08 23:19:40 +04:00
										 |  |  | 		// complex handler...
 | 
					
						
							|  |  |  | 		if(typeof(handler) == typeof({})){ | 
					
						
							|  |  |  | 			var callback = handler[modifers] | 
					
						
							|  |  |  | 			if(callback == null){ | 
					
						
							|  |  |  | 				callback = handler['default'] | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-08-08 23:19:40 +04:00
										 |  |  | 			if(callback != null){ | 
					
						
							| 
									
										
										
										
											2012-08-17 07:30:03 +04:00
										 |  |  | 				var res = callback() | 
					
						
							|  |  |  | 				return res?true:false | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-08-08 23:19:40 +04:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | 			// simple callback...
 | 
					
						
							| 
									
										
										
										
											2012-08-17 07:30:03 +04:00
										 |  |  | 			var res = handler()  | 
					
						
							|  |  |  | 			return res?true:false | 
					
						
							| 
									
										
										
										
											2012-08-08 23:19:40 +04:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return unhandled(key) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | /************************************************ Mode & UI Actions **/ | 
					
						
							| 
									
										
										
										
											2012-08-14 22:08:18 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-05 21:03:37 +04:00
										 |  |  | function getBackgroundMode(){ | 
					
						
							|  |  |  | 	var mode = null | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	var BACKGROUND_MODES = ImageGrid.option.BACKGROUND_MODES | 
					
						
							| 
									
										
										
										
											2012-08-05 21:03:37 +04:00
										 |  |  | 	// find a mode to set...
 | 
					
						
							|  |  |  | 	for(var i = 0; i < BACKGROUND_MODES.length; i++){ | 
					
						
							|  |  |  | 		// we found our mode...
 | 
					
						
							|  |  |  | 		if( $('.' + BACKGROUND_MODES[i]).length > 0 ){ | 
					
						
							|  |  |  | 			return BACKGROUND_MODES[i] | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return mode | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // set the background mode
 | 
					
						
							|  |  |  | // NOTE: passing null will set the default.
 | 
					
						
							|  |  |  | function setBackgroundMode(mode){ | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	var BACKGROUND_MODES = ImageGrid.option.BACKGROUND_MODES | 
					
						
							| 
									
										
										
										
											2012-08-05 21:03:37 +04:00
										 |  |  | 	var cur = BACKGROUND_MODES.indexOf(mode) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// invalid mode...
 | 
					
						
							|  |  |  | 	if( cur == -1 && mode != null ){ | 
					
						
							|  |  |  | 		return null | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// set the mode...
 | 
					
						
							|  |  |  | 	if(mode != null){ | 
					
						
							|  |  |  | 		$('.viewer').addClass(mode) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// remove all others...
 | 
					
						
							|  |  |  | 	for(var i = 0; i < BACKGROUND_MODES.length; i++){ | 
					
						
							|  |  |  | 		if( i == cur ){ | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		mode = BACKGROUND_MODES[i] | 
					
						
							|  |  |  | 		$('.' + mode).removeClass(mode) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // this will toggle through background theems: none -> dark -> black
 | 
					
						
							|  |  |  | function toggleBackgroundModes(){ | 
					
						
							| 
									
										
										
										
											2012-08-15 02:15:37 +04:00
										 |  |  | 	var BACKGROUND_MODES = ImageGrid.option.BACKGROUND_MODES | 
					
						
							| 
									
										
										
										
											2012-08-05 22:06:52 +04:00
										 |  |  | 	var mode = getBackgroundMode() | 
					
						
							|  |  |  | 	// default -> first
 | 
					
						
							|  |  |  | 	if(mode == null){ | 
					
						
							|  |  |  | 		setBackgroundMode(BACKGROUND_MODES[0]) | 
					
						
							|  |  |  | 	// last -> default...
 | 
					
						
							|  |  |  | 	} else if(mode == BACKGROUND_MODES[BACKGROUND_MODES.length-1]){ | 
					
						
							|  |  |  | 		setBackgroundMode() | 
					
						
							|  |  |  | 	// next...
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		setBackgroundMode(BACKGROUND_MODES[BACKGROUND_MODES.indexOf(mode)+1]) | 
					
						
							| 
									
										
										
										
											2012-08-05 21:03:37 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-05 22:06:52 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | // XXX use order and priority of options...
 | 
					
						
							|  |  |  | // XXX make history work for this...
 | 
					
						
							|  |  |  | // XXX should this be a toggle??
 | 
					
						
							| 
									
										
										
										
											2012-08-15 04:03:11 +04:00
										 |  |  | ImageGrid.ACTION({ | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	title: 'Settings', | 
					
						
							|  |  |  | 	doc: 'Show setup interface.', | 
					
						
							|  |  |  | }, | 
					
						
							|  |  |  | function showSetup(){ | 
					
						
							|  |  |  | 	var opts = ImageGrid.option | 
					
						
							|  |  |  | 	var opt_ps = ImageGrid.option_props | 
					
						
							|  |  |  | 	var groups = {} | 
					
						
							| 
									
										
										
										
											2012-08-05 22:06:52 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	var opts_container = $('<div class="options"/>') | 
					
						
							|  |  |  | 	// build options...
 | 
					
						
							|  |  |  | 	for(var n in opt_ps){ | 
					
						
							|  |  |  | 		var disabled = false | 
					
						
							|  |  |  | 		var opt = opt_ps[n] | 
					
						
							|  |  |  | 		var group = opt.group | 
					
						
							|  |  |  | 		// handle disabled opts...
 | 
					
						
							|  |  |  | 		if(opt.display == false){ | 
					
						
							|  |  |  | 			if(!DEBUG){ | 
					
						
							|  |  |  | 				continue | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			disabled = true | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// build an option...
 | 
					
						
							|  |  |  | 		var option = $('<div class="option"/>').append($([ | 
					
						
							|  |  |  | 			$('<div class="title"/>').text(opt.title != null ? opt.title : n)[0], | 
					
						
							|  |  |  | 			$('<div class="doc"/>').html(opt['doc'].replace(/\n/g, '<br>'))[0], | 
					
						
							|  |  |  | 			$('<div class="value"/>').text(opts[n])[0] | 
					
						
							|  |  |  | 		])) | 
					
						
							|  |  |  | 		// group things correctly...
 | 
					
						
							|  |  |  | 		if(group == null){ | 
					
						
							|  |  |  | 			group = 'Other' | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(groups[group] == null){ | 
					
						
							|  |  |  | 			groups[group] = $('<div class="group"/>') | 
					
						
							|  |  |  | 				.append($('<div class="title"/>').text(group)) | 
					
						
							|  |  |  | 				.append(option) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			groups[group].append(option) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		// event handlers...
 | 
					
						
							|  |  |  | 		var handler = opt_ps[n].click_handler | 
					
						
							|  |  |  | 		if(disabled){ | 
					
						
							|  |  |  | 			option.addClass('disabled') | 
					
						
							|  |  |  | 		} else if(handler != null){ | 
					
						
							|  |  |  | 			option.click(handler) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// build groups...
 | 
					
						
							|  |  |  | 	for(var i = 0; i < ImageGrid.option_groups.length; i++){ | 
					
						
							|  |  |  | 		var group_name = ImageGrid.option_groups[i] | 
					
						
							|  |  |  | 		opts_container.append(groups[group_name]) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	opts_container.append(groups['Other']) | 
					
						
							|  |  |  | 	opts_container.click(function(e){ | 
					
						
							|  |  |  | 		// update the view...
 | 
					
						
							|  |  |  | 		// XXX do we need to redraw the whole thing on each click???
 | 
					
						
							|  |  |  | 		ImageGrid.showSetup() | 
					
						
							|  |  |  | 		e.preventDefault() | 
					
						
							|  |  |  | 		return false | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | 	showInOverlay(opts_container) | 
					
						
							| 
									
										
										
										
											2012-08-15 04:03:11 +04:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2012-08-05 22:06:52 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-05 21:03:37 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | ImageGrid.GROUP('Mode: All', | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			id: 'toggleControls', | 
					
						
							|  |  |  | 			title: 'Keyboard-oriented interface', | 
					
						
							|  |  |  | 			doc: 'Toggle Touch/Keyboard UI controls.', | 
					
						
							|  |  |  | 			type: 'toggle', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		createCSSClassToggler('.viewer', 'hidden-controls')), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			id: 'toggleTransitions', | 
					
						
							|  |  |  | 			title: 'Global transitions', | 
					
						
							|  |  |  | 			doc: 'Toggle global transitions.', | 
					
						
							|  |  |  | 			type: 'toggle', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		createCSSClassToggler('.viewer', 'transitions-enabled'))) | 
					
						
							| 
									
										
										
										
											2012-08-02 17:54:40 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | ImageGrid.GROUP('Mode: Single Image', | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			id: 'toggleSingleImageMode', | 
					
						
							|  |  |  | 			title: 'Single image mode', | 
					
						
							|  |  |  | 			doc: 'Toggle single image mode.', | 
					
						
							|  |  |  | 			type: 'toggle', | 
					
						
							|  |  |  | 			display: false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		createCSSClassToggler('.viewer', 'single-image-mode',  | 
					
						
							|  |  |  | 			// pre...
 | 
					
						
							|  |  |  | 			function(action){ | 
					
						
							|  |  |  | 				if(action == 'on'){ | 
					
						
							|  |  |  | 					ImageGrid.option.NORMAL_MODE_BG = getBackgroundMode() | 
					
						
							|  |  |  | 					ImageGrid.option.ORIGINAL_FIELD_SCALE = getElementScale($('.field')) | 
					
						
							|  |  |  | 				// do this only when coming out of single image mode...
 | 
					
						
							|  |  |  | 				} else if(ImageGrid.toggleSingleImageMode('?') == 'on'){ | 
					
						
							|  |  |  | 					ImageGrid.option.SINGLE_IMAGE_MODE_BG = getBackgroundMode() | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			// post...
 | 
					
						
							|  |  |  | 			function(action){ | 
					
						
							|  |  |  | 				if(action == 'on'){ | 
					
						
							|  |  |  | 					fitImage() | 
					
						
							|  |  |  | 					setBackgroundMode(ImageGrid.option.SINGLE_IMAGE_MODE_BG) | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					setContainerScale(ImageGrid.option.ORIGINAL_FIELD_SCALE) | 
					
						
							|  |  |  | 					setBackgroundMode(ImageGrid.option.NORMAL_MODE_BG) | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				clickAfterTransitionsDone() | 
					
						
							|  |  |  | 			})), | 
					
						
							|  |  |  | 	// XXX for some reason this is backwords... (says 'on' when it's off ans 'off' when on)
 | 
					
						
							|  |  |  | 	// 		...and needs an extra click to sync with state...
 | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			id: 'toggleSingleImageModeTransitions', | 
					
						
							|  |  |  | 			title: 'Disable single image mode transitions', | 
					
						
							|  |  |  | 			doc: 'Toggle transitions in single image mode.', | 
					
						
							|  |  |  | 			type: 'toggle', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		createCSSClassToggler('.viewer', 'no-single-image-transitions'))) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ImageGrid.GROUP('Mode: Ribbon', | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			id: 'toggleSingleRibbonMode', | 
					
						
							|  |  |  | 			title: 'Single ribbon mode', | 
					
						
							|  |  |  | 			doc: 'Show/hide other ribbons.', | 
					
						
							|  |  |  | 			type: 'toggle', | 
					
						
							|  |  |  | 		},  | 
					
						
							|  |  |  | 		createCSSClassToggler('.viewer', 'single-ribbon-mode')), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// XXX this can be done in two ways:
 | 
					
						
							|  |  |  | 	// 		- keep all images when promoting, just add a class to them that 
 | 
					
						
							|  |  |  | 	// 		  will hide them until we enable their display...
 | 
					
						
							|  |  |  | 	// 		  	+ very fast to show/hide
 | 
					
						
							|  |  |  | 	// 		  	- will complicate reversing ribbons allot
 | 
					
						
							|  |  |  | 	// 		- add/remove these images on demand
 | 
					
						
							|  |  |  | 	// 			+ a tad complicated...
 | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			id: 'toggleDisplayShiftedUpImages', | 
					
						
							|  |  |  | 			title: 'Display shifted up images', | 
					
						
							|  |  |  | 			doc: 'Toggle display of shifted images.', | 
					
						
							|  |  |  | 			display: false, | 
					
						
							|  |  |  | 			type: 'toggle', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		createCSSClassToggler('.viewer', 'show-shifted-up-images'))) | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-02 17:54:40 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | /********************************************************* Movement **/ | 
					
						
							| 
									
										
										
										
											2012-08-02 17:54:40 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | ImageGrid.GROUP('Movement', | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Center origin', | 
					
						
							|  |  |  | 			doc: 'Set the transform-origin to the center of the current view.', | 
					
						
							|  |  |  | 			display: false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function centerOrigin(){ | 
					
						
							|  |  |  | 			var mt = parseFloat($('.field').css('margin-top')) | 
					
						
							|  |  |  | 			var ml = parseFloat($('.field').css('margin-left')) | 
					
						
							|  |  |  | 			var cml = parseFloat($('.current.ribbon').css('margin-left')) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var t = parseFloat($('.field').css('top')) | 
					
						
							|  |  |  | 			var l = parseFloat($('.field').css('left')) | 
					
						
							|  |  |  | 			var w = $('.field').width() | 
					
						
							|  |  |  | 			var h = $('.field').height() | 
					
						
							|  |  |  | 			var W = $('.container').width() | 
					
						
							|  |  |  | 			var H = $('.container').height() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var ot = -getCurrentVerticalOffset() + H/2 - t | 
					
						
							|  |  |  | 			var ol = -ml + W/2 - l | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			$('.field').css({ | 
					
						
							|  |  |  | 				'transform-origin': ol + 'px ' + ot + 'px', | 
					
						
							|  |  |  | 				'-o-transform-origin': ol + 'px ' + ot + 'px', | 
					
						
							|  |  |  | 				'-moz-transform-origin': ol + 'px ' + ot + 'px', | 
					
						
							|  |  |  | 				'-webkit-transform-origin': ol + 'px ' + ot + 'px', | 
					
						
							|  |  |  | 				'-ms-transform-origin': ol + 'px ' + ot + 'px' | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 			// XXX for debugging...
 | 
					
						
							|  |  |  | 			$('.origin-marker').css({ | 
					
						
							|  |  |  | 				'top': ot, | 
					
						
							|  |  |  | 				'left': ol | 
					
						
							|  |  |  | 			}) | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	// XXX these work oddly when page is scaled in maxthon... 
 | 
					
						
							|  |  |  | 	// XXX virtually identical, see of can be merged...
 | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Move view up', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function moveViewUp(){ | 
					
						
							|  |  |  | 			var t = parseInt($('.field').css('top')) | 
					
						
							|  |  |  | 			$('.field').css({'top': t-(ImageGrid.option.MOVE_DELTA)}) | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Move view down', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function moveViewDown(){ | 
					
						
							|  |  |  | 			var t = parseInt($('.field').css('top')) | 
					
						
							|  |  |  | 			$('.field').css({'top': t+(ImageGrid.option.MOVE_DELTA)}) | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Move view left', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function moveViewLeft(){ | 
					
						
							|  |  |  | 			var l = parseInt($('.field').css('left')) | 
					
						
							|  |  |  | 			$('.field').css({'left': l-(ImageGrid.option.MOVE_DELTA)}) | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Move view right', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function moveViewRight(){ | 
					
						
							|  |  |  | 			var l = parseInt($('.field').css('left')) | 
					
						
							|  |  |  | 			$('.field').css({'left': l+(ImageGrid.option.MOVE_DELTA)}) | 
					
						
							|  |  |  | 		}), | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Center current image', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function centerCurrentImage(){ | 
					
						
							|  |  |  | 			$('.field') | 
					
						
							|  |  |  | 				.css({ | 
					
						
							|  |  |  | 					'top': 0, | 
					
						
							|  |  |  | 					'left': 0 | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 				// do this after animations are done...
 | 
					
						
							|  |  |  | 				.one("webkitTransitionEnd oTransitionEnd msTransitionEnd transitionend", ImageGrid.centerOrigin) | 
					
						
							|  |  |  | 			// this is repeated intentionally...
 | 
					
						
							|  |  |  | 			// ...needed for small shifts, while the after-animation event 
 | 
					
						
							|  |  |  | 			// is for large moves.
 | 
					
						
							|  |  |  | 			ImageGrid.centerOrigin() | 
					
						
							|  |  |  | 		})) | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | /******************************************************* Navigation **/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | ImageGrid.GROUP('Navigation', | 
					
						
							|  |  |  | 	// basic navigation...
 | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Go to first image', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function firstImage(){ | 
					
						
							|  |  |  | 			return $('.current.ribbon').children('.image').first().click() | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Go to previous image', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function prevImage(){ | 
					
						
							|  |  |  | 			return $('.current.image').prev('.image').click() | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Go to next image', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function nextImage(){ | 
					
						
							|  |  |  | 			return $('.current.image').next('.image').click() | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Go to last image', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function lastImage(){ | 
					
						
							|  |  |  | 			return $('.current.ribbon').children('.image').last().click() | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Skip screen images', | 
					
						
							|  |  |  | 			doc: 'Skip screen-width images in specified direction', | 
					
						
							|  |  |  | 			display: false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function skipScreenImages(direction){ | 
					
						
							|  |  |  | 			// calculate screen width in images...
 | 
					
						
							|  |  |  | 			var W = $('.viewer').width() | 
					
						
							|  |  |  | 			var w = $('.current.image').width() | 
					
						
							|  |  |  | 			var scale = getElementScale($('.field')) | 
					
						
							|  |  |  | 			var n = Math.max(Math.floor(W/(w*scale))-1, 0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var img = $('.current.image')[direction + 'All']('.image').eq(n) | 
					
						
							|  |  |  | 			if(img.length > 0){ | 
					
						
							|  |  |  | 				return img.click() | 
					
						
							|  |  |  | 			} else if(direction == 'next'){ | 
					
						
							|  |  |  | 				return ImageGrid.lastImage() | 
					
						
							|  |  |  | 			} else if(direction == 'prev'){ | 
					
						
							|  |  |  | 				return ImageGrid.firstImage() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Skip next screen images', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function nextScreenImages(){ return ImageGrid.skipScreenImages('next') }), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Skip screen images backwards', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function prevScreenImages(){ return ImageGrid.skipScreenImages('prev') }), | 
					
						
							| 
									
										
										
										
											2012-08-04 18:57:54 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Focus ribbon', | 
					
						
							|  |  |  | 			doc: 'Focus ribbon in specified direction', | 
					
						
							|  |  |  | 			display: false, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function focusRibbon(direction, get_order){ | 
					
						
							|  |  |  | 			if(get_order == null){ | 
					
						
							|  |  |  | 				get_order = getImageOrder | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			var id = get_order($('.current.image')) | 
					
						
							|  |  |  | 			var prev = getImageBefore(id, $('.current.ribbon')[direction]('.ribbon')) | 
					
						
							|  |  |  | 			if(prev){ | 
					
						
							|  |  |  | 				var next = prev.next() | 
					
						
							|  |  |  | 				// NOTE: direction is accounted for to make the up/down shifts 
 | 
					
						
							|  |  |  | 				// 		 symmetrical in the general case...
 | 
					
						
							|  |  |  | 				if(next.length == 0 || direction == 'next'){ | 
					
						
							|  |  |  | 					return prev.click() | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					return next.click() | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				return $('.current.ribbon')[direction]('.ribbon').children('.image').first().click() | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Focus ribbon above', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function focusAboveRibbon(){ return ImageGrid.focusRibbon('prev') }), | 
					
						
							|  |  |  | 	ImageGrid.ACTION({ | 
					
						
							|  |  |  | 			title: 'Focus ribbon below', | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		function focusBelowRibbon(){ return ImageGrid.focusRibbon('next') })) | 
					
						
							| 
									
										
										
										
											2012-08-02 17:54:40 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | /********************************************************** Zooming **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // NOTE: this will only return a single scale value...
 | 
					
						
							|  |  |  | function getElementScale(elem){ | 
					
						
							|  |  |  | 	//var transform = elem.css('transform')
 | 
					
						
							|  |  |  | 	var vendors = ['o', 'moz', 'ms', 'webkit'] | 
					
						
							|  |  |  | 	var transform = elem.css('transform') | 
					
						
							|  |  |  | 	var res | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// go through vendor prefixes... (hate this!)
 | 
					
						
							|  |  |  | 	if(!transform || transform == 'none'){ | 
					
						
							|  |  |  | 		for(var i in vendors){ | 
					
						
							|  |  |  | 			transform = elem.css('-' + vendors[i] + '-transform') | 
					
						
							|  |  |  | 			if(transform && transform != 'none'){ | 
					
						
							|  |  |  | 				break | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// no transform is set...
 | 
					
						
							|  |  |  | 	if(!transform || transform == 'none'){ | 
					
						
							|  |  |  | 		return 1 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// get the scale value -- first argument of scale/matrix...
 | 
					
						
							|  |  |  | 	return parseFloat((/(scale|matrix)\(([^,]*),.*\)/).exec(transform)[2]) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setElementScale(elem, scale){ | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | 	return elem.css({ | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | 		'transform': 'scale('+scale+', '+scale+')', | 
					
						
							|  |  |  | 		'-moz-transform': 'scale('+scale+', '+scale+')', | 
					
						
							|  |  |  | 		'-o-transform': 'scale('+scale+', '+scale+')', | 
					
						
							|  |  |  | 		'-ms-transform': 'scale('+scale+', '+scale+')', | 
					
						
							|  |  |  | 		'-webkit-transform': 'scale('+scale+', '+scale+')', | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function scaleContainerBy(factor){ | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | 	return setContainerScale(getElementScale($('.field'))*factor) | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setContainerScale(scale){ | 
					
						
							|  |  |  | 	return setElementScale($('.field'), scale) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | function fitNImages(n){ | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | 	var H = $('.container').height() | 
					
						
							|  |  |  | 	var W = $('.container').width() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var h = $('.image.current').height() | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 	// NOTE: this is cheating, need to get actual three widths...
 | 
					
						
							|  |  |  | 	var w = $('.image.current').width()*n | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var f = Math.min(H/h, W/w) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	setContainerScale(f) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | function fitImage(){fitNImages(1)} | 
					
						
							|  |  |  | function fitTwoImages(){fitNImages(2)} | 
					
						
							|  |  |  | function fitThreeImages(){fitNImages(3)} | 
					
						
							|  |  |  | function fitFourImages(){fitNImages(4)} | 
					
						
							|  |  |  | function fitFiveImages(){fitNImages(5)} | 
					
						
							|  |  |  | function fitSixImages(){fitNImages(6)} | 
					
						
							|  |  |  | function fitSevenImages(){fitNImages(7)} | 
					
						
							|  |  |  | function fitEightImages(){fitNImages(8)} | 
					
						
							|  |  |  | function fitNineImages(){fitNImages(9)} | 
					
						
							| 
									
										
										
										
											2012-08-10 18:31:32 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | /********************************************************** Actions **/ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | // basic actions...
 | 
					
						
							| 
									
										
										
										
											2012-08-04 19:47:13 +04:00
										 |  |  | // NOTE: below 'direction' argument is meant in the html sence, 
 | 
					
						
							|  |  |  | //       i.e. next/prev...
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | // create ribbon above/below helpers...
 | 
					
						
							| 
									
										
										
										
											2012-08-04 19:47:13 +04:00
										 |  |  | // XXX adding a ribbon above the current is still jumpy, need to devise 
 | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | // 		a cleaner way to do this...
 | 
					
						
							| 
									
										
										
										
											2012-06-16 21:40:36 +04:00
										 |  |  | function createRibbon(direction){ | 
					
						
							|  |  |  | 	if(direction == 'next'){ | 
					
						
							|  |  |  | 		var insert = 'insertAfter' | 
					
						
							|  |  |  | 	} else if(direction == 'prev') { | 
					
						
							|  |  |  | 		var insert = 'insertBefore' | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-04 19:47:13 +04:00
										 |  |  | 	// adding a new ribbon above the current effectively pushes the 
 | 
					
						
							|  |  |  | 	// whole view down, so we need to compensate for this.
 | 
					
						
							|  |  |  | 	// NOTE: the problem is partly caused by clicks fiering BEFORE the 
 | 
					
						
							|  |  |  | 	// 		 animation is done...
 | 
					
						
							| 
									
										
										
										
											2012-08-04 19:37:40 +04:00
										 |  |  | 	$('.field').addClass('unanimated')	 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-08-04 19:47:13 +04:00
										 |  |  | 	if(direction == 'prev'){ | 
					
						
							|  |  |  | 		$('.field').css({ | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | 			'margin-top': parseInt($('.field').css('margin-top')) - $('.ribbon').outerHeight() | 
					
						
							| 
									
										
										
										
											2012-08-04 19:47:13 +04:00
										 |  |  | 		}) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	// the actual insert...
 | 
					
						
							|  |  |  | 	var res = $('<div class="ribbon"></div>')[insert]('.current.ribbon') | 
					
						
							| 
									
										
										
										
											2012-08-04 19:37:40 +04:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-08-04 19:47:13 +04:00
										 |  |  | 	// restore the animated state...
 | 
					
						
							| 
									
										
										
										
											2012-08-04 19:37:40 +04:00
										 |  |  | 	$('.field').removeClass('unanimated')	 | 
					
						
							| 
									
										
										
										
											2012-08-04 18:57:54 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	return res | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-04 20:09:19 +04:00
										 |  |  | // merge current and direction ribbon...
 | 
					
						
							|  |  |  | // NOTE: this will take all the elements from direction ribbon and add
 | 
					
						
							|  |  |  | //       them to current
 | 
					
						
							| 
									
										
										
										
											2012-08-04 19:47:13 +04:00
										 |  |  | // XXX this uses jquery animation...
 | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | // XXX one way to optimise this is to add the lesser ribbon to the 
 | 
					
						
							|  |  |  | //     greater disregarding their actual order...
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:26:46 +04:00
										 |  |  | // XXX think about using $(...).sortChildren(...) / sortImages()
 | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | function mergeRibbons(direction, get_order){ | 
					
						
							|  |  |  | 	if(get_order == null){ | 
					
						
							|  |  |  | 		get_order = getImageOrder | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-04 20:09:19 +04:00
										 |  |  | 	var current_ribbon = $('.current.ribbon') | 
					
						
							|  |  |  | 	var images = $('.current.ribbon')[direction]('.ribbon').children() | 
					
						
							|  |  |  | 	for(var i=0; i < images.length; i++){ | 
					
						
							|  |  |  | 		var image = $(images[i]) | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | 		// get previous element after which we need to put the current...
 | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | 		var prev_elem = getImageBefore(get_order(image), current_ribbon) | 
					
						
							| 
									
										
										
										
											2012-08-04 20:26:38 +04:00
										 |  |  | 		// check if we need to be before the first element...
 | 
					
						
							| 
									
										
										
										
											2012-08-04 20:09:19 +04:00
										 |  |  | 		if(prev_elem == null){ | 
					
						
							|  |  |  | 			image | 
					
						
							|  |  |  | 				.detach() | 
					
						
							|  |  |  | 				.insertBefore(current_ribbon.children('.image').first()) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			image | 
					
						
							|  |  |  | 				.detach() | 
					
						
							|  |  |  | 				.insertAfter(prev_elem) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 	// animate...
 | 
					
						
							| 
									
										
										
										
											2012-07-24 14:55:10 +04:00
										 |  |  | 	$('.current.ribbon')[direction]('.ribbon') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			.slideUp(function(){ | 
					
						
							|  |  |  | 				$(this).remove() | 
					
						
							| 
									
										
										
										
											2012-07-24 14:55:10 +04:00
										 |  |  | 				$('.current.image').click() | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 			}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-05 00:02:17 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-17 16:46:46 +04:00
										 |  |  | /*************************************************** Editor Actions **/ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:52:23 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | // now the actual modifiers...
 | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | function shiftImage(direction, get_order){ | 
					
						
							|  |  |  | 	if(get_order == null){ | 
					
						
							|  |  |  | 		get_order = getImageOrder | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-07-24 14:55:10 +04:00
										 |  |  | 	if($('.current.ribbon')[direction]('.ribbon').length == 0){ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:40:36 +04:00
										 |  |  | 		createRibbon(direction) | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// get previous element after which we need to put the current...
 | 
					
						
							|  |  |  | 	var prev_elem = getImageBefore( | 
					
						
							| 
									
										
										
										
											2012-08-10 20:25:49 +04:00
										 |  |  | 					get_order($('.current.image')),  | 
					
						
							| 
									
										
										
										
											2012-07-24 14:55:10 +04:00
										 |  |  | 					$('.current.ribbon')[direction]('.ribbon')) | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// last image in ribbon, merge...
 | 
					
						
							| 
									
										
										
										
											2012-07-24 14:55:10 +04:00
										 |  |  | 	if($('.current.ribbon').children('.image').length == 1){ | 
					
						
							| 
									
										
										
										
											2012-06-16 21:24:11 +04:00
										 |  |  | 		mergeRibbons(direction) | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2012-07-24 14:55:10 +04:00
										 |  |  | 		img = $('.current.image') | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 		if(img.next('.image').length == 0){ | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 			ImageGrid.prevImage() | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2012-08-19 19:30:59 +04:00
										 |  |  | 			ImageGrid.nextImage() | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | 		// do the actual move...
 | 
					
						
							|  |  |  | 		if(prev_elem){ | 
					
						
							|  |  |  | 			// insert element after current...
 | 
					
						
							|  |  |  | 			img | 
					
						
							|  |  |  | 				.detach() | 
					
						
							|  |  |  | 				.insertAfter(prev_elem) | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			// empty ribbon or fisrt element...
 | 
					
						
							|  |  |  | 			img | 
					
						
							|  |  |  | 				.detach() | 
					
						
							| 
									
										
										
										
											2012-07-24 14:55:10 +04:00
										 |  |  | 				.prependTo($('.current.ribbon')[direction]('.ribbon')) | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-04 19:37:40 +04:00
										 |  |  | 	$('.current.image').click() | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-08-10 19:40:26 +04:00
										 |  |  | var shiftImageDown = function(){ return shiftImage('next') } | 
					
						
							|  |  |  | var shiftImageUp = function(){ return shiftImage('prev') } | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-16 22:12:50 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:26:46 +04:00
										 |  |  | // reverse the ribbon order...
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:38:04 +04:00
										 |  |  | // NOTE: this is like flipping the field vertically...
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:26:46 +04:00
										 |  |  | function reverseRibbons(){ | 
					
						
							|  |  |  | 	// reverse...
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:38:58 +04:00
										 |  |  | 	$('.field').reverseChildren() | 
					
						
							| 
									
										
										
										
											2012-08-14 17:26:46 +04:00
										 |  |  | 	// compensate for offset cange...
 | 
					
						
							|  |  |  | 	$('.current.image').click() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // sort all images in all ribbons...
 | 
					
						
							|  |  |  | // NOTE: this will only align three ribbons...
 | 
					
						
							|  |  |  | function sortImages(){ | 
					
						
							|  |  |  | 	$('.ribbon').sortChildren(cmpImageOrder) | 
					
						
							|  |  |  | 	// compensate for offset cange...
 | 
					
						
							|  |  |  | 	$('.current.image').click() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:38:04 +04:00
										 |  |  | // use the cmp function to update image id's and resort...
 | 
					
						
							|  |  |  | function resortImagesVia(cmp){ | 
					
						
							| 
									
										
										
										
											2012-08-14 17:26:46 +04:00
										 |  |  | 	// reverse ID order...
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:38:04 +04:00
										 |  |  | 	$($('.image').get().sort(cmp)) | 
					
						
							| 
									
										
										
										
											2012-08-14 17:26:46 +04:00
										 |  |  | 		.each(function(i, e){$(e).attr({'id': i})}) | 
					
						
							|  |  |  | 	// resort the images...
 | 
					
						
							|  |  |  | 	sortImages() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 20:13:36 +04:00
										 |  |  | // reverse the order of images in all ribbons by reversing their id attr
 | 
					
						
							|  |  |  | // and resorting...
 | 
					
						
							|  |  |  | // NOTE: this is like flipping the field horizontally...
 | 
					
						
							|  |  |  | function reverseImageOrder(){ | 
					
						
							|  |  |  | 	resortImagesVia(function(a, b){return cmpImageOrder(b, a)}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 20:12:30 +04:00
										 |  |  | // sort images py their full path...
 | 
					
						
							|  |  |  | // XXX this should use a normalized path...
 | 
					
						
							|  |  |  | function sortImagesByPath(){ | 
					
						
							|  |  |  | 	resortImagesVia(function(a, b){  | 
					
						
							|  |  |  | 		a = $(a).css('background-image') | 
					
						
							|  |  |  | 		b = $(b).css('background-image')  | 
					
						
							|  |  |  | 		return a > b ? 1 : a < b ? -1 : 0 | 
					
						
							|  |  |  | 	}) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 18:08:45 +04:00
										 |  |  | // XXX group images in ribbon and merge down/up
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 		grouping will make the images in a ribbon adjacent to each 
 | 
					
						
							|  |  |  | // 		other...
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // 		the group's position will be the same as current images i.e. 
 | 
					
						
							|  |  |  | // 		between the below/above two images...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX shift group/image right/left...
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-14 17:26:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-07 21:12:22 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-15 04:03:11 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-14 00:00:16 +04:00
										 |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-06-08 18:30:54 +04:00
										 |  |  | // vim:set ts=4 sw=4 nowrap :
 |