},
-
-
-
-
+ exec: function ( time, fn ) {
+
+ !fn && ( fn = Popcorn.nop );
+
+
+ var timer = 0,
+ self = this,
+ callback = function execCallback( event ) {
+
+ if ( this.currentTime() >= time && !timer ) {
+
+ fn.call(self, event);
+
+ this.unlisten("execCallback");
+
+ timer++;
+ }
+ };
+
+
+
+ this.listen("timeupdate", callback);
+
+
+
+ return this;
+ },
}
// Register
- this.data.events[type][ fn.toString() + Popcorn.guid() ] = fn;
+ this.data.events[type][ fn.name || ( fn.toString() + Popcorn.guid() ) ] = fn;
// only attach one event of any type
if ( !hasEvents && Popcorn.events.all.indexOf( type ) > -1 ) {
this.video.addEventListener( type, function( event ) {
Popcorn.forEach( self.data.events[type], function ( obj, key ) {
- obj.call(self, event);
+
+ if ( typeof obj === "function" ) {
+ obj.call(self, event);
+ }
+
});
//fn.call( self, event );
}
return this;
},
- unlisten: function( type ) {
+ unlisten: function( type, fn ) {
+
+ if ( this.data.events[type] && this.data.events[type][fn] ) {
+ this.data.events[type][fn] = null;
+ return this;
+ }
+
this.data.events[type] = null;
return this;
},
var popped = Popcorn("#video"),
- methods = "load play pause currentTime mute volume roundTime";
+ methods = "load play pause currentTime mute volume roundTime exec";
+
+
ok( "video" in popped, "instance has `video` property" );
ok( Object.prototype.toString.call(popped.video) === "[object HTMLVideoElement]", "video property is a HTMLVideoElement" );
});
-module("Popcorn Object Instance");
-test("Methods", function () {
+module("Popcorn Methods");
+
+
+
+test("roundTime", function () {
QUnit.reset();
popped.play().pause().currentTime( 0.98 );
equals( 1, popped.roundTime(), ".roundTime() returns 1 when currentTime is 0.98s" );
+
+
+});
+
+
+test("exec", function () {
+
+ QUnit.reset();
+
+ var popped = Popcorn("#video"),
+ expects = 1,
+ count = 0;
+
+ expect(expects);
+
+ function plus(){
+ if ( ++count == expects ) start();
+ }
+
+ stop();
+ popped.exec( 4, function () {
+
+
+ ok(true, "exec function");
+ plus();
+
+ }).currentTime(3).play();
+
+
+
});