3 ms·
Hmm. Binds all events to `document`, which means that if you type something in a text field, it'll still trigger the event. (One of the TODOs is "Make behavior
by TrevorBurnham 15y ago
Hmm. Binds all events to `document`, which means that if you type something in a text field, it'll still trigger the event. (One of the TODOs is "Make behavior with INPUT / SELECT / TEXTAREA configurable.)
Thing is, jQuery Hotkeys (https://github.com/jeresig/jquery.hotkeys https://github.com/jeresig/jquery.hotkeys) is more versatile (since you can bind events to any element), works under a wider range of browsers, and is nearly as lightweight (if you already depend on jQuery).
Though, I do like the hipness of using "⌥" and "⌘" instead of "alt" and "meta". I might make a fork of jQuery Hotkeys just for that.
- maratd 15y agoWe don't use Keymaster, but our homebrew solution works the same way. You can solve the problem by adding an event to elements that you don't want to react that stops bubbling. Since those elements are focused when a key is pressed, the event for that element will be triggered first. Our form validation script adds this automatically. Problem solved.
- madrobby 15y agoIt doesn't trigger events if you're in a INPUT/TEXTAREA/SELECT. The todo refers to making this configurable in a per-shortcut fashion.
- TrevorBurnham 15y agoAh, my bad. I didn't catch the line "if (tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA') return;", which is indeed a sensible default.
- deleted 15y ago[deleted]
- fbnt 15y agoI recently had the need of using multiple hotkeys for a web application I'm building. I tried jQuery hotkeys but I had to drop it for a number of reasons: First of all is the unbind problem (well documented on their bug-tracker), if you bind N different keys combination, the callback function for each hotkey is called N times, and that's really annoying and there are no easy workaround. Other than that, not all keys combination are supported, some keys just doesen't work, and it also bind keys per value instead of code: it's basically designed for american keyboards only, the same key value might have different key-codes for different keyboard layouts. So I came up with a simple homemade solution that words flawlessly for my needs: http://jsfiddle.net/2Saj8/ http://jsfiddle.net/2Saj8/ I'm looking forward to try out keymaster.js though.
- TrevorBurnham 15y agoIn case anyone wants it, here's my unicode-friendly fork of jQuery Hotkeys: https://github.com/TrevorBurnham/jquery.hotkeys https://github.com/TrevorBurnham/jquery.hotkeys Note that because of the way the library works, you can only use the unicode equivalents on this fork—aliases like "ctrl" and "alt" will not work. (jQuery Hotkeys was written with a pretty hardcore approach to efficiency, so everything is 1:1. Keymaster uses an `indexOf` search each time a key is pressed, which has a negligible impact on performance in modern browsers.)