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