Skip to content

Commit

Permalink
Support for 'oneTime' attribute + tests [#990]
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher De Cairos committed May 3, 2012
1 parent 031f483 commit 7c74407
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions popcorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,12 @@
natives.start = natives.start || natives[ "in" ];
natives.end = natives.end || natives[ "out" ];

if ( options.oneTime ) {
natives.end = combineFn( natives.end, function() {
this.removeTrackEvent( options._id );
});
}

// extend teardown to always call end if running
natives._teardown = combineFn(function() {

Expand Down
42 changes: 42 additions & 0 deletions test/popcorn.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4173,6 +4173,48 @@ test( "end undefined or false should never be fired", function() {
$pop.currentTime( $pop.duration() );
});

test( "Plugins with a oneTime attribute should be removed after 'end' is fired.", function() {

var $pop = Popcorn( "#video" ),
startFired = 0;
endFired = 0;
stop();
expect( 3 );

Popcorn.plugin( "onetimeplugin", {
start: function() {
if ( !startFired ) {
ok( true, "start called once" );
startFired++;
} else {
ok( false, "Start should oly execute once!" )
startFired++;
}
},
end: function() {
if ( !endFired ) {
ok( true, "end called once" );
this.currentTime( 0 );
endFired++;
} else {
ok( false, "End should only execute once!" );
endFired++;
}
}
});

$pop.onetimeplugin({ start: 2, end: 3, oneTime: true });

$pop.cue( 4, function() {
ok( startFired === 1 && endFired === 1, "start and end called one each" );
$pop.removePlugin( "onetimeplugin" );
$pop.destroy();
start();
});

$pop.play( 0 );
});

module( "Popcorn XHR" );
test( "Basic", function() {

Expand Down

0 comments on commit 7c74407

Please sign in to comment.