forked from chulini/lucho-jarascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lucho-jarascript.js
197 lines (161 loc) · 8.47 KB
/
lucho-jarascript.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
(function(){
//Magic happens
var loadLuchoScript = function ($) {
$.fn.luchoJaraScript = function (options) {
var settings = $.extend({
player: false,
autoplay: false,
english: false
}, options);
var $este = this;
//Array of lucho's images
var luchos = [];
luchos.push("https://i.imgur.com/eRC8onz.jpg");
luchos.push("https://i.imgur.com/eISN50J.jpg");
luchos.push("https://i.imgur.com/nfL1ay3.jpg");
luchos.push("https://i.imgur.com/eYBo65E.jpg");
luchos.push("https://i.imgur.com/WMTJa8v.jpg");
luchos.push("https://i.imgur.com/llTC4uD.jpg");
luchos.push("https://i.imgur.com/yBBoQzj.jpg");
luchos.push("https://i.imgur.com/WAJbX1o.jpg");
luchos.push("https://i.imgur.com/KBM537X.jpg");
luchos.push("https://i.imgur.com/fxtpaM2.jpg");
luchos.push("https://i.imgur.com/91KCiE4.jpg");
luchos.push("https://i.imgur.com/iWys51v.jpg");
luchos.push("https://i.imgur.com/rT6ybOE.jpg");
luchos.push("https://i.imgur.com/4iST79y.jpg");
luchos.push("https://i.imgur.com/0Ce3339.jpg");
luchos.push("https://i.imgur.com/F3uq7wg.jpg");
luchos.push("https://i.imgur.com/obsJjoW.jpg");
luchos.push("https://i.imgur.com/Svs3fP9.jpg");
luchos.push("https://i.imgur.com/Fv75FGB.png");
luchos.push("https://i.imgur.com/0LmhWV2.jpg");
luchos.push("https://i.imgur.com/75inuSW.jpg");
luchos.push("https://i.imgur.com/hnDV1Cy.jpg");
luchos.push("https://i.imgur.com/xm56egI.jpg");
luchos.push("https://i.imgur.com/wcNMFHq.jpg");
luchos.push("https://i.imgur.com/M8Vsx8b.jpg");
luchos.push("https://i.imgur.com/mSWmxSz.jpg");
luchos.push("https://i.imgur.com/Aei4AAF.jpg");
luchos.push("https://i.imgur.com/jkB4Zn5.jpg");
//Languages supported
var languages = {
spanish: {
title: 'Un golpe de suerte',
golpe: 'Un golpe de suerte, espero despierto... igual que un espia en la oscuridad, espero volver a encontrar, un golpe de suerte, podria cambiar el tiempo perdido, que hay en el vacio que dejaste ayer al partir, un golpe de suerte eres tu. Soy, un tipo tranquilo, tratando de no hacer mal, y ser buen amigo, yo soy uno mas, uno de tantos, en busca de ser feliz, de vez en cuando... y con el tiempo de caminar, fui aprendiendo, ahora se que puedo llegar si me dan tiempo. Soy, un caso perdido, luchando para quebrarle la mano al destino, vivir a diario, es tan bulnerable, cuantas noches sin dormir, ardiendo de frioo, y con el tiempo de caminar, fui aprendiendo, ahora se que puedo, llegar si me doy tiempo.',
url: 'https://www.youtube.com/embed/gcpJjmdoDz8'
},
english: {
title: 'A Stroke of Luck',
golpe: "A Stroke of Luck, I lie awake waiting, just like a spy in the dark... hoping to find that spark... A Stroke of Luck could change my life, all the lost time... and fill the emptiness that you left, since you're not mine, my Stroke of Luck is you. I... am just a normal guy... trying to do the right thing, to give it a try... I'm just one more... of the rank and file, trying to be happy, once in a while... and after years of walking by, I've learned on the ride, now I know that I can make it, given the time. I... am a lost cause... fighting to put destiny on pause... every day my life is exposed... so many sleepless nights, burning with cold... and after years of walking by, I've learned on the ride, now I know I can make it, given the time.",
url: 'https://www.youtube.com/embed/noOaxZym9xk'
}
};
var luchoObject = settings.english ? languages.english : languages.spanish;
var golpe_words = luchoObject.golpe.split(" ");
//Returns random image of lucho jara
function randomLucho(){
return luchos[Math.floor(Math.random()*luchos.length)];
}
//Converts regular text to un golpe de suerte lyrics
function textToGolpeDeSuerte(text){
var text_words = text.split(" ");
var replaced_text = "";
for(var i = 0; i < text_words.length;i++)
replaced_text += golpe_words[i%golpe_words.length]+" ";
return replaced_text;
}
$este.find('h1').each(function () {
$(this).html("Luis Jara");
});
$este.find('h2, h3, h4, h5, h6').each(function () {
$(this).html(luchoObject.title);
});
$este.find('p').each(function(){
var text = $(this).text();
$(this).html(textToGolpeDeSuerte(text));
});
setInterval(function(){
$este.find('img').each(function(){
if (this.src.indexOf('data:') > -1 || $(this).hasClass("luchojared"))
return;
// console.log("luchojared!");
$(this).addClass("luchojared");
var $img = $(this),
w = $img.width(),
h = $img.height();
$img.attr("src", 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==')
.width(w)
.height(h)
.css({
backgroundImage: 'url('+ randomLucho() +')',
backgroundSize: 'cover',
backgroundPosition: 'center'
});
});
},500);
//Un Golpe de Suerte Player
if(settings.player){
if($este.css('position') === 'static'){
$este.css('position', 'relative');
}
var $containerDiv = $('<div class="lucho-player-div"></div>')
.css({
position: 'absolute',
top: '0px',
right: '0px',
'z-index': 2147483646
});
var $player = $('<div class="lucho-player"><iframe width="420" height="315" src="'+ luchoObject.url +'?autoplay='
+ (settings.autoplay ? '1' : '0')
+ '" frameborder="0" allowfullscreen></iframe></div>')
.css('clear', 'both')
.hide();
var $button = $('<button class="lucho-button">Lucho!</button>')
.click(function(evento){
$(this).siblings('.lucho-player').slideToggle();
})
.css('float', 'right');
$containerDiv.append($button).append($player).appendTo($este);
}
console.log('Loaded Lucho JaraScript');
return $este;
};
$(document).ready(function(){
if(typeof customLucho !== 'undefined'){
$(customLucho.target ? customLucho.target : 'body').luchoJaraScript(customLucho);
}else{
$('body').luchoJaraScript();
}
});
};
//function to load scripts dynamically (https://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/)
function loadScript(url, callback){
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState){ //IE
script.onreadystatechange = function(){
if (script.readyState == "loaded" ||
script.readyState == "complete"){
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function(){
callback();
};
}
script.src = url;
document.getElementsByTagName("head")[0].appendChild(script);
}
//load jQuery if is not defined
if(typeof jQuery === 'undefined'){
console.log('Loading jQuery 1.11.3 ...');
loadScript('https://code.jquery.com/jquery-1.11.3.min.js',function(){
loadLuchoScript(jQuery);
});
}else{
loadLuchoScript(jQuery);
}
})();