Skip to content

Instantly share code, notes, and snippets.

@sundarj
Forked from anonymous/index.html
Last active August 29, 2015 14:21
Show Gist options
  • Save sundarj/18abd16d8efe79ce05a2 to your computer and use it in GitHub Desktop.
Save sundarj/18abd16d8efe79ce05a2 to your computer and use it in GitHub Desktop.
<!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>
(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