-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.dogey.js
126 lines (98 loc) · 3.67 KB
/
jquery.dogey.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var text, removelist, dogewords, dogecolours, opts, options, $woofelement, dogei = 200, addtionalRemovedWords, addtionalWords, addDogeWords;
(function ( $ ) {
$.fn.dogey = function(options){
opts = $.extend( {}, $.fn.dogey.defaults, options );
text = this.text().toLowerCase();
// remove special chars
text = text.replace(/[^\w\s]/g, "");
// replace line breaks with space
text = text.replace(/(\r\n|\n|\r)/gm,"");
// replace tab space with space
text = text.replace(/\t+/g, " ");
// turn text string into array of words
text = text.split(" ");
removelist = [
"a", "all", "an", "and", "as", "at", "before", "best", "but", "by", "could", "ever", "for", "from", "hes", "I", "is",
"in", "into", "like", "not", "of", "off", "our", "on", "onto", "per", "shes", "since",
"than", "the", "this", "that", "to", "up", "via", "with", "something", "there", "maybe", "has", "ive", "one", "ones", "out", "goes", "seen", "only", "within", "essentially", "spits", "creates"
];
// adding new words to the remove list
if(opts.removeWords != null){
addtionalRemovedWords = opts.removeWords.split(" ");
removelist = addtionalRemovedWords.concat(removelist);
}
dogewords = [
"many", "such", "so", "nice", "much", "very"
];
// adding new words to the dogewords list
if(opts.addDogeWords != null){
addDogeWords = opts.addDogeWords.split(" ");
dogewords = addDogeWords.concat(dogewords);
}
dogecolours = [
"#FF0000", "#2AFF00", "#000DFF", "#FFCC33"
];
// remove list items from the text array
$(removelist).each(function(removeindex,removeelement){
if(text.indexOf(removeelement) !== -1){
for (var i=text.length-1; i>=0; i--) {
if (text[i] === removeelement) {
text.splice(i, 1);
}
}
}
});
// remove empty array items
text = $.grep(text,function(n){ return(n) });
$(opts.container).css({"position":"relative","overflow":opts.overflow}).append("<div class='doge_woofs'></div>");
$("body").append("<style>.woof{font-size:24px;z-index:999;font-family:Comic Sans MS, cursive, sans-serif;}</style>");
if(opts.heightMode == window){
$("body").append("<style>.woof{position:fixed;}</style>");
}
if(opts.heightMode == document){
$("body").append("<style>.woof{position:absolute;}</style>");
}
if(opts.animate == true){
$("body").append("<style>.woof{display:none;}</style>");
}else{
$("body").append("<style>.woof{display:block;}</style>");
}
$(text).each(function(index, element){
$(".doge_woofs").append("<p class='woof'>"+dogewords[Math.floor(Math.random()*dogewords.length)]+" "+element+"</p>");
});
$(".doge_woofs").append("<p class='woof'>wow</p><p class='woof'>amaze</p>");
$(".doge_woofs .woof").each(function(index, element){
if(index <= opts.limit){
$woofelement = $(element);
if(index%2 == 0){
$woofelement.css({
"left": Math.floor(( Math.random() * 45 + 1) ) + "%",
"top": Math.floor(( Math.random() * (($(opts.container).height()/100)*96) + 1) ),
"color": dogecolours[Math.floor(Math.random() * dogecolours.length)]
});
}else{
$woofelement.css({
"right": Math.floor(( Math.random() * 45 + 1) ) + "%",
"bottom": Math.floor(( Math.random() * (($(opts.container).height()/100)*96) + 1) ),
"color": dogecolours[Math.floor(Math.random() * dogecolours.length)]
});
}
if(opts.animate == true){
$woofelement.delay(parseInt(dogei)).fadeIn(opts.duration);
dogei = dogei+opts.offset;
}
}
});
};
$.fn.dogey.defaults = {
heightMode: document,
container:"body",
animate: true,
offset: 500,
duration: 600,
limit:20,
removeWords:null,
addDogeWords:null,
overflow:"hidden"
};
}( jQuery ));