From 9ec71dffe91a74abc5fbdf4242019535ab7a6580 Mon Sep 17 00:00:00 2001 From: Andrey Panchenko Date: Thu, 11 Jul 2013 18:55:11 +0400 Subject: [PATCH] Youtube iframe api implemented with help of callPlayer function. --- src/jquery.cycle2.video.js | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/jquery.cycle2.video.js b/src/jquery.cycle2.video.js index 3f5e232..73871b1 100644 --- a/src/jquery.cycle2.video.js +++ b/src/jquery.cycle2.video.js @@ -2,13 +2,9 @@ (function($) { "use strict"; -var template = '
' + - '' + - '' + - '' + - '' + - '' + -'
'; +var template = '
' + + '' + +'
'; $.extend($.fn.cycle.defaults, { youtubeAllowFullScreen: true, @@ -29,10 +25,10 @@ $(document).on( 'cycle-bootstrap', function( e, opts ) { return; var markup, slide = $(this), url = slide.attr( 'href' ); var fs = opts.youtubeAllowFullScreen ? 'true' : 'false'; - url += ( /\?/.test( url ) ? '&' : '?') + 'enablejsapi=1'; + url += ( /\?/.test( url ) ? '&' : '?') + 'enablejsapi=1&rel=0'; if ( opts.youtubeAutostart && opts.startingSlide === i ) url += '&autoplay=1'; - markup = opts.API.tmpl( template, { url: url, allowFullScreen: fs }); + markup = opts.API.tmpl( template, { url: url, allowFullScreen: fs, divid: "divid" + i }); slide.replaceWith( markup ); }); opts.slides = opts.slides.replace(/(\b>?a\b)/,'div.cycle-youtube'); @@ -40,30 +36,15 @@ $(document).on( 'cycle-bootstrap', function( e, opts ) { if ( opts.youtubeAutostart ) { opts.container.on( 'cycle-initialized cycle-after', function( e, opts ) { var index = e.type == 'cycle-initialized' ? opts.currSlide : opts.nextSlide; - $( opts.slides[ index ] ).find('object,embed').each( play ); + callPlayer(opts.slides[ index ].firstChild.id, 'playVideo'); }); } if ( opts.youtubeAutostop ) { opts.container.on( 'cycle-before', function( e, opts ) { - $( opts.slides[ opts.currSlide ] ).find('object,embed').each( pause ); + callPlayer(opts.slides[ opts.currSlide ].firstChild.id, 'stopVideo'); }); } }); -function play() { - /*jshint validthis:true */ - try { - this.playVideo(); - } - catch( ignore ) {} -} -function pause() { - /*jshint validthis:true */ - try { - this.pauseVideo(); - } - catch( ignore ) {} -} - })(jQuery);