From: ScottDowne Date: Fri, 11 Mar 2011 16:22:09 +0000 (-0500) Subject: [#324] Popcorn now takes an id, or an abstracted video like object X-Git-Tag: v0.4~10^2~4 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b18116c1c8e2ead8351bc5a0421e6112610693f1;p=popcorn-js.git [#324] Popcorn now takes an id, or an abstracted video like object --- diff --git a/popcorn.js b/popcorn.js index 25510c5..9b97e1c 100644 --- a/popcorn.js +++ b/popcorn.js @@ -130,17 +130,21 @@ 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: [], diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 56a061e..32294c6 100755 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -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");