]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#324] Popcorn now takes an id, or an abstracted video like object
authorScottDowne <sdowne@learn.senecac.on.ca>
Fri, 11 Mar 2011 16:22:09 +0000 (11:22 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Fri, 11 Mar 2011 16:22:09 +0000 (11:22 -0500)
popcorn.js
test/popcorn.unit.js

index 25510c578e9a041644f4d285da46109445dc187e..9b97e1c2e97ee8e8ddc634736b4449287257a143 100644 (file)
         return;
       }
 
-
+      // check if entity is a valid string id
       matches = rIdExp.exec( entity );
 
-      if ( matches.length && matches[2]  ) {
-        elem = document.getElementById(matches[2]);
-      }
+      // entity is a valid id
+      if ( matches ) {
 
+        // get video element by id
+        this.video = matches.length && matches[ 2 ] ? document.getElementById( matches[ 2 ] ) : null;
+      } else {
 
-      this.video = elem ? elem : null;
-      
-      Popcorn.addInstance(this);
+        // get video like object by reference
+        this.video = entity;
+      }
+
+      Popcorn.addInstance( this );
 
       this.data = {
         history: [],
index 56a061e236db1f83a9b9fa92e65bbd01dfafba50..32294c6fadc44643235b345328e61c83c63104ba 100755 (executable)
@@ -177,34 +177,73 @@ test("Protected", function () {
 
 
 
-test("Object", function () {
+test( "Object", function () {
 
+  var popped = Popcorn( "#video" ),
+      popObj = Popcorn( document.getElementById( "video" ) ),
+      methods = "load play pause currentTime mute volume roundTime exec removePlugin",
+      count = 0,
+      expects = 30;
   
-  var popped = Popcorn("#video"), 
-      methods = "load play pause currentTime mute volume roundTime exec removePlugin";
-  
-  
+  expect( expects );
   
-  ok( "video" in popped, "instance has `video` property" );
-  ok( Object.prototype.toString.call(popped.video) === "[object HTMLVideoElement]", "video property is a HTMLVideoElement" );
+  function plus() {
+
+    if ( ++count === expects ) {
+
+      start(); 
+    }
+  }
+
+  stop( 10000 ); 
 
-  ok( "data" in popped, "instance has `data` property" );
-  ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" );
+  // testing element passed by id
+  ok( "video" in popped, "instance by id has `video` property" );
+  plus();
+  equal( Object.prototype.toString.call( popped.video ), "[object HTMLVideoElement]", "instance by id video property is a HTMLVideoElement" );
+  plus();
 
-  ok( "trackEvents" in popped.data, "instance has `trackEvents` property" );
-  ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "trackEvents property is an object" )
+  ok( "data" in popped, "instance by id has `data` property" );
+  plus();
+  equal( Object.prototype.toString.call( popped.data ), "[object Object]", "instance by id data property is an object" );
+  plus();
+
+  ok( "trackEvents" in popped.data, "instance by id has `trackEvents` property" );
+  plus();
+  equal( Object.prototype.toString.call( popped.data.trackEvents ), "[object Object]", "instance by id trackEvents property is an object" );
+  plus();
 
-  
   popped.play();
 
+  methods.split( /\s+/g ).forEach(function ( k,v ) {
+
+    ok( k in popped, "instance by id has method: " + k );
+    plus();
+  });
 
-  methods.split(/\s+/g).forEach(function (k,v) {
+  // testing element passed by reference
+  ok( "video" in popObj, "instance by reference has `video` property" );
+  plus();
+  equal( Object.prototype.toString.call( popObj.video ), "[object HTMLVideoElement]", "instance by reference video property is a HTMLVideoElement" );
+  plus();
 
-    ok( k in popped, "instance has method: " + k );
-    
+  ok( "data" in popObj, "instance by reference has `data` property" );
+  plus();
+  equal( Object.prototype.toString.call( popObj.data ), "[object Object]", "instance by reference data property is an object" );
+  plus();
+
+  ok( "trackEvents" in popObj.data, "instance by reference has `trackEvents` property" );
+  plus();
+  equal( Object.prototype.toString.call( popObj.data.trackEvents ), "[object Object]", "instance by reference trackEvents property is an object" );
+  plus();
+
+  popObj.play();
+
+  methods.split( /\s+/g ).forEach(function ( k,v ) {
+
+    ok( k in popObj, "instance by reference has method: " + k );
+    plus();
   });
-  
-  
 });
 
 module("Popcorn Methods");