Skip to content

Commit

Permalink
Raptorize is now config once
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorrall committed Dec 22, 2013
1 parent d5547b9 commit a61cb09
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
21 changes: 16 additions & 5 deletions app/assets/javascripts/welcome.js.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,39 @@
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

$ ->
raptor_options = {
spiderpigLabel = $('#spiderpig-label').text()
callbackPID = null

# Setup Raptorize
raptorize.config {
playAudio: Modernizr.audio,
imageSource: "<%= image_path 'raptor.png' %>",
audioSources: ["<%= audio_path 'raptor-sound.mp3' %>", "<%= audio_path 'raptor-sound.ogg' %>"]
}

# Attach the Raptor
$('#spiderpig img')
.raptorize(raptor_options)
.raptorize()
.click (e)->
Analytics.push ['_trackEvent', 'welcome', 'clickedPig']
true # Don't prevent callback

# Attach the Swarm
new Konami(->
# Stop the User Label Scrolling
clearTimeout callbackPID
$('#spiderpig-label').text('!!! RAPTOR SWARM !!!')

# Release the Swarm
Analytics.push ['_trackEvent', 'welcome', 'konamiCode']
raptorize.raptorSwarm(raptor_options);
raptorize.raptorSwarm();

# Resume scrolling the User Label
setTimeout(spiderpigCallback, 8000)
true # Run find
)

# Update the User's label
spiderpigLabel = $('#spiderpig-label').text()
callbackPID = null
spiderpigCallback = ->
if $('#spiderpig-label').text() == spiderpigLabel
$('#spiderpig-label').text('//github.com/bmorrall')
Expand Down
33 changes: 16 additions & 17 deletions lib/assets/javascripts/jquery.raptorize.1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,29 @@
};
});

// Global Raptorize Config
var config = {}

// Create the Raptor Factory
window.raptorize = {
// Set the default options for raptorize
config: function(options) {
config = options
},
// Allow Raptor to be changed
raptor: raptor,
raptorable: raptor,
// Quickly fire off a Raptor
quickSpawn: function(options) {
return new raptorize.raptor(options).unleash();
quickSpawn: function() {
return new raptorize.raptorable(config).unleash();
},
raptorSwarm: function(options, i) {
if (i < 20) {
raptorSwarm: function(count) {
if (typeof(count) == "undefined") {
count = 10; // Unleash 10 by default
}
if (count > 0) {
raptorize.quickSpawn();
setTimeout(function() {
raptorize.raptorSwarm(options, i + 1);
raptorize.raptorSwarm(count - 1);
}, Math.random() * 1000);
}
},
Expand All @@ -117,17 +127,6 @@
var delayTime = defaults.delayTime || options.delayTime;
var callback = function() { raptorize.quickSpawn(options); }
setTimeout(callback, delayTime);
},
// Fire on Konami Code
onKonami: function(options) {
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
$(window).bind("keydown.raptorz", function(e) {
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ) {
raptorize.quickSpawn(options);
$(window).unbind('keydown.raptorz');
}
}, true);
}
};

Expand Down

0 comments on commit a61cb09

Please sign in to comment.