Last active
October 3, 2015 22:39
-
-
Save moimikey/99daf72978b712f58dc1 to your computer and use it in GitHub Desktop.
a standalone marionette module you can use in your own app to add a single 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
@MM.module 'KonamiApp', (KonamiApp, App, Backbone, Marionette, $, _) -> | |
# up, up, down, down, left, right, left, right, a, enter | |
KonamiApp.sequence = [38, 38, 40, 40, 37, 39, 37, 39, 65, 13] | |
KonamiApp.pressed = [] | |
KonamiApp.on | |
'start': -> | |
$(window).on 'keyup.konami', KonamiApp.pressedKey | |
'stop': -> | |
$(window).off '.konami' | |
KonamiApp.pressedKey = (evt) => | |
KonamiApp.pressed.push keycode = evt.keyCode ? evt.which | |
if keycode is 27 | |
window.cancelAnimationFrame @marquee | |
if (container = document.querySelector('.konami-container'))? | |
document.body.removeChild container | |
@audio.pause() | |
return | |
diff = _.difference KonamiApp.sequence, KonamiApp.pressed | |
len = KonamiApp.pressed.length - 1 | |
KonamiApp.pressed.length = 0 if KonamiApp.pressed[len] isnt KonamiApp.sequence[len] or diff.length is 0 | |
KonamiApp.surprise() if diff.length is 0 | |
KonamiApp.musicParse = (f) -> | |
eval("for(var t=0,S='RIFF_oO_WAVEfmt " + atob('EAAAAAEAAQBAHwAAQB8AAAEACAA') + "data';++t<3e5;)S+=String.fromCharCode(" + f + ")") | |
KonamiApp.music = -> | |
formula = '(t<<3)*[8/9,1,9/8,6/5,4/3,3/2,0][[0xd2d2c8,0xce4088,0xca32c8,0x8e4009][t>>14&3]>>(0x3dbe4688>>((t>>10&15)>9?18:t>>10&15)*3&7)*3&7]&255' | |
@audio = new Audio("data:audio/wav;base64,#{btoa(KonamiApp.musicParse(formula))}") | |
@audio.play() | |
KonamiApp.surprise = -> | |
@movement = -100 | |
fragment = document.createDocumentFragment() | |
container = document.createElement('div') | |
container.className = 'konami-container' | |
container.style.position = 'fixed' | |
container.style.top = 0 | |
container.style.left = 0 | |
container.style.right = 0 | |
container.style.bottom = 0 | |
container.style.opacity = 0 | |
container.style.height = '100vh' | |
container.style.width = '100vw' | |
container.style.background = 'rgba(255, 255, 255, .8)' | |
container.style.zIndex = '9999999' | |
container.style.overflow = 'hidden' | |
container.style.webkitTransition = 'opacity 1s ease-in' | |
container.style.mozTransition = 'opacity 1s ease-in' | |
container.style.msTransition = 'opacity 1s ease-in' | |
container.style.oTransition = 'opacity 1s ease-in' | |
container.style.transition = 'opacity 1s ease-in' | |
credits = document.createElement('div') | |
credits.className = 'konami' | |
credits.style.position = 'absolute' | |
credits.style.top = 0 | |
credits.style.left = 0 | |
credits.style.right = 0 | |
credits.style.bottom = 0 | |
credits.style.height = 'inherit' | |
credits.style.width = 'inherit' | |
credits.style.textAlign = 'center' | |
credits.style.fontFamily = 'courier new' | |
credits.style.fontSize = '20px' | |
credits.style.color = '#4AB3A4' | |
credits.style.marginTop = '-100%' | |
credits.innerHTML = """ | |
<p><img src="/assets/images/badge.png" width="250" height="auto"></p> | |
<p>made with <span style="color:#e66452">❥</span> by</p> | |
<p>Engineering @ MiMedia</p> | |
<p> </p> | |
<p>★</p> | |
<p> </p> | |
<p><strong>el capitan</strong></p> | |
<p> </p> | |
<p>Michael Yoon</p> | |
<p> </p> | |
<p>★</p> | |
<p> </p> | |
<p><strong>platform</strong></p> | |
<p> </p> | |
<p>Richard Elam</p> | |
<p>Jeff Mericle</p> | |
<p>Helenka Casler</p> | |
<p> </p> | |
<p>★</p> | |
<p> </p> | |
<p><strong>UI</strong></p> | |
<p> </p> | |
<p>Michael Hertzberg</p> | |
<p>Ian Johnson</p> | |
<p>Alex Burgos</p> | |
<p> </p> | |
<p>★</p> | |
<p> </p> | |
<p><strong>QA</strong></p> | |
<p> </p> | |
<p>Nicole Smith</p> | |
<p>Ashley Alfaro</p> | |
<p>Mashur Hossain</p> | |
<p> </p> | |
<p>★</p> | |
<p> </p> | |
<p><strong>netops</strong></p> | |
<p> </p> | |
<p>Bob Eckert</p> | |
<p>James "Awesome" Morelli</p> | |
<p>Nate Diller</p> | |
""" | |
container.appendChild credits | |
fragment.appendChild container | |
document.body.appendChild fragment | |
setTimeout => | |
container.style.opacity = 1 | |
KonamiApp.music() | |
marquee = => | |
requestAnimationFrame = window.requestAnimationFrame or | |
window.mozRequestAnimationFrame or | |
window.webkitRequestAnimationFrame or | |
window.msRequestAnimationFrame or | |
(callback) -> window.setTimeout callback, 1000/60 | |
@marquee = requestAnimationFrame(marquee) | |
if @movement < 100 | |
@movement += .1 | |
else | |
@movement = -100 | |
credits.style.marginTop = "#{@movement}%" | |
marquee() | |
, 1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment