]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#475] youtube now working for position and offsetWidth/Height, subtitles now fixed
authorScottDowne <sdowne@learn.senecac.on.ca>
Wed, 20 Apr 2011 23:18:34 +0000 (19:18 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Wed, 20 Apr 2011 23:18:34 +0000 (19:18 -0400)
players/youtube/popcorn.youtube.html
players/youtube/popcorn.youtube.js
popcorn.js

index 004428a39b8ee0fe6fecfed52b92a74094266406..c61f97db5e5a7f213bda65254a800a04fec320ad 100644 (file)
   <body>
     <div>
       <div>
-        <div id="video" width="360" height="300" ></div><br />
+        <div id="video" style="width: 360px; height: 300px;" ></div><br />
         <button class="simple" id="btn-play-pause">Play</button>
         <button class="seek" id="btn-seek">Seek to 30</button>
         <button class="volume" id="btn-volume">Toggle Volume</button>
index a64efa67e98c72cd0a9826c0b696799fe9543348..0c093e1394b6831e4a17c2b5acd1a3ae9e401399 100644 (file)
@@ -109,8 +109,8 @@ var onYouTubePlayerReady;
     bounds = container.getBoundingClientRect();
     
     // Determine width/height/etc based on container
-    this.width = container.getAttribute("width") || 460;
-    this.height = container.getAttribute("height") || 350;
+    this.width = container.style.width || 460;
+    this.height = container.style.height || 350;
     
     // Just in case we got the attributes as strings. We'll need to do math with these later
     this.width = parseFloat(this.width);
@@ -171,14 +171,22 @@ var onYouTubePlayerReady;
     
     var self = this;
     
-    this.playerId = elementId;
+    this.playerId = elementId + Popcorn.guid();
     this.readyState = READY_STATE_HAVE_NOTHING;
     this._eventListeners = {};
     this.loadStarted = false;
     this.loadedData = false;
     this.fullyLoaded = false;
     
-    this._container = document.getElementById( elementId );
+    this._target = document.getElementById( elementId );
+    this._container = document.createElement( "div" );
+    this._container.id = this.playerId;
+    this._container.style.height = this._target.style.height = this._target.style.height || "350px";
+    this._container.style.width  = this._target.style.width  = this._target.style.width  || "460px";
+    this._target.appendChild( this._container );
+
+    this.offsetHeight = +this._target.offsetHeight;
+    this.offsetWidth = +this._target.offsetWidth;
     
     this.currentTime = this.previousCurrentTime = 0;
     this.volume = this.previousVolume = this.preMuteVol = 1;
@@ -333,7 +341,7 @@ var onYouTubePlayerReady;
       if ( !loadedPlayers[this.playerId] ) {
         this.addEventListener( "load", function() {
           this.load();
-}          );
+        });
         return;
       }
       
@@ -434,16 +442,16 @@ var onYouTubePlayerReady;
           height: b.height || ( b.bottom - b.top )
         };
       } else {
-        b = this._container.getBoundingClientRect();
+        b = self._container.getBoundingClientRect();
         
         // Update bottom, right for expected values once the container loads
         return {
           left: b.left,
           top: b.top,
-          width: self.offsetWidth,
-          height: self.offsetHeight,
-          bottom: b.top + this.width,
-          right: b.top + this.height
+          width: self._target.offsetWidth,
+          height: self._target.offsetHeight,
+          bottom: b.top + self._target.offsetWidth,
+          right: b.left + self._target.offsetHeight
         };
       }
     },
index e03ecaffc0a3bbf0be28e2d7dd1bd73f9cc89272..8adf3828035cd927e76e58f6b495662a086a8976 100644 (file)
       for ( var p in clientRect ) {
         bounds[ p ] = Math.round( clientRect[ p ] );
       }
-      
       return Popcorn.extend({}, bounds, { top: top, left: left });
     }
   });