// LOADER ANIMATION $(window).on("load", function () { console.log("UP, UP, DOWN, DOWN, LEFT, RIGHT, LEFT, RIGHT, B, A") console.log("Biff, Marty, Emmett, Goldie") console.log("pie, ufo, walk, cool, balloon, hangover, kirby, no, onmyway, haters, board, snorlax, fly, earth, thankyou, swim, penguin, handsome, tank, jump, winner, fox, mario, joker, rabbit, piggy, psyduck, dragon, salamander, airguitar, pikachu, bravo, ghost, britney, pikarun, catrun, koggy, sonic, doggy, spongebob, gun, money, bird, piqiu, lol, ohhh, nyancat") }) // SCROLLING TITLE var space = " "; var speed = "60"; var pos = 0; var msg = "// s1n.ical // Landing Page "; function Scroll() { document.title = msg.substring(pos, msg.length) + space + msg.substring(0, pos); pos++; if (pos > msg.length) pos = 0; window.setTimeout("Scroll()", speed); } Scroll(); // KONAMI CODE FOR TOASTY // a key map of allowed keys var allowedKeys = { 37: 'left', 38: 'up', 39: 'right', 40: 'down', 65: 'a', 66: 'b' }; // the 'official' Konami Code sequence var konamiCode = ['up', 'up', 'down', 'down', 'left', 'right', 'left', 'right', 'b', 'a']; // a variable to remember the 'position' the user has reached so far. var konamiCodePosition = 0; // add keydown event listener document.addEventListener('keydown', function (e) { // get the value of the key code from the key map var key = allowedKeys[e.keyCode]; // get the value of the required key from the konami code var requiredKey = konamiCode[konamiCodePosition]; // compare the key with the required key if (key == requiredKey) { // move to the next key in the konami code sequence konamiCodePosition++; // if the last key is reached, activate cheats if (konamiCodePosition == konamiCode.length) { activateCheats(); konamiCodePosition = 0; } } else { konamiCodePosition = 0; } }); function activateCheats() { var audio = new Audio('https://s3-eu-west-1.amazonaws.com/wdildnproject2/toasty.mp3'); audio.play(); $('.toasty').addClass('animateIn'); setTimeout(function () { $('.toasty').removeClass('animateIn'); }, 3500); } var TxtRotate = function (el, toRotate, period) { this.toRotate = toRotate; this.el = el; this.loopNum = 0; this.period = parseInt(period, 10) || 2000; this.txt = ''; this.tick(); this.isDeleting = false; }; TxtRotate.prototype.tick = function () { var i = this.loopNum % this.toRotate.length; var fullTxt = this.toRotate[i]; if (this.isDeleting) { this.txt = fullTxt.substring(0, this.txt.length - 1); } else { this.txt = fullTxt.substring(0, this.txt.length + 1); } this.el.innerHTML = '' + this.txt + ''; var that = this; var delta = 300 - Math.random() * 100; setTimeout(function () { that.tick(); }, delta); }; window.onload = function () { var elements = document.getElementsByClassName('txt-rotate'); for (var i = 0; i < elements.length; i++) { var toRotate = elements[i].getAttribute('data-rotate'); var period = elements[i].getAttribute('data-period'); if (toRotate) { new TxtRotate(elements[i], JSON.parse(toRotate), period); } } }; // BIFF, MARTY, EMMETT, GOLDIE // give $ to jQuery (function ($) { /**============================================================== * BTTF CHARACTER EASTER EGGS * ============================================================== */ var characters = {}; var pressedKeys = []; /** * Plays the audio clip for a specific easter egg character * @param {string} character name of character */ function playAudio(character) { setTimeout(function () { characters[character].audioFile.play(); setTimeout(function () { toggleShowChar(character); updateEggs(); }, characters[character].audioLength); }, 300); } /** * Toggles the display of an easter egg character * @param {string} character character name */ function toggleShowChar(character) { $('body').toggleClass(characters[character].name + '-show'); } /** * Add characters' information once page loads */ $(document).ready(function () { characters = { 'guessed': [], 'marty': { 'name': 'marty', 'nameKeys': "77,65,82,84,89", 'audioFile': $('audio.marty')[0], 'audioLength': 1300, }, 'docbrown': { 'name': 'docbrown', 'nameKeys': "69,77,77,69,84,84", 'audioFile': $('audio.docbrown')[0], 'audioLength': 2500, }, 'biff': { 'name': 'biff', 'nameKeys': "66,73,70,70", 'audioFile': $('audio.biff')[0], 'audioLength': 1100, }, 'goldie': { 'name': 'goldie', 'nameKeys': "71,79,76,68,73,69", 'audioFile': $('audio.goldie')[0], 'audioLength': 4000, }, 'toasty': { 'name': 'toasty', 'nameKeys': "84,79,65,83,84,89", } }; }); /** * Track character names being typed */ $(window).keydown(function (e) { pressedKeys.push(e.keyCode); // loop through characters for (var character in characters) { // if the "pressedKeys" contains the current character name if (pressedKeys.toString().indexOf(characters[character].nameKeys) >= 0) { // reset the pressedKeys array pressedKeys = []; // add "show" class to animate the character in toggleShowChar(character); if ($.inArray(character, characters.guessed) === -1) { characters.guessed.push(character); } // wait a second and play the character's audio file playAudio(character); } } // reset pressedKeys at 50 keypresses to save memory if (pressedKeys.length > 500) { pressedKeys = []; } }); })(jQuery);