Tuesday, August 22, 2006
Recently I needed to add hotkeys to our application for quick navigation. The result of this work is the Hotkey plugin, which I’m releasing today.
The Hotkey plugin consists of a Javascript file and three helpers that use it. You can add a hotkey using Javascript directly using the Hotkey.add() function in your application.js, or you can use the helpers in your templates. Here’s a few examples of helper usage:
<%= hotkey_to_remote :d, :url => {:controller=>’some_controller’} %> <%= hotkey_to :h, :controller => ‘home’ %>
<%= hotkey_to_function :p, “showPreferencesPanel();” %>
Here we’ve defined three hotkeys; d, h, and p. Pressing a modifier key (which modifier key depends on the browser/platform you’re using) and the letter activates the associated function.
The plugin is very easy to use, and suits our needs. Hopefully it will help out a few others.
Update 2008-03-09: You can get the Hotkey plugin at http://github.com/bruce/hotkey; feel free to fork it and send me pull requests :-)
Take a look at the README after installation for additional setup information.
Welcome to the personal website of Bruce Williams, longtime Rubyist, graphic designer, language enthusiast, amateur chef, and oil painter of little skill. I am a work in progress.
I have the good fortune to write code for a living. Take a peek at my work and personal projects.
Read more about me here.