mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +00:00
added a common case specialization to keyboard.js -- KeyboardWithCSSModes(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
60f5431155
commit
55a6c106ec
@ -25,6 +25,8 @@
|
||||
* XXX needs revision...
|
||||
* - tasks
|
||||
* XXX not yet used
|
||||
* - self-test
|
||||
* basic framework for running test actions at startup...
|
||||
*
|
||||
*
|
||||
*
|
||||
|
||||
@ -591,24 +591,11 @@ var KeyboardActions = actions.Actions({
|
||||
return true
|
||||
}).bind(this)
|
||||
|
||||
//* XXX gen2
|
||||
var kb = this.__keyboard_object =
|
||||
this.__keyboard_object
|
||||
|| keyboard.Keyboard(
|
||||
|| keyboard.KeyboardWithCSSModes(
|
||||
function(){ return that.__keyboard_config },
|
||||
function(mode, keyboard, context){
|
||||
var pattern = keyboard[mode].pattern || mode
|
||||
var target = that.ribbons.viewer
|
||||
return !pattern
|
||||
|| pattern == '*'
|
||||
// XXX legacy...
|
||||
//|| $(pattern).length > 0
|
||||
// XXX can we join these into one search???
|
||||
|| target.is(pattern)
|
||||
|| target.find(pattern).length > 0
|
||||
})
|
||||
kb.service_fields = kb.constructor.service_fields.concat(['pattern'])
|
||||
//*/
|
||||
function(){ return that.ribbons.viewer })
|
||||
|
||||
// start/reset keyboard handling...
|
||||
if(state == 'on'){
|
||||
|
||||
@ -163,7 +163,7 @@ function parseActionCall(txt){
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Helpers...
|
||||
// Helpers and utility functions...
|
||||
|
||||
// Form standard key string from keyboard event...
|
||||
//
|
||||
@ -311,9 +311,11 @@ function shifted(key){
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
var KeyboardHandlerClassPrototype = {
|
||||
/*********************************************************************/
|
||||
// Generic keyboard handler...
|
||||
|
||||
var KeyboardClassPrototype = {
|
||||
service_fields: ['doc', 'drop'],
|
||||
|
||||
event2key: event2key,
|
||||
@ -325,7 +327,7 @@ var KeyboardHandlerClassPrototype = {
|
||||
shifted: shifted
|
||||
}
|
||||
|
||||
var KeyboardHandlerPrototype = {
|
||||
var KeyboardPrototype = {
|
||||
//service_fields: ['doc', 'drop'],
|
||||
special_handlers: {
|
||||
DROP: 'drop key',
|
||||
@ -365,13 +367,13 @@ var KeyboardHandlerPrototype = {
|
||||
//context: null,
|
||||
|
||||
// utils...
|
||||
event2key: KeyboardHandlerClassPrototype.event2key,
|
||||
key2code: KeyboardHandlerClassPrototype.key2code,
|
||||
code2key: KeyboardHandlerClassPrototype.code2key,
|
||||
shifted: KeyboardHandlerClassPrototype.shifted,
|
||||
splitKey: KeyboardHandlerClassPrototype.splitKey,
|
||||
normalizeKey: KeyboardHandlerClassPrototype.normalizeKey,
|
||||
isKey: KeyboardHandlerClassPrototype.isKey,
|
||||
event2key: KeyboardClassPrototype.event2key,
|
||||
key2code: KeyboardClassPrototype.key2code,
|
||||
code2key: KeyboardClassPrototype.code2key,
|
||||
shifted: KeyboardClassPrototype.shifted,
|
||||
splitKey: KeyboardClassPrototype.splitKey,
|
||||
normalizeKey: KeyboardClassPrototype.normalizeKey,
|
||||
isKey: KeyboardClassPrototype.isKey,
|
||||
|
||||
//isModeApplicable: function(mode, keyboard, context){ return true },
|
||||
|
||||
@ -751,8 +753,47 @@ var KeyboardHandlerPrototype = {
|
||||
var Keyboard =
|
||||
module.Keyboard =
|
||||
object.makeConstructor('Keyboard',
|
||||
KeyboardHandlerClassPrototype,
|
||||
KeyboardHandlerPrototype)
|
||||
KeyboardClassPrototype,
|
||||
KeyboardPrototype)
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Keyboard handler with modes identified by CSS selectors...
|
||||
|
||||
var KeyboardWithCSSModesPrototype = {
|
||||
service_fields: ['doc', 'drop', 'pattern'],
|
||||
|
||||
isModeApplicable: function(mode, keyboard, context){
|
||||
var pattern = keyboard[mode].pattern || mode
|
||||
context = context || this.context
|
||||
return !pattern
|
||||
|| pattern == '*'
|
||||
// XXX can we join these into one search???
|
||||
|| context.is(pattern)
|
||||
|| context.find(pattern).length > 0
|
||||
},
|
||||
|
||||
__init__: function(keyboard, context){
|
||||
object.superMethod(KeyboardWithCSSModes, '__init__').call(this, keyboard)
|
||||
|
||||
if(context instanceof Function){
|
||||
Object.defineProperty(this, 'context', {
|
||||
get: context,
|
||||
})
|
||||
|
||||
} else {
|
||||
this.context = context
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
var KeyboardWithCSSModes =
|
||||
module.KeyboardWithCSSModes =
|
||||
object.makeConstructor('KeyboardWithCSSModes',
|
||||
KeyboardClassPrototype,
|
||||
KeyboardWithCSSModesPrototype)
|
||||
// inherit from Keyboard...
|
||||
KeyboardWithCSSModes.prototype.__proto__ = Keyboard.prototype
|
||||
|
||||
|
||||
|
||||
|
||||
@ -132,21 +132,10 @@ var WidgetPrototype = {
|
||||
|
||||
// add keyboard handler...
|
||||
if(this.keybindings && this.dom){
|
||||
var kb = this.keyboard =
|
||||
this.keyboard || keyboard.Keyboard(
|
||||
function(){ return that.keybindings },
|
||||
function(mode, keyboard, context){
|
||||
var pattern = keyboard[mode].pattern || mode
|
||||
var target = that.dom
|
||||
return !pattern
|
||||
|| pattern == '*'
|
||||
// XXX can we join these into one search???
|
||||
|| target.is(pattern)
|
||||
|| target.find(pattern).length > 0
|
||||
})
|
||||
kb.service_fields = kb.constructor.service_fields
|
||||
.concat(['pattern'])
|
||||
.unique()
|
||||
this.keyboard =
|
||||
this.keyboard || keyboard.KeyboardWithCSSModes(
|
||||
function(){ return that.keybindings },
|
||||
function(){ return that.dom })
|
||||
this.dom
|
||||
.keydown(
|
||||
keyboard.makeKeyboardHandler(
|
||||
@ -221,21 +210,10 @@ var ContainerPrototype = {
|
||||
|
||||
// add keyboard handler...
|
||||
if(this.keybindings && this.dom){
|
||||
var kb = this.keyboard =
|
||||
this.keyboard || keyboard.Keyboard(
|
||||
function(){ return that.keybindings },
|
||||
function(mode, keyboard, context){
|
||||
var pattern = keyboard[mode].pattern || mode
|
||||
var target = that.dom
|
||||
return !pattern
|
||||
|| pattern == '*'
|
||||
// XXX can we join these into one search???
|
||||
|| target.is(pattern)
|
||||
|| target.find(pattern).length > 0
|
||||
})
|
||||
kb.service_fields = kb.constructor.service_fields
|
||||
.concat(['pattern'])
|
||||
.unique()
|
||||
this.keyboard =
|
||||
this.keyboard || keyboard.KeyboardWithCSSModes(
|
||||
function(){ return that.keybindings },
|
||||
function(){ return that.dom })
|
||||
this.dom
|
||||
.keydown(
|
||||
keyboard.makeKeyboardHandler(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user