From: ScottDowne Date: Tue, 27 Sep 2011 16:09:56 +0000 (-0400) Subject: review changes and Object.defineProperty use X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=f3dadbf526b1e625d347dbcf13530b3fef52c9f0;p=popcorn-js.git review changes and Object.defineProperty use --- diff --git a/players/youtube/popcorn.youtube.js b/players/youtube/popcorn.youtube.js index 7d35dca..09b08b6 100755 --- a/players/youtube/popcorn.youtube.js +++ b/players/youtube/popcorn.youtube.js @@ -23,6 +23,11 @@ Popcorn.player( "youtube", { var youtubeInit = function() { + var flashvars, + params, + attributes, + src; + // expose a callback to this scope, that is called from the global callback youtube calls onYouTubePlayerReady[ container.id ] = function() { @@ -92,59 +97,62 @@ Popcorn.player( "youtube", { } }; - media.__defineSetter__( "currentTime", function( val ) { - - // make sure val is a number - currentTime = seekTime = +val; - seeking = true; - media.dispatchEvent( "seeked" ); - media.dispatchEvent( "timeupdate" ); - youtubeObject.seekTo( currentTime ); - return currentTime; - }); - - media.__defineGetter__( "currentTime", function() { + Popcorn.player.defineProperty( media, "currentTime", { + set: function( val ) { - return currentTime; - }); + if ( youtubeObject.isMuted() !== val ) { - media.__defineSetter__( "muted", function( val ) { + if ( val ) { - if ( youtubeObject.isMuted() !== val ) { + youtubeObject.mute(); + } else { - if ( val ) { + youtubeObject.unMute(); + } - youtubeObject.mute(); - } else { - - youtubeObject.unMute(); + media.dispatchEvent( "volumechange" ); } - media.dispatchEvent( "volumechange" ); - } + return youtubeObject.isMuted(); + }, + get: function() { - return youtubeObject.isMuted(); + return currentTime; + } }); - media.__defineGetter__( "muted", function() { + Popcorn.player.defineProperty( media, "muted", { + set: function( val ) { - return youtubeObject.isMuted(); - }); + // make sure val is a number + currentTime = seekTime = +val; + seeking = true; + media.dispatchEvent( "seeked" ); + media.dispatchEvent( "timeupdate" ); + youtubeObject.seekTo( currentTime ); + return currentTime; + }, + get: function() { - media.__defineSetter__( "volume", function( val ) { + return youtubeObject.isMuted(); + } + }); - if ( youtubeObject.getVolume() !== val ) { + Popcorn.player.defineProperty( media, "volume", { + set: function( val ) { - youtubeObject.setVolume( val ); - media.dispatchEvent( "volumechange" ); - } + if ( youtubeObject.getVolume() !== val ) { - return youtubeObject.getVolume(); - }); + youtubeObject.setVolume( val ); + media.dispatchEvent( "volumechange" ); + } - media.__defineGetter__( "volume", function() { + return youtubeObject.getVolume(); + }, + get: function() { - return youtubeObject.getVolume(); + return youtubeObject.getVolume(); + } }); media.readyState = 4; @@ -164,15 +172,26 @@ Popcorn.player( "youtube", { options.controls = +options.controls === 0 || +options.controls === 1 ? options.controls : 1; options.annotations = +options.annotations === 1 || +options.annotations === 3 ? options.annotations : 1; - var flashvars = { + flashvars = { playerapiid: container.id, controls: options.controls, iv_load_policy: options.annotations }; - swfobject.embedSWF( "http://www.youtube.com/e/" + /^.*[\/=](.{11})/.exec( media.src )[ 1 ] + "?enablejsapi=1&playerapiid=" + container.id + "&version=3", + params = { + wmode: "transparent", + allowScriptAccess: "always" + }; + + attributes = { + id: container.id + }; + + src = /^.*[\/=](.{11})/.exec( media.src )[ 1 ]; + + swfobject.embedSWF( "http://www.youtube.com/e/" + src + "?enablejsapi=1&playerapiid=" + container.id + "&version=3", container.id, media.offsetWidth, media.offsetHeight, "8", null, - flashvars, {wmode: "transparent", allowScriptAccess: "always"}, {id: container.id} ); + flashvars, params, attributes ); }; if ( !window.swfobject ) { diff --git a/popcorn.js b/popcorn.js index 4ebd8c4..334a1d0 100644 --- a/popcorn.js +++ b/popcorn.js @@ -1507,7 +1507,7 @@ basePlayer[ val ] = container[ val ]; } else if ( typeof container[ val ] === "function" ) { - basePlayer[ val ] = ( function( value ) { + basePlayer[ val ] = (function( value ) { return function() { @@ -1516,13 +1516,17 @@ }( val )); } else { - basePlayer.__defineGetter__( val, ( function( value ) { + Popcorn.player.defineProperty( basePlayer, val, { + get: (function( value ) { - return function() { + return function() { - return container[ value ]; - }; - }( val ))); + return container[ value ]; + }; + }( val )), + set: Popcorn.nop, + configurable: true + }); } } @@ -1530,7 +1534,7 @@ date = new Date() / 1000; - if( !basePlayer.paused ) { + if ( !basePlayer.paused ) { basePlayer.currentTime = basePlayer.currentTime + ( date - baselineTime ); basePlayer.dispatchEvent( "timeupdate" ); @@ -1558,17 +1562,19 @@ basePlayer.dispatchEvent( "pause" ); }; - basePlayer.__defineSetter__( "currentTime", function( val ) { + Popcorn.player.defineProperty( basePlayer, "currentTime", { + get: function() { - // make sure val is a number - currentTime = +val; - basePlayer.dispatchEvent( "timeupdate" ); - return currentTime; - }); - - basePlayer.__defineGetter__( "currentTime", function() { + return currentTime; + }, + set: function( val ) { - return currentTime; + // make sure val is a number + currentTime = +val; + basePlayer.dispatchEvent( "timeupdate" ); + return currentTime; + }, + configurable: true }); // Adds an event listener to the object @@ -1639,6 +1645,12 @@ Popcorn[ name ] = Popcorn[ name ] || playerFn; }; + Popcorn.player.defineProperty = Object.defineProperty || function( object, description, options ) { + + object.__defineGetter__( description, options.get || Popcorn.nop ); + object.__defineSetter__( description, options.set || Popcorn.nop ); + }; + // Cache references to reused RegExps var rparams = /\?/, // XHR Setup object