make behaviour in input, select, and textarea configurable. #33

Merged
merged 3 commits into from Mar 21, 2012
View
@@ -83,10 +83,15 @@ key('o, enter', 'files', function(){ /* do something else */ });
key.setScope('issues'); // default scope is 'all'
```
-## Notes
+## Veto keypresses
+
+By default, when in an `INPUT`, `SELECT` or `TEXTAREA` element is focused, Keymaster doesn't process any shortcuts.
+
+You can change this by overwriting `key.prekeydown` with a new function.
-When an `INPUT`, `SELECT` or `TEXTAREA` element is focused, Keymaster
-doesn't process shortcuts.
+If your function returns false, then the no shortcuts will be processed. If you only want _some_ shortcuts to work while in a input element, you can change the scope in the key.prekeydown funtcion
+
+## Notes
Keymaster should work with any browser that fires `keyup` and `keydown` events,
and is tested with IE (6+), Safari, Firefox and Chrome.
View
@@ -41,8 +41,7 @@
// handle keydown event
function dispatch(event){
- var key, tagName, handler, k, i, modifiersMatch;
- tagName = (event.target || event.srcElement).tagName;
+ var key, handler, k, i, modifiersMatch;
key = event.keyCode;
// if a modifier key, set the key.<modifierkeyname> property to true and return
@@ -54,8 +53,10 @@
return;
}
- // ignore keypressed in any elements that support keyboard data input
- if (tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA') return;
+ //need a prekeydown hook, so that this can be overridden.
+ //by default, this will ignore key presses if a select, textarea, or input is focused.
+ //but it can be overridden so that it's possible to say, change the scope.
+ if(assignKey.prekeydown.call(this, event) === false) return;
// abort if no potentially matching shortcuts found
if (!(key in _handlers)) return;
@@ -131,6 +132,13 @@
}
};
+ assignKey.prekeydown = function (e) {
+ var tagName = (event.target || event.srcElement).tagName;
+ // ignore keypressed in any elements that support keyboard data input
+ if (tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA')
+ return false;
+ }
+
// initialize key.<modifier> to false
for(k in _MODIFIERS) assignKey[k] = false;
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.