]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#447] Update to ninja in for #475
authorstevenaw <sweerdenburg@gmail.com>
Thu, 14 Apr 2011 16:42:32 +0000 (12:42 -0400)
committerstevenaw <sweerdenburg@gmail.com>
Thu, 14 Apr 2011 16:42:32 +0000 (12:42 -0400)
players/baseplayer/popcorn.baseplayer.html
players/baseplayer/popcorn.baseplayer.js
players/baseplayer/popcorn.baseplayer.unit.js

index 73ecaeb64724fbc178c24e82b1fc55969553ec05..9417d8eaa4e884f2688b5526f9f4f3a652a1c7cf 100644 (file)
@@ -37,9 +37,9 @@
               document.getElementById( "btnPlay" ).addEventListener( "click", function() { popcorn.play(); }, false );
               document.getElementById( "btnPause" ).addEventListener( "click", function() { popcorn.pause(); }, false );
               
-              player.resource = document.getElementById('player_1');
+              player._resource = document.getElementById('player_1');
               
-              player.resource.innerHTML += '<br />Width and Height: '+player.getStyle( 'width' ) + ' by ' + player.getStyle( 'height' )
+              player._resource.innerHTML += '<br />Width and Height: '+player.getStyle( 'width' ) + ' by ' + player.getStyle( 'height' )
                                             + '<br /> Positioned at: '+player.getStyle( 'left' ) + ',' + player.getStyle( 'top' );
               
               dimensions = player.getBoundingClientRect();
index 7cc5f728ade826e108844f7eb5533f2449a7c257..e3fceada528fce3cb1b0b7a3b0c8ff66aaf4f104 100644 (file)
     this.loop;
     
     // List of events
-    this.events = {};
+    this._events = {};
     
     // The underlying player resource. May be <canvas>, <iframe>, <object>, array, etc
-    this.resource;
+    this._resource;
     // The container div of the resource
     this._container;
     
@@ -29,7 +29,7 @@
     this.offsetHeight = this.height = 0;
     this.offsetLeft = 0;
     this.offsetTop = 0;
-    this.offsetParent = 0;
+    this.offsetParent;
   }
 
   Popcorn.baseplayer.init.prototype = {
@@ -66,8 +66,8 @@
       var b,
           self = this;
           
-      if ( this.resource ) {
-        b = this.resource.getBoundingClientRect();
+      if ( this._resource ) {
+        b = this._resource.getBoundingClientRect();
         
         return {
           bottom: b.bottom,
       }
     },
     
-    // By default, assumes this.resource is a DOM Element
-    // Changing the type of this.resource requires this method to be overridden
-    // Returns the computed value for CSS style 'prop' as computed by the browser
-    getStyle: function( prop ) {
-      var elem = this.resource;
-      
-      if ( elem.currentStyle ) {
-        // IE syntax
-        return elem.currentStyle[prop];
-      } else if ( global.getComputedStyle ) {
-        // Firefox, Chrome et. al
-        return doc.defaultView.getComputedStyle( elem, null ).getPropertyValue( prop );
-      } else {
-        // Fallback, just in case
-        return elem.style[prop];
-      }
-    },
-    
     // Add an event listener to the object
     addEventListener: function( evtName, fn ) {
-      if ( !this.events[evtName] ) {
-        this.events[evtName] = [];
+      if ( !this._events[evtName] ) {
+        this._events[evtName] = [];
       }
       
-      this.events[evtName].push( fn );
+      this._events[evtName].push( fn );
       return fn;
     },
     
         }
       }
       
-      Popcorn.forEach( this.events[eventName], function( val ) {
+      Popcorn.forEach( this._events[eventName], function( val ) {
         val.call( self, evt, self );
       });
+    },
+    
+    // Extracts values from container onto this object
+    extractContainerValues: function( id ) {
+      this._container = document.getElementById( id );
+      
+      if ( !this._container ) {
+        return;
+      }
+      
+      var bounds = this._container.getBoundingClientRect();
+      
+      this.offsetWidth = this.width = container.getAttribute( "width" ) || getStyle( "width" ) || 0;
+      this.offsetHeight = this.height = container.getAttribute( "height" ) || getStyle( "height" ) || 0;
+      this.offsetLeft = bounds.left;
+      this.offsetTop = bound.top;
+      this.offsetParent = this._container.offsetParent;
+      
+      return this._container;
+    },
+    
+    // By default, assumes this.resource is a DOM Element
+    // Changing the type of this.resource requires this method to be overridden
+    // Returns the computed value for CSS style 'prop' as computed by the browser
+    getStyle: function( prop ) {
+      var elem = this._resource;
+      
+      if ( elem.currentStyle ) {
+        // IE syntax
+        return elem.currentStyle[prop];
+      } else if ( global.getComputedStyle ) {
+        // Firefox, Chrome et. al
+        return doc.defaultView.getComputedStyle( elem, null ).getPropertyValue( prop );
+      } else {
+        // Fallback, just in case
+        return elem.style[prop];
+      }
     }
   };
 })( window, document );
\ No newline at end of file
index a461aa9450bc0a6253c4b1e0bbf6fb976327b08c..22bd004cec98d860a58f9f2f137a843dbdb560f5 100644 (file)
@@ -25,11 +25,20 @@ test( "API", function () {
         'addEventListener' : 'function',
         'dispatchEvent' : 'function',
         'getBoundingClientRect' : 'function',
+        'width' : 'number',
+        'height' : 'number',
+        'offsetWidth' : 'number',
+        'offsetHeight' : 'number',
+        'offsetTop' : 'number',
+        'offsetLeft' : 'number',
+        'offsetParent' : 'undefined',
         
         // Helper functions and members
-        'events' : 'object',
-        'resource' : 'undefined',
-        'getStyle' : 'function'
+        '_events' : 'object',
+        '_resource' : 'undefined',
+        '_container' : 'undefined',
+        'getStyle' : 'function',
+        'extractContainerValues' : 'function'
       };
       
   function plus() {
@@ -69,7 +78,7 @@ test( "Default Functionality", function () {
     }
   }
   
-  player.resource = document.getElementById('player_1');
+  player._resource = document.getElementById('player_1');
   dimensions = player.getBoundingClientRect();
   
   Popcorn.forEach( expectedVals, function() {