Skip to content

Instantly share code, notes, and snippets.

@TrevorJTClarke
Created May 5, 2015 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrevorJTClarke/b7379b2092312ec625e2 to your computer and use it in GitHub Desktop.
Save TrevorJTClarke/b7379b2092312ec625e2 to your computer and use it in GitHub Desktop.
An easter egg Angular directive. NBD.
/**
* tbde
* AKA "The Best Directive Ever"
*/
D.directive('tbde',
["$http","$rootScope", function ($http,$rootScope) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var randomGifUrl = "http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=laugh";
var el = angular.element(element);
var playing = false;
function createLaughter(){
$.ajax(randomGifUrl).success(function(res){
var img = document.createElement("IMG");
img.src = res.data.image_url;
img.id = "tbde";
img.className = "avatar avatar-tdbe";
$("#mainAvatar").addClass("hided");
// put into element
el.append(img);
setTimeout(function(){
playing = false;
$("#mainAvatar").removeClass("hided");
$("#tbde").remove();
},5000);
});
}
var keyCombo = "5116"; //shift + 3
var activeCombo = "";
var activeKey = "";
var previousKey = "";
window.executeKeyTest = function(){
activeCombo = activeKey + "" + previousKey;
if(activeCombo === keyCombo){
startTbde();
} else {
activeCombo = "";
}
};
window.addEventListener('keydown',function(e){
previousKey = activeKey;
activeKey = e.keyCode;
executeKeyTest();
});
function startTbde(){
if(playing === true){return;}
playing = true;
createLaughter();
}
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment