SPOILER! Kattints ide a szöveg elolvasásához![code]
var youtubeEmbed = function() {
var v = document.getElementsByClassName("youtube-player");
for (var n = 0; n < v.length; n++) {
if (!$(v[n]).hasClass('youtube-player-done')) {
$(v[n]).addClass('youtube-player-done');
var p = document.createElement("div");
p.innerHTML = labnolThumb(v[n].dataset.id);
p.onclick = labnolIframe;
v[n].appendChild(p);
}
}
};
youtubeEmbed();
function labnolThumb(id) {
if (id.indexOf('?') > -1) {
id = id.substring(0, id.indexOf('?'));
}
return '<img class="youtube-thumb" src="//i.ytimg.com/vi/' + id + '/hqdefault.jpg"><div class="play-button"></div>';
}
function labnolIframe() {
var mark = '?';
if (this.parentNode.dataset.id.indexOf('?') > -1) {
var end = this.parentNode.dataset.id.substring(this.parentNode.dataset.id.indexOf("?") + 1),
regex,
tmp,
seconds = 0;
end = end.replace('start=', '');
mark = '&';
if (end.indexOf('s') > -1) {
regex = /([\d]+)s/g;
tmp = regex.exec(end);
seconds = seconds + parseInt(tmp[1]);
}
if (end.indexOf('m') > -1) {
regex = /([\d]+)m/g;
tmp = regex.exec(end);
seconds = seconds + (60 * parseInt(tmp[1]));
}
if (end.indexOf('h') > -1) {
regex = /([\d]+)h/g;
tmp = regex.exec(end);
seconds = seconds + (3600 * parseInt(tmp[1]));
}
if (seconds !== 0) {
this.parentNode.dataset.id = this.parentNode.dataset.id.substring(0, this.parentNode.dataset.id.indexOf("?")) + '?start=' + seconds;
}
}
var iframe = document.createElement("iframe");
iframe.setAttribute("src", "//www.youtube.com/embed/" + this.parentNode.dataset.id + mark +
"autoplay=1&autohide=0&border=0&wmode=opaque&enablejsapi=1&controls=2&showinfo=1&disablekb=1&fs=1&origin=sg.hu");
iframe.setAttribute("frameborder", "0");
iframe.setAttribute("id", "youtube-iframe");
iframe.setAttribute('allowfullscreen', '1');
this.parentNode.replaceChild(iframe, this);
}