Skip to content

Commit

Permalink
Fixed nodelist support for safari, youtube defaults its height and wi…
Browse files Browse the repository at this point in the history
…dth [#782]
  • Loading branch information
Christopher De Cairos committed Nov 1, 2011
2 parents ff60bcf + 3ff377d commit 2c8864a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
8 changes: 7 additions & 1 deletion players/youtube/popcorn.youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Popcorn.player( "youtube", {
params,
attributes,
src,
width,
height,
query;

// expose a callback to this scope, that is called from the global callback youtube calls
Expand Down Expand Up @@ -204,8 +206,12 @@ Popcorn.player( "youtube", {
src = /^.*(?:\/|v=)(.{11})/.exec( media.src )[ 1 ];
query = ( media.src.split( "?" )[ 1 ] || "" ).replace( /v=.{11}/, "" );

// setting youtube player's height and width, default to 560 x 315
width = media.style.width ? ""+media.offsetWidth : "560";
height = media.style.height ? ""+media.offsetHeight : "315";

swfobject.embedSWF( "//www.youtube.com/e/" + src + "?" + query + "&enablejsapi=1&playerapiid=" + container.id + "&version=3",
container.id, media.offsetWidth, media.offsetHeight, "8", null, flashvars, params, attributes );
container.id, width, height, "8", null, flashvars, params, attributes );
};

if ( !window.swfobject ) {
Expand Down
2 changes: 2 additions & 0 deletions players/youtube/popcorn.youtube.unit.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ <h2 id="qunit-userAgent"></h2>
<div id="video" style="width: 360px; height: 300px" ></div>
<div id="video2" style="width: 360px; height: 300px" ></div>
<div id="video3" style="width: 360px; height: 300px" ></div>
<div id="video4"></div>
<div id="video5" style="width: 0px; height: 0px" ></div>
</body>
</html>

28 changes: 28 additions & 0 deletions players/youtube/popcorn.youtube.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,31 @@ test( "Controls and Annotations toggling", function() {

});

test( "Player height and width", function() {

QUnit.reset();

expect( 4 );

stop( 10000 );
var popcorn1 = Popcorn.youtube( "#video4", "http://www.youtube.com/watch?v=9oar9glUCL0" ),
popcorn2 = Popcorn.youtube( "#video5", "http://www.youtube.com/watch?v=9oar9glUCL0" ),
readyStatePoll = function() {

if ( popcorn1.media.readyState !== 4 && popcorn2.media.readyState !== 4 ) {

setTimeout( readyStatePoll, 10 );
} else {

equal( popcorn1.media.children[ 0 ].width, 560, "Youtube player default width is 560" );
equal( popcorn1.media.children[ 0 ].height, 315, "Youtube player default height is 315" );

equal( popcorn2.media.children[ 0 ].width, 0, "Youtube player explicit width is 0" );
equal( popcorn2.media.children[ 0 ].height, 0, "Youtube player explicit height is 0" );
start();
}
};

readyStatePoll();
});

14 changes: 11 additions & 3 deletions popcorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -1665,10 +1665,18 @@

basePlayer[ val ] = (function( value ) {

return function() {
// this is a stupid ugly kludgy hack in honour of Safari
// in Safari a NodeList is a function, not an object
if ( "length" in container[ value ] && !container[ value ].call ) {

return container[ value ].apply( container, arguments );
};
return container[ value ];
} else {

return function() {

return container[ value ].apply( container, arguments );
};
}
}( val ));
} else {

Expand Down

0 comments on commit 2c8864a

Please sign in to comment.