Skip to content

Commit

Permalink
Simplify filter scope example
Browse files Browse the repository at this point in the history
  • Loading branch information
madrobby committed Sep 5, 2013
1 parent 96cfc2f commit a2b06f5
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,14 @@ function filter(event){
}
```

If you only want _some_ shortcuts to work while in a input element, you change the scope in the
`key.filter` function - here's an example implementation, setting the scope to either `'input'` or `'other'`.
In this case, it's important to always return `true` from the filter function:
If you only want _some_ shortcuts to work while in an input element, you can change the scope in the
`key.filter` function. Here's an example implementation, setting the scope to either `'input'` or `'other'`.
Don't forget to return `true` so the any shortcuts get processed.

```javascript
key.filter = function(event){
var tagName = (event.target || event.srcElement).tagName;
if ((tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA')) {
// The event is coming from an input field.
key.setScope('input');
}
else {
// The event is coming from somewhere else
key.setScope('other');
}
key.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');
return true;
}
```
Expand Down

0 comments on commit a2b06f5

Please sign in to comment.