mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 19:00:09 +00:00
fixed a problem with keyboard handler (see number keys in source)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
32ad1b9cde
commit
81f26c36a4
@ -67,14 +67,10 @@ var KEYBOARD_CONFIG = {
|
|||||||
ctrl: 'Right',
|
ctrl: 'Right',
|
||||||
'ctrl+shift': 'Left',
|
'ctrl+shift': 'Left',
|
||||||
},
|
},
|
||||||
/* XXX for some reason this does not work,,,
|
|
||||||
// XXX for some odd reason, returning false does not cancel
|
|
||||||
// default behaviour here...
|
|
||||||
Backspace: {
|
Backspace: {
|
||||||
default: 'Left',
|
default: 'Left',
|
||||||
shift: 'Right',
|
shift: 'Right',
|
||||||
},
|
},
|
||||||
*/
|
|
||||||
Home: function(){
|
Home: function(){
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
firstImage()
|
firstImage()
|
||||||
@ -125,16 +121,15 @@ var KEYBOARD_CONFIG = {
|
|||||||
|
|
||||||
|
|
||||||
// zooming...
|
// zooming...
|
||||||
'1': function(){ fitNImages(1) },
|
'#1': function(){ fitNImages(1) },
|
||||||
'2': function(){ fitNImages(2) },
|
'#2': function(){ fitNImages(2) },
|
||||||
'3': function(){ fitNImages(3) },
|
'#3': function(){ fitNImages(3) },
|
||||||
'4': function(){ fitNImages(4) },
|
'#4': function(){ fitNImages(4) },
|
||||||
'5': function(){ fitNImages(5) },
|
'#5': function(){ fitNImages(5) },
|
||||||
'6': function(){ fitNImages(6) },
|
'#6': function(){ fitNImages(6) },
|
||||||
'7': function(){ fitNImages(7) },
|
'#7': function(){ fitNImages(7) },
|
||||||
// XXX for some reason this also hooks the Backspace key (80)...
|
'#8': function(){ fitNImages(8) },
|
||||||
'8': function(){ fitNImages(8) },
|
'#9': function(){ fitNImages(9) },
|
||||||
'9': function(){ fitNImages(9) },
|
|
||||||
|
|
||||||
'-': function(){ zoomOut() },
|
'-': function(){ zoomOut() },
|
||||||
'=': function(){ zoomIn() },
|
'=': function(){ zoomIn() },
|
||||||
|
|||||||
@ -25,7 +25,7 @@ var _SPECIAL_KEYS = {
|
|||||||
// Special Keys...
|
// Special Keys...
|
||||||
9: 'Tab', 33: 'PgUp', 45: 'Ins',
|
9: 'Tab', 33: 'PgUp', 45: 'Ins',
|
||||||
13: 'Enter', 34: 'PgDown', 46: 'Del',
|
13: 'Enter', 34: 'PgDown', 46: 'Del',
|
||||||
16: 'Shift', 35: 'End', 80: 'Backspace',
|
16: 'Shift', 35: 'End', 8: 'Backspace',
|
||||||
17: 'Ctrl', 36: 'Home', 91: 'Win',
|
17: 'Ctrl', 36: 'Home', 91: 'Win',
|
||||||
18: 'Alt', 37: 'Left', 93: 'Menu',
|
18: 'Alt', 37: 'Left', 93: 'Menu',
|
||||||
20: 'Caps Lock',38: 'Up',
|
20: 'Caps Lock',38: 'Up',
|
||||||
@ -39,8 +39,19 @@ var _SPECIAL_KEYS = {
|
|||||||
115: 'F4', 119: 'F8', 123: 'F12',
|
115: 'F4', 119: 'F8', 123: 'F12',
|
||||||
|
|
||||||
// Number row..
|
// Number row..
|
||||||
49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
|
// NOTE: to avoid conflicts with keys that have a code the same as
|
||||||
54: '6', 55: '7', 56: '8', 57: '9', 48: '0',
|
// the value of a number key...
|
||||||
|
// Ex:
|
||||||
|
// 'Backspace' (8) vs. '8' (56)
|
||||||
|
// 'Tab' (9) vs. '9' (57)
|
||||||
|
// ...all of the numbers start with a '#'
|
||||||
|
// this is a problem due to JS coercing the types to string
|
||||||
|
// on object attr access.
|
||||||
|
// Ex:
|
||||||
|
// o = {1: 2}
|
||||||
|
// o[1] == o['1'] == true
|
||||||
|
49: '#1', 50: '#2', 51: '#3', 52: '#4', 53: '#5',
|
||||||
|
54: '#6', 55: '#7', 56: '#8', 57: '#9', 48: '#0',
|
||||||
|
|
||||||
// Punctuation...
|
// Punctuation...
|
||||||
// top row...
|
// top row...
|
||||||
@ -97,14 +108,25 @@ var KEYBOARD_HANDLER_PROPAGATE = true
|
|||||||
* // defined in the current section.
|
* // defined in the current section.
|
||||||
* ignore: <ignored-keys>
|
* ignore: <ignored-keys>
|
||||||
*
|
*
|
||||||
|
* // NOTE: a callback can have a .doc attr containing
|
||||||
|
* // documentation...
|
||||||
* <key-def> : <callback>,
|
* <key-def> : <callback>,
|
||||||
*
|
*
|
||||||
|
* <key-def> : [
|
||||||
|
* // this can be any type of handler except for an alias...
|
||||||
|
* <handler>,
|
||||||
|
* <doc>
|
||||||
|
* ],
|
||||||
|
*
|
||||||
* <key-def> : {
|
* <key-def> : {
|
||||||
|
* // optional documentation string...
|
||||||
|
* doc: <doc-string>,
|
||||||
|
*
|
||||||
* // modifiers can either have a callback or an alias as
|
* // modifiers can either have a callback or an alias as
|
||||||
* // a value...
|
* // a value...
|
||||||
* // NOTE: when the alias is resolved, the same modifiers
|
* // NOTE: when the alias is resolved, the same modifiers
|
||||||
* // will be applied to the final resolved handler.
|
* // will be applied to the final resolved handler.
|
||||||
* 'default': <callback> | <key-def-x>,
|
* default: <callback> | <key-def-x>,
|
||||||
*
|
*
|
||||||
* // a modifier can be any single modifier, like shift or a
|
* // a modifier can be any single modifier, like shift or a
|
||||||
* // combination of modifers like 'ctrl+shift', given in order
|
* // combination of modifers like 'ctrl+shift', given in order
|
||||||
@ -117,12 +139,6 @@ var KEYBOARD_HANDLER_PROPAGATE = true
|
|||||||
* ...
|
* ...
|
||||||
* },
|
* },
|
||||||
*
|
*
|
||||||
* <key-def> : [
|
|
||||||
* // this can be any type of handler except for an alias...
|
|
||||||
* <handler>,
|
|
||||||
* <doc>
|
|
||||||
* ],
|
|
||||||
*
|
|
||||||
* // alias...
|
* // alias...
|
||||||
* <key-def-a> : <key-def-b>,
|
* <key-def-a> : <key-def-b>,
|
||||||
*
|
*
|
||||||
@ -147,8 +163,9 @@ var KEYBOARD_HANDLER_PROPAGATE = true
|
|||||||
* NOTE: a <css-selector> is used as a predicate to select a section to
|
* NOTE: a <css-selector> is used as a predicate to select a section to
|
||||||
* use. if multiple selectors match something then multiple sections
|
* use. if multiple selectors match something then multiple sections
|
||||||
* will be resolved in order of occurrence.
|
* will be resolved in order of occurrence.
|
||||||
*
|
* NOTE: the number keys are named with a leading hash '#' (e.g. '#8')
|
||||||
* XXX might need to add meta information to generate sensible help...
|
* to avoid conflicsts with keys that have the code with the same
|
||||||
|
* value (e.g. 'backspace' (8)).
|
||||||
*/
|
*/
|
||||||
function makeKeyboardHandler(keybindings, unhandled){
|
function makeKeyboardHandler(keybindings, unhandled){
|
||||||
if(unhandled == null){
|
if(unhandled == null){
|
||||||
@ -158,12 +175,16 @@ function makeKeyboardHandler(keybindings, unhandled){
|
|||||||
return function(evt){
|
return function(evt){
|
||||||
var did_handling = false
|
var did_handling = false
|
||||||
var res = null
|
var res = null
|
||||||
|
|
||||||
|
var key = evt.keyCode
|
||||||
|
var chr = toKeyName(key)
|
||||||
|
|
||||||
|
window.DEBUG && console.log('KEY:', key, chr)
|
||||||
|
|
||||||
for(var mode in keybindings){
|
for(var mode in keybindings){
|
||||||
if($(mode).length > 0){
|
if($(mode).length > 0){
|
||||||
var bindings = keybindings[mode]
|
var bindings = keybindings[mode]
|
||||||
|
|
||||||
var key = evt.keyCode
|
|
||||||
var chr = toKeyName(evt.keyCode)
|
|
||||||
// normalize the modifiers...
|
// normalize the modifiers...
|
||||||
var modifers = evt.ctrlKey ? 'ctrl' : ''
|
var modifers = evt.ctrlKey ? 'ctrl' : ''
|
||||||
modifers += evt.altKey ? (modifers != '' ? '+alt' : 'alt') : ''
|
modifers += evt.altKey ? (modifers != '' ? '+alt' : 'alt') : ''
|
||||||
@ -176,9 +197,11 @@ function makeKeyboardHandler(keybindings, unhandled){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// alias...
|
// alias...
|
||||||
while (typeof(handler) == typeof(123)
|
while( handler != null
|
||||||
|| typeof(handler) == typeof('str')
|
&& (typeof(handler) == typeof(123)
|
||||||
|| typeof(handler) == typeof({}) && handler.constructor.name == 'Object') {
|
|| typeof(handler) == typeof('str')
|
||||||
|
|| typeof(handler) == typeof({})
|
||||||
|
&& handler.constructor.name == 'Object') ){
|
||||||
|
|
||||||
// do the complex handler aliases...
|
// do the complex handler aliases...
|
||||||
if(typeof(handler) == typeof({}) && handler.constructor.name == 'Object'){
|
if(typeof(handler) == typeof({}) && handler.constructor.name == 'Object'){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user