Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jokeyrhyme/scoped-mousetrap
add support for switching scopes to Mousetrap https://github.com/ccampbell/mousetrap
https://github.com/jokeyrhyme/scoped-mousetrap
Last synced: 21 days ago
JSON representation
add support for switching scopes to Mousetrap https://github.com/ccampbell/mousetrap
- Host: GitHub
- URL: https://github.com/jokeyrhyme/scoped-mousetrap
- Owner: jokeyrhyme
- License: mit
- Created: 2013-10-23T11:07:56.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2016-12-16T04:16:24.000Z (almost 8 years ago)
- Last Synced: 2024-10-14T21:23:38.761Z (25 days ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# scoped-mousetrap
add support for switching scopes to Mousetrap https://github.com/ccampbell/mousetrap
## Getting Started
Include the original Mousetrap library plus `scoped-mousetrap.js` in your web
project.## Documentation
`window.ScopedMousetrap` will be installed as a singleton. You may also use it
via AMD with something like Require.JS.Note: this does not (yet) support more complex features of Mousetrap like key
sequences. Only simple key and key-combinations are supported.### JavaScript API
#### .on(keys, scope, handler)
- **keys**, String[] or String: key(s) to bind
- **scope**, String: name of the scope to incorporate this bind (optional, default="*")
- **handler**, Function: event handler to be executed when the key is pressedRecords a binding against a specific scope. Neither the binding nor the scope are
automatically enabled.#### .scopes(scopes)
- **scopes**, String[] or String: scope(s) to activate
Returns the previously active set of scopes. Replaces the previously active set
of scopes with the provided set of scopes. Bindings within the provided scopes
are activated, all other bindings are deactivated.#### .binds()
Returns an Object data structure of all binds, grouped by scope.
#### .activeBinds()
Returns a String[] of currently bound keys.
#### .reset()
Forgets all binds and scopes and wipes Mousetrap clean.
### Example
```javascript
ScopedMousetrap.on('esc', 'normal', function () { /* ... */ });
ScopedMousetrap.on('esc', 'specific', function () { /* ... */ });ScopedMousetrap.scopes('normal'); // returns []
// now the first handler is bound to the "escape" keyScopedMousetrap.scopes('specific'); // returns ['normal']
// now the second handler is bound to the "escape" key
```## Contributing
Formal style-guide for this project is JSLint. See JSLint settings at the top of
each file.Add unit tests for any new or changed functionality. Lint and test your code
using [Grunt](http://gruntjs.com/).grunt test
This project uses [Git Flow](https://github.com/nvie/gitflow), so the master
branch always reflects what is in production (i.e. what is in the NPM repository).
New code should be merged into the develop branch.## Release History
See [GitHub Releases](https://github.com/jokeyrhyme/scoped-mousetrap/releases)
## License
Copyright (c) 2013 Ron Waldon
Licensed under the MIT license.