├── README └── jquery.hotkeys.js /README: -------------------------------------------------------------------------------- 1 | NOTE: This repository is no longer supported or updated by GitHub. If you wish to continue to develop this code yourself, we recommend you fork it. 2 | 3 | This project is an extraction from GitHub. 4 | 5 | For this and other extractions, see http://github.com/github 6 | -------------------------------------------------------------------------------- /jquery.hotkeys.js: -------------------------------------------------------------------------------- 1 | //// 2 | // simple hotkeys plugin. 3 | // 4 | // all 5 | // 6 | // $.hotkey('a', function() { window.location = 'somewhere' }) 7 | // 8 | // $.hotkeys({ 9 | // 'a': function() { window.location = 'somewhere' }, 10 | // 'b': function() { alert('something else') } 11 | // }) 12 | // 13 | (function($) { 14 | $.hotkeys = function(options) { 15 | for(key in options) $.hotkey(key, options[key]) 16 | return this 17 | } 18 | 19 | // accepts a function or url 20 | $.hotkey = function(key, value) { 21 | $.hotkeys.cache[key.charCodeAt(0) - 32] = value 22 | return this 23 | } 24 | 25 | $.hotkeys.cache = {} 26 | })(jQuery) 27 | 28 | jQuery(document).ready(function($) { 29 | $('a[hotkey]').each(function() { 30 | $.hotkey($(this).attr('hotkey'), $(this).attr('href')) 31 | }) 32 | 33 | $(document).bind('keydown.hotkey', function(e) { 34 | // don't hotkey when typing in an input 35 | if ($(e.target).is(':input')) return 36 | // no modifiers supported 37 | if (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) return true 38 | var el = $.hotkeys.cache[e.keyCode] 39 | if (el) $.isFunction(el) ? el.call(this) : window.location = el 40 | }) 41 | }); 42 | --------------------------------------------------------------------------------