]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
review changes and Object.defineProperty use
authorScottDowne <sdowne@learn.senecac.on.ca>
Tue, 27 Sep 2011 16:09:56 +0000 (12:09 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Tue, 27 Sep 2011 16:09:56 +0000 (12:09 -0400)
players/youtube/popcorn.youtube.js
popcorn.js

index 7d35dca780517e026361c9f4796cfa928aaf70d2..09b08b6349e8b52ae6caa0d3bf2e326f7b34b872 100755 (executable)
@@ -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 ) {
index 4ebd8c4de3c167d19805e2a49b3c503bd1d59b12..334a1d07fe3c7776b2762f6e8e299cb81b10767d 100644 (file)
           basePlayer[ val ] = container[ val ];
         } else if ( typeof container[ val ] === "function" ) {
 
-          basePlayer[ val ] = ( function( value ) {
+          basePlayer[ val ] = (function( value ) {
 
             return function() {
 
           }( 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
+          });
         }
       }
 
 
         date = new Date() / 1000;
 
-        if( !basePlayer.paused ) {
+        if ( !basePlayer.paused ) {
 
           basePlayer.currentTime = basePlayer.currentTime + ( date - baselineTime );
           basePlayer.dispatchEvent( "timeupdate" );
         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
     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