Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

processing keypresses is configurable via key.prekeydown

  • Loading branch information...
commit 951d6edcde42ac271d37a03ecea317d9032f8f14 1 parent 1153827
@dominictarr authored
Showing with 64 additions and 7 deletions.
  1. +8 −3 README.markdown
  2. +12 −4 keymaster.js
  3. +44 −0 npm-debug.log
View
11 README.markdown
@@ -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
16 keymaster.js
@@ -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
44 npm-debug.log
@@ -0,0 +1,44 @@
+info it worked if it ends with ok
+verbose cli [ 'node',
+verbose cli '/home/dominic/.nave/installed/0.6.10/bin/npm',
+verbose cli 'install',
+verbose cli 'uglyify' ]
+info using npm@1.1.0-3
+info using node@v0.6.10
+verbose config file /home/dominic/.npmrc
+verbose config file /home/dominic/.nave/installed/0.6.10/etc/npmrc
+verbose config file /home/dominic/.nave/installed/0.6.10/lib/node_modules/npm/npmrc
+verbose caching /home/dominic/d/keymaster/package.json
+verbose loadDefaults keymaster@1.0.2
+verbose from cache /home/dominic/d/keymaster/package.json
+verbose cache add [ 'uglyify', null ]
+silly cache add: name, spec, args [ undefined, 'uglyify', [ 'uglyify', null ] ]
+verbose parsed url { pathname: 'uglyify', path: 'uglyify', href: 'uglyify' }
+verbose addNamed [ 'uglyify', '' ]
+verbose addNamed [ null, '' ]
+silly name, range, hasData [ 'uglyify', '', false ]
+verbose raw, before any munging uglyify
+verbose url resolving [ 'https://registry.npmjs.org/', './uglyify' ]
+verbose url resolved https://registry.npmjs.org/uglyify
+http GET https://registry.npmjs.org/uglyify
+http 404 https://registry.npmjs.org/uglyify
+silly get cb [ 404,
+silly get cb { server: 'CouchDB/1.1.0 (Erlang OTP/R14B04)',
+silly get cb date: 'Mon, 05 Mar 2012 04:48:45 GMT',
+silly get cb 'content-type': 'application/json',
+silly get cb 'content-length': '52',
+silly get cb 'cache-control': 'must-revalidate' } ]
+ERR! 404 'uglyify' is not in the npm registry.
+ERR! 404 You should bug the author to publish it
+ERR! 404 Note that you can also install from a
+ERR! 404 tarball, folder, or http url, or git url.
+ERR!
+ERR! System Linux 3.0.0-16-generic
+ERR! command "node" "/home/dominic/.nave/installed/0.6.10/bin/npm" "install" "uglyify"
+ERR! cwd /home/dominic/d/keymaster
+ERR! node -v v0.6.10
+ERR! npm -v 1.1.0-3
+ERR! code E404
+ERR! message 404 Not Found: uglyify
+ERR! errno {}
+verbose exit [ 1, true ]
Please sign in to comment.
Something went wrong with that request. Please try again.