added complex handler aliases to keyboard.js...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-05-03 00:39:29 +04:00
parent e32384b64d
commit 346b09b4c0
3 changed files with 38 additions and 6 deletions

View File

@ -176,6 +176,7 @@ function createRibbon(){
* Modes
*/
// XXX shifting images and unmarking in this mode do not work correctly...
var toggleMarkedOnlyView = createCSSClassToggler('.viewer', 'marked-only',
function(){
var cur = $('.current.image')
@ -522,6 +523,7 @@ function markAll(mode){
}
}
// NOTE: this only does it's work in the current ribbon...
function invertImageMarks(){
return $('.current.image')
.closest('.ribbon')
@ -559,8 +561,7 @@ function toggleImageMarkBlock(image){
function clickHandler(evt){
var img = $(evt.target).closest('.image')
centerImage(
focusImage(img))
centerImage( focusImage(img) )
}

View File

@ -281,6 +281,10 @@ var KEYBOARD_CONFIG = {
}
*/
},
Space: {
default: 'Right',
shift: 'Left',
},
Home: function(){
firstImage()
@ -304,6 +308,13 @@ var KEYBOARD_CONFIG = {
F: function(){ toggleImageProportions() },
// XXX not final, think of a better way to do this...
I: {
shift: function(){ invertImageMarks() },
},
A: {
shift: function(){ toggleImageMarkBlock() },
ctrl: function(){ markAll('ribbon') },
},
M: {
default: function(){ toggleImageMark() },
shift: function(){ toggleMarkedOnlyView() },

View File

@ -100,7 +100,12 @@ var KEYBOARD_HANDLER_PROPAGATE = true
* <key-def> : <callback>,
*
* <key-def> : {
* 'default': <callback>,
* // modifiers can either have a callback or an alias as
* // a value...
* // NOTE: when the alias is resolved, the same modifiers
* // will be applied to the final resolved handler.
* 'default': <callback> | <key-def-x>,
*
* // a modifier can be any single modifier, like shift or a
* // combination of modifers like 'ctrl+shift', given in order
* // of priority.
@ -171,11 +176,26 @@ function makeKeyboardHandler(keybindings, unhandled){
}
// alias...
while (typeof(handler) == typeof(123) || typeof(handler) == typeof('str')) {
while (typeof(handler) == typeof(123)
|| typeof(handler) == typeof('str')
|| typeof(handler) == typeof({}) && handler.constructor.name == 'Object') {
// do the complex handler aliases...
if(typeof(handler) == typeof({}) && handler.constructor.name == 'Object'){
if(typeof(handler[modifers]) == typeof('str')){
handler = handler[modifers]
} else if(typeof(handler['default']) == typeof('str')){
handler = handler['default']
} else {
break
}
}
// simple handlers...
if(handler in bindings){
// XXX need to take care of that we can always be a number or a string...
handler = bindings[handler]
} else if(typeof(h) == typeof(1)) {
} else if(typeof(handler) == typeof(1)) {
handler = bindings[toKeyName(handler)]
} else {
handler = bindings[toKeyCode(handler)]
@ -200,7 +220,7 @@ function makeKeyboardHandler(keybindings, unhandled){
handler = handler[0]
}
// complex handler...
if(typeof(handler) == typeof({})){
if(typeof(handler) == typeof({}) && handler.constructor.name == 'Object'){
var callback = handler[modifers]
if(callback == null){
callback = handler['default']