Created
December 10, 2014 18:15
-
-
Save g-i-o-/875dd9d60b8320e7dcc7 to your computer and use it in GitHub Desktop.
angular module for the konami code
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
angular.module('angular-konami', []) | |
.run(function($rootScope){ | |
var code = [38,38,40,40,37,39,37,39,65,66,13]; | |
var stack = []; | |
$(document).keydown(function(evt){ | |
console.log(evt.which); | |
stack.push(evt.which); | |
if(stack.length > code.length){ | |
stack.shift(); | |
} else if(stack.length == code.length){ | |
if(stack.filter(function(k, i){ | |
return k != code[i]; | |
}).length === 0){ | |
$rootScope.$broadcast('konami-code'); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment