From 346b09b4c09f2de96ce08d802f0b784c128e9e77 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 3 May 2013 00:39:29 +0400 Subject: [PATCH] added complex handler aliases to keyboard.js... Signed-off-by: Alex A. Naanou --- ui/ImageGrid.js | 5 +++-- ui/index.html | 11 +++++++++++ ui/lib/keyboard.js | 28 ++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/ui/ImageGrid.js b/ui/ImageGrid.js index 3b6d1121..f99c5d14 100755 --- a/ui/ImageGrid.js +++ b/ui/ImageGrid.js @@ -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) ) } diff --git a/ui/index.html b/ui/index.html index 5e5f8261..8c7c60af 100755 --- a/ui/index.html +++ b/ui/index.html @@ -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() }, diff --git a/ui/lib/keyboard.js b/ui/lib/keyboard.js index 13cede69..3cda974b 100755 --- a/ui/lib/keyboard.js +++ b/ui/lib/keyboard.js @@ -100,7 +100,12 @@ var KEYBOARD_HANDLER_PROPAGATE = true * : , * * : { - * 'default': , + * // 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': | , + * * // 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']