-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.raptorize.1.0.js
106 lines (89 loc) · 2.69 KB
/
jquery.raptorize.1.0.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* jQuery Raptorize Plugin 1.0
* www.ZURB.com/playground
* Copyright 2010, ZURB
* Free to use under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/
(function($) {
$.fn.raptorize = function(options) {
//Yo' defaults
var defaults = {
enterOn: 'click', //timer, konami-code, click
delayTime: 5000 //time before raptor attacks on timer mode
};
//Extend those options
var options = $.extend(defaults, options);
return this.each(function() {
var _this = $(this);
var audioSupported = false;
//Stupid Browser Checking which should be in jQuery Support
if ($.browser.mozilla && $.browser.version.substr(0, 5) >= "1.9.2" || $.browser.webkit) {
audioSupported = true;
}
//Raptor Vars
var raptorImageMarkup = '<img id="elRaptor" style="display: none" src="raptor.png" />'
var raptorAudioMarkup = '<audio id="elRaptorShriek" preload="auto"><source src="raptor-sound.mp3" /><source src="raptor-sound.ogg" /></audio>';
var locked = false;
//Append Raptor and Style
$('body').append(raptorImageMarkup);
if(audioSupported) { $('body').append(raptorAudioMarkup); }
var raptor = $('#elRaptor').css({
"position":"fixed",
"bottom": "-700px",
"right" : "0",
"display" : "block"
})
// Animating Code
function init() {
locked = true;
//Sound Hilarity
if(audioSupported) {
function playSound() {
document.getElementById('elRaptorShriek').play();
}
playSound();
}
// Movement Hilarity
raptor.animate({
"bottom" : "0"
}, function() {
$(this).animate({
"bottom" : "-130px"
}, 100, function() {
var offset = (($(this).position().left)+400);
$(this).delay(300).animate({
"right" : offset
}, 2200, function() {
raptor = $('#elRaptor').css({
"bottom": "-700px",
"right" : "0"
})
locked = false;
})
});
});
}
//Determine Entrance
if(options.enterOn == 'timer') {
setTimeout(init, options.delayTime);
} else if(options.enterOn == 'click') {
_this.bind('click', function(e) {
e.preventDefault();
if(!locked) {
init();
}
})
} else if(options.enterOn == 'konami-code'){
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 ) {
init();
$(window).unbind('keydown.raptorz');
}
}, true);
}
});//each call
}//orbit plugin call
})(jQuery);