Skip to content

Commit 6b339e6

Browse files
committed
1 parent 68e5b83 commit 6b339e6

File tree

4 files changed

+45
-40
lines changed

4 files changed

+45
-40
lines changed

keymaster/README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ it in.*
1111

1212
## Usage
1313

14-
Include `keymaster.min.js` in your web app, by loading it as usual:
14+
Include `keymaster.js` in your web app*, by loading it as usual:
1515

1616
```html
17-
<script src="keymaster.min.js"></script>
17+
<script src="keymaster.js"></script>
1818
```
1919

2020
Keymaster has no dependencies and can be used completely standalone.
2121
It should not interfere with any JavaScript libraries or frameworks.
2222

23+
_*Preferably use a minified version that fits your workflow. You can
24+
run `make` to have UglifyJS (if you have it installed) create a
25+
`keymaster.min.js` file for you._
26+
2327
## Defining shortcuts
2428

2529
One global method is exposed, `key` which defines shortcuts when
@@ -50,6 +54,7 @@ key('⌘+r, ctrl+r', function(event, handler){
5054
// "ctrl+r", "all"
5155
```
5256

57+
5358
## Supported keys
5459

5560
Keymaster understands the following modifiers:
@@ -60,6 +65,7 @@ The following special keys can be used for shortcuts:
6065
`up`, `down`, `left`, `right`, `home`, `end`, `pageup`, `pagedown`, `del`, `delete`
6166
and `f1` through `f19`.
6267

68+
6369
## Modifier key queries
6470

6571
At any point in time (even in code other than key shortcut handlers),
@@ -71,6 +77,7 @@ allows easy implementation of things like shift+click handlers. For example,
7177
if(key.shift) alert('shift is pressed, OMGZ!');
7278
```
7379

80+
7481
## Other key queries
7582

7683
At any point in time (even in code other than key shortcut handlers),
@@ -91,7 +98,7 @@ key.getPressedKeyCodes() // returns an array of key codes currently pressed
9198

9299
## Scopes
93100

94-
If you want to reuse the same shortcut for seperate areas in your single page app,
101+
If you want to reuse the same shortcut for separate areas in your single page app,
95102
Keymaster supports switching between scopes. Use the `key.setScope` method to set scope.
96103

97104
```javascript
@@ -103,6 +110,7 @@ key('o, enter', 'files', function(){ /* do something else */ });
103110
key.setScope('issues'); // default scope is 'all'
104111
```
105112

113+
106114
## Filter key presses
107115

108116
By default, when an `INPUT`, `SELECT` or `TEXTAREA` element is focused, Keymaster doesn't process any shortcuts.
@@ -136,6 +144,7 @@ key.filter = function(event){
136144
However a more robust way to handle this is to use proper
137145
focus and blur event handlers on your input element, and change scopes there as you see fit.
138146

147+
139148
## noConflict mode
140149

141150
You can call ```key.noConflict``` to remove the ```key``` function from global scope and restore whatever ```key``` was defined to before Keymaster was loaded. Calling ```key.noConflict``` will return the Keymaster ```key``` function.
@@ -148,6 +157,7 @@ key()
148157
// --> TypeError: 'undefined' is not a function
149158
```
150159

160+
151161
## Unbinding shortcuts
152162

153163
Similar to defining shortcuts, they can be unbound using `key.unbind`.
@@ -162,13 +172,15 @@ key.unbind('o, enter', 'issues');
162172
key.unbind('o, enter', 'files');
163173
```
164174

175+
165176
## Notes
166177

167178
Keymaster should work with any browser that fires `keyup` and `keydown` events,
168179
and is tested with IE (6+), Safari, Firefox and Chrome.
169180

170181
See [http://madrobby.github.com/keymaster/](http://madrobby.github.com/keymaster/) for a live demo.
171182

183+
172184
## CoffeeScript
173185

174186
If you're using CoffeeScript, configuring key shortcuts couldn't be simpler:
@@ -186,19 +198,6 @@ key 'o, enter', 'issues', ->
186198
alert 'shift is pressed, OMGZ!' if key.shift
187199
```
188200

189-
## Ender support
190-
191-
Add `keymaster` as a top level method to your [Ender](http://ender.no.de) compilation.
192-
193-
$ ender add keymaster
194-
195-
Use it:
196-
197-
``` js
198-
$.key('⌘+r', function () {
199-
alert('reload!')
200-
})
201-
```
202201

203202
## Contributing
204203

@@ -211,3 +210,4 @@ submit a pull request.
211210

212211
Keymaster is (c) 2011-2013 Thomas Fuchs and may be freely distributed under the MIT license.
213212
See the `MIT-LICENSE` file.
213+

keymaster/dist/keymaster-debug.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// keymaster.js
2-
// (c) 2011-2012 Thomas Fuchs
2+
// (c) 2011-2013 Thomas Fuchs
33
// keymaster.js may be freely distributed under the MIT license.
4-
define("gallery/keymaster/1.0.2/keymaster-debug", [], function(require, exports, module) {
4+
define("gallery/keymaster/1.6.2/keymaster-debug", [], function(require, exports, module) {
55
var global = {};
66
var k, _handlers = {}, _mods = {
77
16: false,
@@ -79,8 +79,8 @@ define("gallery/keymaster/1.0.2/keymaster-debug", [], function(require, exports,
7979
for (k in _mods) _mods[k] = event[modifierMap[k]];
8080
}
8181
// handle keydown event
82-
function dispatch(event, scope) {
83-
var key, handler, k, i, modifiersMatch;
82+
function dispatch(event) {
83+
var key, handler, k, i, modifiersMatch, scope;
8484
key = event.keyCode;
8585
if (index(_downKeys, key) == -1) {
8686
_downKeys.push(key);
@@ -100,6 +100,7 @@ define("gallery/keymaster/1.0.2/keymaster-debug", [], function(require, exports,
100100
if (!assignKey.filter.call(this, event)) return;
101101
// abort if no potentially matching shortcuts found
102102
if (!(key in _handlers)) return;
103+
scope = getScope();
103104
// for each potential shortcut
104105
for (i = 0; i < _handlers[key].length; i++) {
105106
handler = _handlers[key][i];
@@ -169,23 +170,27 @@ define("gallery/keymaster/1.0.2/keymaster-debug", [], function(require, exports,
169170
}
170171
// unbind all handlers for given key in current scope
171172
function unbindKey(key, scope) {
172-
var keys = key.split("+"), mods = [], i, obj;
173-
if (keys.length > 1) {
174-
mods = getMods(keys);
175-
key = keys[keys.length - 1];
176-
}
177-
key = code(key);
178-
if (scope === undefined) {
179-
scope = getScope();
180-
}
181-
if (!_handlers[key]) {
182-
return;
183-
}
184-
for (i in _handlers[key]) {
185-
obj = _handlers[key][i];
186-
// only clear handlers if correct scope and mods match
187-
if (obj.scope === scope && compareArray(obj.mods, mods)) {
188-
_handlers[key][i] = {};
173+
var multipleKeys, keys, mods = [], i, j, obj;
174+
multipleKeys = getKeys(key);
175+
for (j = 0; j < multipleKeys.length; j++) {
176+
keys = multipleKeys[j].split("+");
177+
if (keys.length > 1) {
178+
mods = getMods(keys);
179+
key = keys[keys.length - 1];
180+
}
181+
key = code(key);
182+
if (scope === undefined) {
183+
scope = getScope();
184+
}
185+
if (!_handlers[key]) {
186+
return;
187+
}
188+
for (i = 0; i < _handlers[key].length; i++) {
189+
obj = _handlers[key][i];
190+
// only clear handlers if correct scope and mods match
191+
if (obj.scope === scope && compareArray(obj.mods, mods)) {
192+
_handlers[key][i] = {};
193+
}
189194
}
190195
}
191196
}
@@ -248,7 +253,7 @@ define("gallery/keymaster/1.0.2/keymaster-debug", [], function(require, exports,
248253
}
249254
// set the handlers globally on document
250255
addEvent(document, "keydown", function(event) {
251-
dispatch(event, _scope);
256+
dispatch(event);
252257
});
253258
// Passing _scope to a callback to ensure it remains the same by execution. Fixes #48
254259
addEvent(document, "keyup", clearModifier);

keymaster/dist/keymaster.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

keymaster/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "keymaster",
33
"family": "gallery",
4-
"version": "1.0.2",
4+
"version": "1.6.2",
55
"package": "https://raw.github.com/madrobby/keymaster/master/package.json",
66
"homepage": "https://github.com/madrobby/keymaster",
77
"description": "library for defining and dispatching keyboard shortcuts",

0 commit comments

Comments
 (0)