-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathjquery.toasty.js
69 lines (57 loc) · 1.68 KB
/
jquery.toasty.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
/*
* Toasty v0.1.2
* Show Dan Forden's Toasty from Mortal Kombat as an Easter Egg for your website
* (c)2014 Ruben Torres - rubentdlh@gmail.com
* Released under the MIT license
*/
(function($) {
//singleton
var singleToasty;
function Toasty(elem, options){
this.options=options;
}
Toasty.prototype = {
//initialize including neccesary elements in DOM
init: function(){
//Add to dom needed elements
$("body").append('<div id="toasty-guy-dan"><img src="'+ this.options.image +'" alt="toasty"></div>');
$('#toasty-guy-dan').css('position', 'fixed');
$('#toasty-guy-dan').css('right', '-170px');
$('#toasty-guy-dan').css('bottom', '0px');
if(this.options.sound){
$("body").append('<audio id="toasty-audio"><source src="'+ this.options.sound +'" type="audio/mpeg"></source></audio>');
}
},
pop: function(){
var audio = document.getElementById('toasty-audio');
audio.play();
$("#toasty-guy-dan").addClass("show-dan");
setTimeout( function(){ $("#toasty-guy-dan").removeClass("show-dan"); }, 1000);
}
}
$.fn.toasty = function(options) {
this.each(function(){
// Check if we should operate with some method
if (/^(pop)$/i.test(options)) {
// Normalize method's name
options = options.toLowerCase();
switch(options){
case 'pop':
singleToasty.pop();
break;
}
}else if (typeof options == 'object' || !options) {
options = $.extend({}, $.fn.toasty.defaults, options);
if(!singleToasty){
singleToasty = new Toasty($(this), options);
singleToasty.init();
}
}
});
}
$.fn.toasty.defaults = {
sound: true,
image: 'toasty.png',
sound: 'toasty.mp3'
};
})(jQuery);