Skip to content

Commit

Permalink
work around the missing maxresdefault thumbs, add on touchstart
Browse files Browse the repository at this point in the history
  • Loading branch information
tmtmtm committed Feb 11, 2015
1 parent 002039c commit a2f0b8d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lazyYT.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@
thumb_img = 'default.jpg';
}

var urlbase = '//i.ytimg.com/vi/'+id+'/';

$thumb = $el.find('.ytp-thumbnail').css({
'background-image': ['url(http://img.youtube.com/vi/', id, '/', thumb_img, ')'].join('')
'background-image': 'url(' + urlbase + thumb_img + ')'
})
.addClass('lazyYT-image-loaded')
.on('click', function (e) {
.on('click touchstart', function (e) {
e.preventDefault();
if (!$el.hasClass('lazyYT-video-loaded') && $thumb.hasClass('lazyYT-image-loaded')) {
$el.html('<iframe src="//www.youtube.com/embed/' + id + '?autoplay=1&' + youtube_parameters + '" frameborder="0" allowfullscreen></iframe>')
Expand All @@ -104,6 +106,12 @@

$.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);
// work around the missing maxresdefault
if( thumb_img == 'maxresdefault.jpg' && data.entry['yt$hd'] == undefined ) {
$el.find('.ytp-thumbnail').css({
'background-image': 'url(' + urlbase + 'hqdefault.jpg)'
});
}
});

}
Expand Down

0 comments on commit a2f0b8d

Please sign in to comment.