reworked the key handler a bit...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2012-09-10 04:23:48 +04:00
parent f4ff9adcba
commit 4f8ebda91c
2 changed files with 60 additions and 43 deletions

View File

@ -1483,13 +1483,17 @@ function makeKeyboardHandler(keybindings, unhandled){
unhandled = function(){return false}
}
return function(evt){
var did_handling = false
var res = null
for(var mode in keybindings){
if($(mode).length > 0){
var bindings = keybindings[mode]
var key = evt.keyCode
if(bindings.ignore != null && bindings.ignore.indexOf(key) != -1){
return true
// return true
did_handling = true
continue
}
// XXX ugly...
var modifers = evt.ctrlKey ? 'ctrl' : ''
@ -1504,7 +1508,7 @@ function makeKeyboardHandler(keybindings, unhandled){
}
// no handler...
if(handler == null){
return unhandled(key)
continue
}
// Array, lisp style with docs...
// XXX for some odd reason in chrome typeof([]) == typeof({})!!!
@ -1519,17 +1523,25 @@ function makeKeyboardHandler(keybindings, unhandled){
callback = handler['default']
}
if(callback != null){
var res = callback()
return KEYBOARD_HANDLER_PROPAGATE&&res?true:false
res = callback()
did_handling = true
continue
}
} else {
// simple callback...
var res = handler()
return KEYBOARD_HANDLER_PROPAGATE&&res?true:false
res = handler()
did_handling = true
continue
}
return unhandled(key)
}
}
if(!did_handling){
// key is unhandled by any modes...
return unhandled(key)
} else {
// XXX should we handle multiple hits???
return KEYBOARD_HANDLER_PROPAGATE&&res?true:false
}
}
}

View File

@ -2,31 +2,11 @@
// NOTE: use String.fromCharCode(code)...
// list of keys to be ignored by handler but still handled by the browser...
var keybindings = {
'.overlay-mode': {
title: 'Overlay mode',
doc: 'overlay mode key bindings.',
ignore: [
37, // Left
39, // Right
36, // Home
32, // Space
35, // End
38, // Up
40, // Down
],
27: ImageGrid.closeOverlay, // Esc
},
//'*': {
// everything except overlays...
'.viewer *:not(.overlay-mode *)': {
title: 'ALL',
doc: 'global key bindings.',
// global bindings...
'*': {
title: 'Global',
doc: '',
ignore: [
116, // F5
@ -53,6 +33,43 @@ var keybindings = {
27: ImageGrid.closeOverlay, // Esc
// ignore the modifiers (shift, alt, ctrl, caps)...
16: function(){},
17: 16,
18: 16,
20: 16, // Caps Lock
// refresh...
// XXX make this into a real action...
116: function(){ return DEBUG?true:false }, // F5
112: 116, // F12
},
// overlay...
'.overlay-mode': {
title: 'Overlay mode',
doc: 'Overlay mode key bindings.',
ignore: [
33, // PgUp
34, // PgDown
37, // Left
39, // Right
36, // Home
32, // Space
35, // End
38, // Up
40, // Down
],
},
// everything except overlays...
'.viewer *:not(.overlay-mode *)': {
title: 'Ribbon and Viewer',
doc: '',
// zooming...
187: ImageGrid.scaleContainerUp, // +
189: ImageGrid.scaleContainerDown, // -
@ -118,18 +135,6 @@ var keybindings = {
// misc actions...
82: ImageGrid.reverseImageOrder, // r
// ignore the modifiers (shift, alt, ctrl, caps)...
16: function(){},
17: 16,
18: 16,
20: 16, // Caps Lock
// refresh...
// XXX make this into a real action...
116: function(){ return DEBUG?true:false }, // F5
112: 116, // F12
}
}