2017-04-10 15:15:14 -07:00
|
|
|
(function ($) {
|
|
|
|
|
|
|
|
$(document).bind("DOMContentLoaded",
|
|
|
|
function () {
|
2017-04-11 20:08:03 -07:00
|
|
|
|
2017-04-10 15:15:14 -07:00
|
|
|
var playBtn = '<i class="fa fa-play-circle-o play-button"></i>'
|
2017-04-11 14:37:42 -07:00
|
|
|
$('div[youtube_id]').each(function () {
|
2017-04-11 20:08:03 -07:00
|
|
|
if ($(this).attr('nothumb') !== "yes") {
|
|
|
|
var vid = $(this).attr('youtube_id');
|
|
|
|
var bgi = `style="background-image: url(https://i.ytimg.com/vi/${vid}/mqdefault.jpg)"`
|
|
|
|
var thumb = `<div class="thumb--yt" ${bgi} width="560" height="315">`
|
2017-04-19 14:10:18 -07:00
|
|
|
$(this).append(thumb).children().append(playBtn).click(insertIframe).fitToWindow()
|
2017-04-11 20:08:03 -07:00
|
|
|
|
|
|
|
} else { // if image thumbs turned off
|
|
|
|
insertIframe.call(this)
|
|
|
|
}
|
|
|
|
|
2017-04-11 14:37:42 -07:00
|
|
|
})
|
2017-04-11 20:08:03 -07:00
|
|
|
})
|
2017-04-10 15:15:14 -07:00
|
|
|
|
|
|
|
function insertIframe() {
|
|
|
|
var $box = $(this).parent()
|
2017-04-11 14:37:42 -07:00
|
|
|
var id = $box.attr('youtube_id')
|
2017-04-11 20:08:03 -07:00
|
|
|
var autoplay = "autoplay=1&"
|
|
|
|
if (!id) { // image thumb is off not called by thumb so don't need parent
|
|
|
|
$box = $(this)
|
|
|
|
id = $box.attr('youtube_id')
|
|
|
|
autoplay = ""
|
|
|
|
}
|
|
|
|
var mw = $box.attr('maxWidth');
|
|
|
|
var wp = $box.attr('wPad');
|
2017-04-11 14:37:42 -07:00
|
|
|
var start = $box.attr("start") || 1
|
|
|
|
var list = ""
|
|
|
|
if ($box.attr("list")) { list = `&list=${$box.attr("list")}` }
|
2017-04-11 20:08:03 -07:00
|
|
|
var url = `https://www.youtube.com/embed/${id}?${autoplay}start=${start}`
|
2017-04-11 14:37:42 -07:00
|
|
|
var vIframe = `<iframe width = "560" height = "315" src ="${url}${list}" frameborder = "0" allowfullscreen></iframe>`
|
2017-04-11 20:08:03 -07:00
|
|
|
$box.html(vIframe).children().fitToWindow($box.data("maxWidth") || mw, $box.data("wPad") || wp)
|
2017-04-10 15:15:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}(jQuery));
|
2017-04-19 15:43:53 -07:00
|
|
|
|
|
|
|
// TODO grab the video title as well as the thumb for use in thumb display
|
|
|
|
// only works if server allows cross domain like s3
|
|
|
|
//http://stackoverflow.com/questions/1760231/how-do-i-get-the-title-of-a-youtube-video-if-i-have-the-video-id
|
|
|
|
// #var ytApiKey = "...";
|
|
|
|
// #var videoId = "ylLzyHk54Z0";
|
|
|
|
// #$.get("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" + videoId + "&key=" + ytApiKey, function(data) {
|
|
|
|
// #alert(data.items[0].snippet.title);
|
|
|
|
// # });
|