mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
added .keyPress(..) action/event...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ae2cb9af7b
commit
1e969e2b13
@ -154,7 +154,7 @@ module.GLOBAL_KEYBOARD2 = {
|
|||||||
meta_Q: 'close',
|
meta_Q: 'close',
|
||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
F5: 'reload!: "full"',
|
F5: 'reload!: "full" -- Reload viewer (full)',
|
||||||
/*F5: keyboard.doc('Reload viewer (full)',
|
/*F5: keyboard.doc('Reload viewer (full)',
|
||||||
function(){
|
function(){
|
||||||
//a.stop()
|
//a.stop()
|
||||||
@ -569,6 +569,62 @@ var KeyboardActions = actions.Actions({
|
|||||||
|
|
||||||
// keyboard handling ----------------------------------------------
|
// keyboard handling ----------------------------------------------
|
||||||
|
|
||||||
|
keyPress: ['- Interface/Handle key or keyboard event',
|
||||||
|
function(key, no_match){
|
||||||
|
var that = this
|
||||||
|
var did_handling = false
|
||||||
|
var res
|
||||||
|
var evt = event
|
||||||
|
|
||||||
|
//if(key instanceof Event || key instanceof $.Event){
|
||||||
|
if(typeof(key) != typeof('str')){
|
||||||
|
evt = key
|
||||||
|
key = keyboard.event2key(evt)
|
||||||
|
}
|
||||||
|
|
||||||
|
var handlers = this.keyboard.handler('?', key)
|
||||||
|
|
||||||
|
Object.keys(handlers).forEach(function(mode){
|
||||||
|
if(res === false){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var handler = handlers[mode]
|
||||||
|
|
||||||
|
// raw function handler...
|
||||||
|
if(handler instanceof Function){
|
||||||
|
res = handler.call(that)
|
||||||
|
|
||||||
|
// action call syntax...
|
||||||
|
} else {
|
||||||
|
var h = keyboard.parseActionCall(handler)
|
||||||
|
|
||||||
|
if(h && h.action in that){
|
||||||
|
did_handling = true
|
||||||
|
|
||||||
|
evt
|
||||||
|
&& h.no_default
|
||||||
|
&& evt.preventDefault()
|
||||||
|
|
||||||
|
// call the handler...
|
||||||
|
res = that[h.action].apply(that, h.arguments)
|
||||||
|
|
||||||
|
evt
|
||||||
|
&& h.stop_propagation
|
||||||
|
&& evt.stopPropagation()
|
||||||
|
&& (res = false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
no_match
|
||||||
|
&& !did_handling
|
||||||
|
&& no_match.call(this, evt, key)
|
||||||
|
|
||||||
|
// XXX not sure if this is the right way to go...
|
||||||
|
return res
|
||||||
|
}],
|
||||||
|
|
||||||
toggleKeyboardHandling: ['- Interface/Keyboard handling',
|
toggleKeyboardHandling: ['- Interface/Keyboard handling',
|
||||||
toggler.Toggler(null, function(_, state){
|
toggler.Toggler(null, function(_, state){
|
||||||
var that = this
|
var that = this
|
||||||
@ -596,7 +652,7 @@ var KeyboardActions = actions.Actions({
|
|||||||
}).bind(this)
|
}).bind(this)
|
||||||
|
|
||||||
// pass keys pressed to .keyPressed(..) action...
|
// pass keys pressed to .keyPressed(..) action...
|
||||||
// XXX EXPERIMENTAL...
|
/*/ XXX EXPERIMENTAL...
|
||||||
var keyPressdCall = function(handler){
|
var keyPressdCall = function(handler){
|
||||||
return that.config['keyboard-key-pressed-action'] == 'on' ?
|
return that.config['keyboard-key-pressed-action'] == 'on' ?
|
||||||
function(evt){
|
function(evt){
|
||||||
@ -612,6 +668,7 @@ var KeyboardActions = actions.Actions({
|
|||||||
}
|
}
|
||||||
: handler
|
: handler
|
||||||
}
|
}
|
||||||
|
//*/
|
||||||
|
|
||||||
var kb = this.__keyboard_object =
|
var kb = this.__keyboard_object =
|
||||||
this.__keyboard_object
|
this.__keyboard_object
|
||||||
@ -635,15 +692,33 @@ var KeyboardActions = actions.Actions({
|
|||||||
&& target.off('keydown', this.__keyboard_handler)
|
&& target.off('keydown', this.__keyboard_handler)
|
||||||
|
|
||||||
// make the base handler...
|
// make the base handler...
|
||||||
|
var handler =
|
||||||
|
keyboard.stoppableKeyboardRepeat(
|
||||||
|
this.keyPress.bind(this),
|
||||||
|
check)
|
||||||
|
/*
|
||||||
|
var handler =
|
||||||
|
keyboard.stoppableKeyboardRepeat(
|
||||||
|
function(evt){
|
||||||
|
return that.keyPress(evt, function(evt, k){
|
||||||
|
window.DEBUG && console.log('KEY:', k) }) },
|
||||||
|
check)
|
||||||
|
//*/
|
||||||
|
/*
|
||||||
var handler =
|
var handler =
|
||||||
keyboard.stoppableKeyboardRepeat(
|
keyboard.stoppableKeyboardRepeat(
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
keyPressdCall(
|
keyPressdCall(
|
||||||
keyboard.makeKeyboardHandler(
|
//this.keyPress.bind(this)),
|
||||||
this.keyboard,
|
function(evt){
|
||||||
function(k){ window.DEBUG && console.log('KEY:', k) },
|
return that.keyPress(evt, function(evt, k){
|
||||||
this)),
|
window.DEBUG && console.log('KEY:', k) }) }),
|
||||||
|
//keyboard.makeKeyboardHandler(
|
||||||
|
// this.keyboard,
|
||||||
|
// function(k){ window.DEBUG && console.log('KEY:', k) },
|
||||||
|
// this)),
|
||||||
check)
|
check)
|
||||||
|
//*/
|
||||||
|
|
||||||
// setup base keyboard for devel, in case something breaks...
|
// setup base keyboard for devel, in case something breaks...
|
||||||
// This branch does not drop keys...
|
// This branch does not drop keys...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user