mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-30 19:00:09 +00:00 
			
		
		
		
	refactored the keyboard.js module a bit...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									2ace671030
								
							
						
					
					
						commit
						80a5f031a2
					
				| @ -39,11 +39,10 @@ function directionImage(reverse){ | ||||
| /*********************************************************************/ | ||||
| 
 | ||||
| var KEYBOARD_CONFIG = { | ||||
| 	// Global bindings...
 | ||||
| 	'*': { | ||||
| 		title: 'Global bindings', | ||||
| 	'Global bindings': { | ||||
| 		doc: 'NOTE: binding priority is the same as the order of sections '+ | ||||
| 			'on this page.', | ||||
| 		pattern: '*', | ||||
| 
 | ||||
| 		F4: { | ||||
| 			alt: doc('Close viewer',  | ||||
| @ -92,8 +91,7 @@ var KEYBOARD_CONFIG = { | ||||
| 	//
 | ||||
| 	// NOTE: this is here to prevent selecting images while trying to 
 | ||||
| 	// 		select info text...
 | ||||
| 	'.overlay-info:hover': { | ||||
| 		title: 'Info overlay', | ||||
| 	'Info overlay': { | ||||
| 		doc: 'Displayed on bottom of the screen if enabled (toggle with '+ | ||||
| 			'<b>I</b>) and/or inline, at bottom of an image when cursor '+ | ||||
| 			'is over it (only in ribbon view, toggle with <b>alt-I</b>)'+ | ||||
| @ -101,6 +99,7 @@ var KEYBOARD_CONFIG = { | ||||
| 			'<p>NOTE: when the cursor is over the info overlay one can use '+ | ||||
| 			'Ctrl-A and Ctrl-D for info text selection, without affecting '+ | ||||
| 			'image selection/marks.', | ||||
| 		pattern: '.overlay-info:hover', | ||||
| 
 | ||||
| 		ignore: [ 'A' ], | ||||
| 
 | ||||
| @ -122,10 +121,11 @@ var KEYBOARD_CONFIG = { | ||||
| 	//
 | ||||
| 	// NOTE: editor effects are not documented, but should be obvious...
 | ||||
| 	// 		XXX is this the case?
 | ||||
| 	'.viewer.overlay .overlay-block.dialog, .panel :focus': { | ||||
| 		title: 'Dialog', | ||||
| 	'Dialog': { | ||||
| 		doc: 'NOTE: to <i>close</i> a dialog, in addition to the keyaboard '+ | ||||
| 			'shortcuts, one can also click anywhere outside the dialog.', | ||||
| 		pattern: '.viewer.overlay .overlay-block.dialog, ' | ||||
| 			+'.panel :focus', | ||||
| 
 | ||||
| 		ignore: '*', | ||||
| 
 | ||||
| @ -181,10 +181,10 @@ var KEYBOARD_CONFIG = { | ||||
| 	//
 | ||||
| 	// NOTE: need to keep all info modes before the rest so as to give 
 | ||||
| 	// 		their bindings priority...
 | ||||
| 	'.drawer-mode': { | ||||
| 		title: 'Drawer views', | ||||
| 	'Drawer views': { | ||||
| 		doc: 'NOTE: In this view all other key bindings are disabled, '+ | ||||
| 			'except app defaults and the ones explicitly defined here.', | ||||
| 		pattern: '.drawer-mode', | ||||
| 
 | ||||
| 		ignore: '*', | ||||
| 
 | ||||
| @ -199,9 +199,9 @@ var KEYBOARD_CONFIG = { | ||||
| 
 | ||||
| 	// slideshow view...
 | ||||
| 	//
 | ||||
| 	'.slideshow-mode': { | ||||
| 		title: 'Slideshow view', | ||||
| 	'Slideshow view': { | ||||
| 		doc: 'To enter this view press <b>S</b>.', | ||||
| 		pattern: '.slideshow-mode', | ||||
| 
 | ||||
| 		// XXX think about what else to disable here...
 | ||||
| 		ignore: [ | ||||
| @ -232,9 +232,9 @@ var KEYBOARD_CONFIG = { | ||||
| 
 | ||||
| 	// single image view...
 | ||||
| 	//
 | ||||
| 	'.single-image-mode': { | ||||
| 		title: 'Single image view', | ||||
| 	'Single image view': { | ||||
| 		doc: 'To toggle between this and ribbon view press <b>Enter</b>.', | ||||
| 		pattern: '.single-image-mode', | ||||
| 
 | ||||
| 		Esc: doc('Exit single image view',  | ||||
| 				function(){  | ||||
| @ -247,12 +247,13 @@ var KEYBOARD_CONFIG = { | ||||
| 
 | ||||
| 	// crop views...
 | ||||
| 	//
 | ||||
| 	'.single-ribbon-mode:not(.single-image-mode), .marked-only-view:not(.single-image-mode)': { | ||||
| 		title: 'Cropped ribbon views', | ||||
| 	'Cropped ribbon views': { | ||||
| 		doc: 'To crop marked images press <b>shift-F2</b> for '+ | ||||
| 			'single ribbon crop view press <b>F3</b> and to open the crop '+ | ||||
| 			'dialog for more options press <b>C</b>.'+ | ||||
| 			'<p>NOTE: toggling crop views is only possible from ribbon view.', | ||||
| 		pattern: '.single-ribbon-mode:not(.single-image-mode), ' | ||||
| 			+'.marked-only-view:not(.single-image-mode)', | ||||
| 
 | ||||
| 		Esc: { | ||||
| 				default: doc('Uncrop to last state',  | ||||
| @ -291,8 +292,8 @@ var KEYBOARD_CONFIG = { | ||||
| 	// ribbon view only...
 | ||||
| 	//
 | ||||
| 	// XXX this breaks getKeyHandlers(...) when modes argument is given...
 | ||||
| 	'.viewer:not(.overlay):not(.single-image-mode)': { | ||||
| 		title: 'Ribbon view', | ||||
| 	'Ribbon view': { | ||||
| 		pattern: '.viewer:not(.overlay):not(.single-image-mode)', | ||||
| 
 | ||||
| 		Left: { | ||||
| 				// XXX revise...
 | ||||
| @ -416,14 +417,14 @@ var KEYBOARD_CONFIG = { | ||||
| 
 | ||||
| 	// general setup...
 | ||||
| 	//
 | ||||
| 	'.viewer:not(.overlay)': { | ||||
| 		title: 'Viewer', | ||||
| 	'Viewer': { | ||||
| 		doc: 'These key bindings work in most other viewer views.'+ | ||||
| 
 | ||||
| 			'<p>NOTE: shifting all marked images from different ribbons will '+ | ||||
| 			'perform the operations on ALL marked images but relative '+ | ||||
| 			'the the current ribbon. i.e. some images might get promoted, '+ | ||||
| 			'others demoted while some will not change position. ', | ||||
| 		pattern: '.viewer:not(.overlay)', | ||||
| 
 | ||||
| 		// Basics...
 | ||||
| 		// XXX STUB: use a real path browser...
 | ||||
|  | ||||
| @ -222,7 +222,14 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys){ | ||||
| 
 | ||||
| 	res = {} | ||||
| 
 | ||||
| 	for(var mode in keybindings){ | ||||
| 	for(var title in keybindings){ | ||||
| 
 | ||||
| 		// older version compatibility...
 | ||||
| 		if(keybindings[title].pattern != null){ | ||||
| 			var mode = keybindings[title].pattern | ||||
| 		} else { | ||||
| 			var mode = title | ||||
| 		} | ||||
| 
 | ||||
| 		// check if we need to skip this mode...
 | ||||
| 		if( !(modes == 'all' | ||||
| @ -237,7 +244,7 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys){ | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		var bindings = keybindings[mode] | ||||
| 		var bindings = keybindings[title] | ||||
| 
 | ||||
| 		if(s_chr != null && s_chr in bindings){ | ||||
| 			var handler = bindings[s_chr] | ||||
| @ -350,10 +357,9 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys){ | ||||
| /* Basic key binding format: | ||||
|  * | ||||
|  * { | ||||
|  * 		<css-selector>: { | ||||
|  *			// meta-data used to generate user docs/help/config
 | ||||
|  * 			title: <text>, | ||||
|  * 		<title>: { | ||||
|  * 			doc: <text>, | ||||
|  * 			pattern: <css-selector>, | ||||
|  * | ||||
|  *			// this defines the list of keys to ignore by the handler.
 | ||||
|  *			// NOTE: use "*" to ignore all keys other than explicitly 
 | ||||
| @ -398,6 +404,13 @@ function getKeyHandlers(key, modifiers, keybindings, modes, shifted_keys){ | ||||
|  *			... | ||||
|  * 		}, | ||||
|  * | ||||
|  *		// legacy format, still supported... (deprecated)
 | ||||
|  * 		<css-selector>: { | ||||
|  *			// meta-data used to generate user docs/help/config
 | ||||
|  * 			title: <text>, | ||||
|  * 			... | ||||
|  * 		}, | ||||
|  * | ||||
|  * 		... | ||||
|  * } | ||||
|  * | ||||
| @ -499,11 +512,18 @@ function buildKeybindingsHelp(keybindings, shifted_keys){ | ||||
| 	var res = {} | ||||
| 	var mode, title | ||||
| 
 | ||||
| 	for(var pattern in keybindings){ | ||||
| 		mode = keybindings[pattern] | ||||
| 	for(var title in keybindings){ | ||||
| 		mode = keybindings[title] | ||||
| 
 | ||||
| 		// older version compatibility...
 | ||||
| 		if(keybindings[title].pattern != null){ | ||||
| 			var pattern = keybindings[title].pattern | ||||
| 		} else { | ||||
| 			var pattern = title | ||||
| 			// titles and docs...
 | ||||
| 		title = mode.title == null ? pattern : mode.title | ||||
| 			var title = mode.title == null ? pattern : mode.title | ||||
| 		} | ||||
| 
 | ||||
| 		res[title] = { | ||||
| 			doc: mode.doc == null ? '' : mode.doc | ||||
| 		} | ||||
| @ -511,17 +531,15 @@ function buildKeybindingsHelp(keybindings, shifted_keys){ | ||||
| 
 | ||||
| 		// handlers...
 | ||||
| 		for(var key in mode){ | ||||
| 			if(key == 'doc' || key == 'title' || key == 'ignore'){ | ||||
| 			if(key == 'doc' || key == 'title' || key == 'ignore' || key == 'pattern'){ | ||||
| 				continue | ||||
| 			} | ||||
| 			//var modifiers = getKeyHandlers(key, '?', keybindings, pattern)[pattern]
 | ||||
| 			var modifiers = getKeyHandlers(key, '?', keybindings, 'all')[pattern] | ||||
| 			modifiers = modifiers == 'none' || modifiers == undefined ? [''] : modifiers | ||||
| 
 | ||||
| 			for(var i=0; i < modifiers.length; i++){ | ||||
| 				var mod = modifiers[i] | ||||
| 
 | ||||
| 				//var handler = getKeyHandlers(key, mod, keybindings, pattern)[pattern]
 | ||||
| 				var handler = getKeyHandlers(key, mod, keybindings, 'all')[pattern] | ||||
| 
 | ||||
| 				// standard object doc...
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user