Last active
December 16, 2015 08:29
-
-
Save davier26/5406211 to your computer and use it in GitHub Desktop.
Konami Code
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
/* 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