Created
May 5, 2015 22:39
-
-
Save TrevorJTClarke/b7379b2092312ec625e2 to your computer and use it in GitHub Desktop.
An easter egg Angular directive. NBD.
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
/** | |
* 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