Created
October 15, 2013 17:40
-
-
Save JimmyHoffa/6995513 to your computer and use it in GitHub Desktop.
Something like this... just off the top of my head
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
KbdButton.prototype = { | |
installHotkey: function() { | |
// Install a single anchor in the body to catch our accessor. | |
var accessor = $( "<a accesskey='k' style='display:none; position:absolute;'>" ); | |
$( "body" ).append( accessor ); | |
var whichKey = 0; | |
var keyCaptureDialog = $("body").append('<div id="captureKeys"></div>').dialog({ | |
resizable: false, | |
height:140, | |
modal: true, | |
buttons: { | |
Cancel: function() { | |
$( this ).dialog( "close" ); | |
} | |
}); | |
keyCaptureDialog.on("keydown" function( event ) { | |
if( event.altKey ) { | |
keyCaptureDialog.dialog({buttons: "Alt+" + String.fromCharCode(event.which): function() { | |
whichKey = event.which; | |
$( this ).dialog( "close" ); | |
}, | |
Cancel: function() { | |
$( this ).dialog( "close" ); | |
} | |
}}}); | |
$( document ).on( "keydown", function( event ) { | |
// If Alt+K was pressed... | |
if( event.altKey && event.which == whichKey ) { | |
// ...find the parent KBD toggle button. | |
var kbdToggle = $( document.activeElement ).parents( ".wmd-container" ).find( "li.kbd-button" ); | |
if( kbdToggle.length > 0 ) { | |
kbdToggle.click(); | |
event.preventDefault(); | |
} | |
} | |
} ); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment