Skip to content

Commit

Permalink
Multimedia: Fixed not being to have more than one YouTube player per …
Browse files Browse the repository at this point in the history
…page
  • Loading branch information
LaurentGoderre committed Jul 3, 2014
1 parent fd4ba73 commit 9790130
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/plugins/multimedia/multimedia.js
Expand Up @@ -512,6 +512,12 @@ var pluginName = "wb-mltmd",
}
},

youTubeAPIReady = function() {
var youTube = window.youTube;
youTube.ready = true;
youTube.waitingPlayers.trigger( youtubeEvent );
},

onResize = function() {
$( selector + " object, " + selector + " iframe, " + selector + " video" ).trigger( resizeEvent );
};
Expand Down Expand Up @@ -557,6 +563,7 @@ $document.on( initializedEvent, selector, function() {
width: width
}, i18nText),
media = $media.get( 0 ),
youTube = window.youTube,
url;

if ( $media.attr( "id" ) === undef ) {
Expand All @@ -579,12 +586,15 @@ $document.on( initializedEvent, selector, function() {
$this.data( "youtube", url.params.v );

// Method called the the YouTUbe API when ready
if ( window.onYouTubeIframeAPIReady === undefined ) {

// lets bind youtubes global function
window.onYouTubeIframeAPIReady = function() {
$this.trigger( youtubeEvent );
};
if ( youTube.ready === false ) {
if ( youTube.waitingPlayers === undef ) {
youTube.waitingPlayers = $this;
} else {
youTube.waitingPlayers = youTube.waitingPlayers.add( $this );
}
} else {
$this.trigger( youtubeEvent );
}

// finally lets load safely
Expand Down Expand Up @@ -1029,6 +1039,12 @@ $document.on( resizeEvent, selector, function( event ) {
}
});

window.onYouTubeIframeAPIReady = youTubeAPIReady;

window.youTube = {
ready: false
};

wb.add( selector );

})( jQuery, window, wb );

0 comments on commit 9790130

Please sign in to comment.