Created
November 6, 2012 04:18
-
-
Save mahemoff/4022515 to your computer and use it in GitHub Desktop.
Mousetrap.js support for Bootstrap with help dialog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monkey-patch stopCallback so that Mousetrap will ignore any keyboard action during modal | |
((originalStopCallback) -> Mousetrap.stopCallback = -> | |
return true if $('body.modal-open').length | |
originalStopCallback.apply(Mousetrap, arguments) | |
)(Mousetrap.stopCallback) | |
# "?" key will produce keyboard shortcuts dialog (as on Twitter and GitHub) | |
# It fetches the dialog content on demand for performance reasons | |
Mousetrap.bind '?', -> | |
$.get '/docs/keyboard_shortcuts', (html) -> | |
if !$wrapper | |
$wrapper = $('<div class="keyboard-shortcuts-wrapper">loading …</div>') | |
$wrapper.appendTo('body').html(html) | |
$('.modal', $wrapper).modal('toggle') | |
# Typical search shortcut | |
Mousetrap.bind '/', (-> $('.query').focus()), 'keyup' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment