Last active
April 6, 2018 05:00
-
-
Save mdimai666/c57e1d86b116a041a6c5e343cc623669 to your computer and use it in GitHub Desktop.
key bind script for jquery
This file contains 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
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