mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
new kb ready for testing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
72757fe2ae
commit
88e8c1b9cb
@ -892,11 +892,9 @@ var Keyboard2HandlerProto = {
|
|||||||
.concat([ k, c ])
|
.concat([ k, c ])
|
||||||
.unique()
|
.unique()
|
||||||
|
|
||||||
var dropped = (mode == 'applicable' || mode == '?') ? false : null
|
var drop = mode == 'applicable' || mode == '?'
|
||||||
modes.forEach(function(m){
|
for(var i=0; i < modes.length; i++){
|
||||||
if(dropped == true){
|
var m = modes[i]
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var bindings = keyboard[m]
|
var bindings = keyboard[m]
|
||||||
|
|
||||||
@ -905,20 +903,28 @@ var Keyboard2HandlerProto = {
|
|||||||
keys
|
keys
|
||||||
.filter(function(k){ return bindings[k] })[0])
|
.filter(function(k){ return bindings[k] })[0])
|
||||||
|
|
||||||
|
// handle explicit IGNORE...
|
||||||
|
if(drop && handler == 'IGNORE'){
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
// we got a match...
|
||||||
if(handler){
|
if(handler){
|
||||||
res[m] = handler
|
res[m] = handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if key in .drop then ignore the rest...
|
||||||
dropped = dropped === false
|
if(drop
|
||||||
&& (bindings.drop == '*'
|
&& (bindings.drop == '*'
|
||||||
// XXX should this be more flexible by adding a
|
// XXX should this be more flexible by adding a
|
||||||
// specific key combo?
|
// specific key combo?
|
||||||
// ... if yes, we'll need to differentiate
|
// ... if yes, we'll need to differentiate
|
||||||
// between X meaning drop only X and drop
|
// between X meaning drop only X and drop
|
||||||
// all combos with X...
|
// all combos with X...
|
||||||
|| (bindings.drop || []).indexOf(k))
|
|| (bindings.drop || []).indexOf(k) >= 0)){
|
||||||
})
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (typeof(mode) == typeof('str')
|
return (typeof(mode) == typeof('str')
|
||||||
&& ['*', 'applicable', '?'].indexOf(mode) < 0) ?
|
&& ['*', 'applicable', '?'].indexOf(mode) < 0) ?
|
||||||
@ -958,6 +964,7 @@ var Keyboard2HandlerProto = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*/ XXX for testing...
|
||||||
var kb = window.kb = Object.create(Keyboard2HandlerProto)
|
var kb = window.kb = Object.create(Keyboard2HandlerProto)
|
||||||
kb.keyboard = GLOBAL_KEYBOARD2
|
kb.keyboard = GLOBAL_KEYBOARD2
|
||||||
kb.isModeApplicable = function(mode, context){
|
kb.isModeApplicable = function(mode, context){
|
||||||
@ -966,6 +973,51 @@ kb.isModeApplicable = function(mode, context){
|
|||||||
|| pattern == '*'
|
|| pattern == '*'
|
||||||
|| $(this.keyboard[mode].pattern).length > 0
|
|| $(this.keyboard[mode].pattern).length > 0
|
||||||
}
|
}
|
||||||
|
//*/
|
||||||
|
|
||||||
|
|
||||||
|
// XXX this is not compatible with GLOBAL_KEYBOARD use GLOBAL_KEYBOARD2!!
|
||||||
|
function makeKeyboardHandler(keyboard, unhandled, actions){
|
||||||
|
var kb = Object.create(Keyboard2HandlerProto)
|
||||||
|
kb.keyboard = keyboard
|
||||||
|
// XXX this is specific to ImageGrid ...
|
||||||
|
kb.isModeApplicable = function(mode, context){
|
||||||
|
var pattern = this.keyboard[mode].pattern
|
||||||
|
return !pattern
|
||||||
|
|| pattern == '*'
|
||||||
|
|| $(this.keyboard[mode].pattern).length > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return function(evt){
|
||||||
|
var res
|
||||||
|
var did_handling = false
|
||||||
|
var key = kb.event2key(evt)
|
||||||
|
var handlers = kb.handler('applicable', key)
|
||||||
|
|
||||||
|
Object.keys(handlers).forEach(function(mode){
|
||||||
|
// XXX do we need this???
|
||||||
|
if(res === false){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var h = keyboard.parseActionCall(handlers[mode])
|
||||||
|
|
||||||
|
if(h && h.action in actions){
|
||||||
|
did_handling = true
|
||||||
|
|
||||||
|
h.no_default
|
||||||
|
&& evt.preventDefault()
|
||||||
|
|
||||||
|
// call the handler...
|
||||||
|
res = actions[h.action].apply(actions, h.args)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
unhandled
|
||||||
|
&& !did_handling
|
||||||
|
&& unhandled.call(actions, evt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user