Skip to content

Instantly share code, notes, and snippets.

@davier26
Last active December 16, 2015 08:29
Show Gist options
  • Save davier26/5406211 to your computer and use it in GitHub Desktop.
Save davier26/5406211 to your computer and use it in GitHub Desktop.
Konami Code
/* up, up, down, down, left, right, left, right, b, a */
myapp.directive("konami", function () {
return {
restrict: "AEC",
controller: function ($scope) {
$scope.unleashTheUnicorns = function () {
...
}
},
link: function (scope, element, attrs) {
var kon_index = 0,
kon_keys = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
$(document).keydown(function(e){
if (e.keyCode === kon_keys[kon_index++]) {
console.log(e.keyCode);
if (kon_index === kon_keys.length) {
scope.unleashTheUnicorns();
}
} else {
kon_index = 0;
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment