FIX: fetch YouTube video title via oEmbed

This commit is contained in:
Arpit Jalan 2015-05-08 18:03:36 +05:30
parent c2ffe255c3
commit 88135e5b22
2 changed files with 8 additions and 9 deletions

View file

@ -16,11 +16,11 @@
height = $el.data('height'), height = $el.data('height'),
ratio = ($el.data('ratio')) ? $el.data('ratio') : settings.default_ratio, ratio = ($el.data('ratio')) ? $el.data('ratio') : settings.default_ratio,
id = $el.data('youtube-id'), id = $el.data('youtube-id'),
title = $el.data('youtube-title'),
padding_bottom, padding_bottom,
innerHtml = [], innerHtml = [],
$thumb, $thumb,
thumb_img, thumb_img,
loading_text = $el.text() ? $el.text() : settings.loading_text,
youtube_parameters = $el.data('parameters') || ''; youtube_parameters = $el.data('parameters') || '';
ratio = ratio.split(":"); ratio = ratio.split(":");
@ -64,8 +64,12 @@
innerHtml.push('<div class="html5-info-bar">'); innerHtml.push('<div class="html5-info-bar">');
innerHtml.push('<div class="html5-title">'); innerHtml.push('<div class="html5-title">');
innerHtml.push('<div class="html5-title-text-wrapper">'); innerHtml.push('<div class="html5-title-text-wrapper">');
innerHtml.push('<a id="lazyYT-title-', id, '" class="html5-title-text" target="_blank" tabindex="3100" href="https://www.youtube.com/watch?v=', id, '">'); innerHtml.push('<a class="html5-title-text" target="_blank" tabindex="3100" href="https://www.youtube.com/watch?v=', id, '">');
innerHtml.push(loading_text); if (title === null || title === '') {
innerHtml.push('https://www.youtube.com/watch?v=' + id);
} else {
innerHtml.push(title);
}
innerHtml.push('</a>'); innerHtml.push('</a>');
innerHtml.push('</div>'); // .html5-title innerHtml.push('</div>'); // .html5-title
innerHtml.push('</div>'); // .html5-title-text-wrapper innerHtml.push('</div>'); // .html5-title-text-wrapper
@ -102,15 +106,10 @@
} }
}); });
$.getJSON('https://gdata.youtube.com/feeds/api/videos/' + id + '?v=2&alt=json', function (data) {
$el.find('#lazyYT-title-' + id).text(data.entry.title.$t);
});
} }
$.fn.lazyYT = function (newSettings) { $.fn.lazyYT = function (newSettings) {
var defaultSettings = { var defaultSettings = {
loading_text: 'Loading...',
default_ratio: '16:9', default_ratio: '16:9',
callback: null, // ToDO execute callback if given callback: null, // ToDO execute callback if given
container_class: 'lazyYT-container' container_class: 'lazyYT-container'

View file

@ -18,7 +18,7 @@ class Onebox::Engine::YoutubeOnebox
def to_html def to_html
if video_id if video_id
# Put in the LazyYT div instead of the iframe # Put in the LazyYT div instead of the iframe
"<div class=\"lazyYT\" data-youtube-id=\"#{video_id}\" data-width=\"480\" data-height=\"270\" data-parameters=\"#{embed_params}\"></div>" "<div class=\"lazyYT\" data-youtube-id=\"#{video_id}\" data-youtube-title=\"#{video_title}\" data-width=\"480\" data-height=\"270\" data-parameters=\"#{embed_params}\"></div>"
else else
super super
end end