mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30: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...
|
* XXX needs revision...
|
||||||
* - tasks
|
* - tasks
|
||||||
* XXX not yet used
|
* XXX not yet used
|
||||||
|
* - self-test
|
||||||
|
* basic framework for running test actions at startup...
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|||||||
@ -591,24 +591,11 @@ var KeyboardActions = actions.Actions({
|
|||||||
return true
|
return true
|
||||||
}).bind(this)
|
}).bind(this)
|
||||||
|
|
||||||
//* XXX gen2
|
|
||||||
var kb = this.__keyboard_object =
|
var kb = this.__keyboard_object =
|
||||||
this.__keyboard_object
|
this.__keyboard_object
|
||||||
|| keyboard.Keyboard(
|
|| keyboard.KeyboardWithCSSModes(
|
||||||
function(){ return that.__keyboard_config },
|
function(){ return that.__keyboard_config },
|
||||||
function(mode, keyboard, context){
|
function(){ return that.ribbons.viewer })
|
||||||
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'])
|
|
||||||
//*/
|
|
||||||
|
|
||||||
// start/reset keyboard handling...
|
// start/reset keyboard handling...
|
||||||
if(state == 'on'){
|
if(state == 'on'){
|
||||||
|
|||||||
@ -163,7 +163,7 @@ function parseActionCall(txt){
|
|||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// Helpers...
|
// Helpers and utility functions...
|
||||||
|
|
||||||
// Form standard key string from keyboard event...
|
// 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'],
|
service_fields: ['doc', 'drop'],
|
||||||
|
|
||||||
event2key: event2key,
|
event2key: event2key,
|
||||||
@ -325,7 +327,7 @@ var KeyboardHandlerClassPrototype = {
|
|||||||
shifted: shifted
|
shifted: shifted
|
||||||
}
|
}
|
||||||
|
|
||||||
var KeyboardHandlerPrototype = {
|
var KeyboardPrototype = {
|
||||||
//service_fields: ['doc', 'drop'],
|
//service_fields: ['doc', 'drop'],
|
||||||
special_handlers: {
|
special_handlers: {
|
||||||
DROP: 'drop key',
|
DROP: 'drop key',
|
||||||
@ -365,13 +367,13 @@ var KeyboardHandlerPrototype = {
|
|||||||
//context: null,
|
//context: null,
|
||||||
|
|
||||||
// utils...
|
// utils...
|
||||||
event2key: KeyboardHandlerClassPrototype.event2key,
|
event2key: KeyboardClassPrototype.event2key,
|
||||||
key2code: KeyboardHandlerClassPrototype.key2code,
|
key2code: KeyboardClassPrototype.key2code,
|
||||||
code2key: KeyboardHandlerClassPrototype.code2key,
|
code2key: KeyboardClassPrototype.code2key,
|
||||||
shifted: KeyboardHandlerClassPrototype.shifted,
|
shifted: KeyboardClassPrototype.shifted,
|
||||||
splitKey: KeyboardHandlerClassPrototype.splitKey,
|
splitKey: KeyboardClassPrototype.splitKey,
|
||||||
normalizeKey: KeyboardHandlerClassPrototype.normalizeKey,
|
normalizeKey: KeyboardClassPrototype.normalizeKey,
|
||||||
isKey: KeyboardHandlerClassPrototype.isKey,
|
isKey: KeyboardClassPrototype.isKey,
|
||||||
|
|
||||||
//isModeApplicable: function(mode, keyboard, context){ return true },
|
//isModeApplicable: function(mode, keyboard, context){ return true },
|
||||||
|
|
||||||
@ -751,8 +753,47 @@ var KeyboardHandlerPrototype = {
|
|||||||
var Keyboard =
|
var Keyboard =
|
||||||
module.Keyboard =
|
module.Keyboard =
|
||||||
object.makeConstructor('Keyboard',
|
object.makeConstructor('Keyboard',
|
||||||
KeyboardHandlerClassPrototype,
|
KeyboardClassPrototype,
|
||||||
KeyboardHandlerPrototype)
|
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...
|
// add keyboard handler...
|
||||||
if(this.keybindings && this.dom){
|
if(this.keybindings && this.dom){
|
||||||
var kb = this.keyboard =
|
this.keyboard =
|
||||||
this.keyboard || keyboard.Keyboard(
|
this.keyboard || keyboard.KeyboardWithCSSModes(
|
||||||
function(){ return that.keybindings },
|
function(){ return that.keybindings },
|
||||||
function(mode, keyboard, context){
|
function(){ return that.dom })
|
||||||
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.dom
|
this.dom
|
||||||
.keydown(
|
.keydown(
|
||||||
keyboard.makeKeyboardHandler(
|
keyboard.makeKeyboardHandler(
|
||||||
@ -221,21 +210,10 @@ var ContainerPrototype = {
|
|||||||
|
|
||||||
// add keyboard handler...
|
// add keyboard handler...
|
||||||
if(this.keybindings && this.dom){
|
if(this.keybindings && this.dom){
|
||||||
var kb = this.keyboard =
|
this.keyboard =
|
||||||
this.keyboard || keyboard.Keyboard(
|
this.keyboard || keyboard.KeyboardWithCSSModes(
|
||||||
function(){ return that.keybindings },
|
function(){ return that.keybindings },
|
||||||
function(mode, keyboard, context){
|
function(){ return that.dom })
|
||||||
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.dom
|
this.dom
|
||||||
.keydown(
|
.keydown(
|
||||||
keyboard.makeKeyboardHandler(
|
keyboard.makeKeyboardHandler(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user