Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jayphelps/shortcut.js

Add keyboard shortcuts that simulate an element being clicked
https://github.com/jayphelps/shortcut.js

Last synced: 21 days ago
JSON representation

Add keyboard shortcuts that simulate an element being clicked

Awesome Lists containing this project

README

        

# *This project is woefully outdated, incomplete, and naive. Don't use it, much better projects exist. Only keeping for historical reasons*

Shortcut.js
======

Add keyboard shortcuts for your HTML elements to make your web app more accessible. Triggers a click event on the targeted element; usually on anchor (i.e. "a") tags but works on any, including plain old divs.

NOTE: If all you want is simple one character shortcuts on elements that allow focus, you should just use the [accesskey](http://en.wikipedia.org/wiki/Access_key) HTML attribute built into every modern browser.

Getting Started
---------------

### Add through markup

``` html
Some Url>
```

### Add through JavaScript

``` javascript
var element = document.getElementById('foo');
var shortcut = Shortcut.add(element, 'ctrl+a+b');
```

### Remove through JavaScript

If you have a reference to the added Shortcut instance you can simply call .remove(); on it.

``` javascript
shortcut.remove();
```
Alternatively, you can call .remove() on the global Shortcut object, passing in the element node and shortcut string.

``` javascript
Shortcut.remove(element, 'ctrl+a+b');
```

### Compatibility

* Not all keys are implemented yet and certain browser quirks aren't normalized. This is on my todo.

* Although it doesn't require jQuery, Shortcut.js currently attempts to auto-initialize itself using jQuery's DOM Ready helper. If not available, it falls back to DOMContentLoaded or window onload for older IE.

License
------------

MIT Licensed
http://www.opensource.org/licenses/mit-license.php