Skip to content

Instantly share code, notes, and snippets.

@mdimai666
Last active April 6, 2018 05:00
Show Gist options
  • Save mdimai666/c57e1d86b116a041a6c5e343cc623669 to your computer and use it in GitHub Desktop.
Save mdimai666/c57e1d86b116a041a6c5e343cc623669 to your computer and use it in GitHub Desktop.
key bind script for jquery
function ready_keyBind(){
$(function(){
var schema = [
{key:'s', fn: d_save, args: []}
];
for(var k of schema)
$.ctrl(k.key,k.fn,k.args);
})
}
$.ctrl = function(key, callback, args) {
$(document).keydown(function(e) {
if(!args) args=[]; // IE barks when args is null
if(e.keyCode == key.toUpperCase().charCodeAt(0) && e.ctrlKey) {
e.preventDefault();
callback.apply(this, args);
return false;
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment