-
-
Save sundarj/18abd16d8efe79ce05a2 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>nest.key</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
(function(window){ | |
var nest = {}; | |
nest.key = function(keydir) { | |
keydir = keydir || 'keydown'; | |
var mod; | |
var upon = function(key){ | |
return { | |
upon: function(fn) { | |
window.addEventListener(keydir, function(e) { | |
e.preventDefault(); | |
if (e[mod]) { | |
if (String.fromCharCode(e.which) === key.toUpperCase()) | |
fn(); | |
} | |
}); | |
} | |
}; | |
}; | |
return { | |
ctrl: function(key) { | |
mod = 'ctrlKey'; | |
return upon(key); | |
} | |
}; | |
}; | |
window.nest = nest; | |
})(this); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">(function(window){ | |
var nest = {}; | |
nest.key = function(keydir) { | |
keydir = keydir || 'keydown'; | |
var mod; | |
var upon = function(key){ | |
return { | |
upon: function(fn) { | |
window.addEventListener(keydir, function(e) { | |
e.preventDefault(); | |
if (e[mod]) { | |
if (String.fromCharCode(e.which) === key.toUpperCase()) | |
fn(); | |
} | |
}); | |
} | |
}; | |
}; | |
return { | |
ctrl: function(key) { | |
mod = 'ctrlKey'; | |
return upon(key); | |
} | |
}; | |
}; | |
window.nest = nest; | |
})(this);</script></body> | |
</html> |
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
(function(window){ | |
var nest = {}; | |
nest.key = function(keydir) { | |
keydir = keydir || 'keydown'; | |
var mod; | |
var upon = function(key){ | |
return { | |
upon: function(fn) { | |
window.addEventListener(keydir, function(e) { | |
e.preventDefault(); | |
if (e[mod]) { | |
if (String.fromCharCode(e.which) === key.toUpperCase()) | |
fn(); | |
} | |
}); | |
} | |
}; | |
}; | |
return { | |
ctrl: function(key) { | |
mod = 'ctrlKey'; | |
return upon(key); | |
} | |
}; | |
}; | |
window.nest = nest; | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment