hasOwn = Object.prototype.hasOwnProperty,
slice = Array.prototype.slice,
+ // intentionally left undefined
+ undef,
+
// ID string matching
rIdExp = /^(#([\w\-\_\.]+))$/,
this.data = {
events: {},
- tracks: {
+ trackEvents: {
byStart: [{start: -1, end: -1}],
byEnd: [{start: -1, end: -1}],
startIndex: 0,
// this is so we do not fall off either end
var videoDurationPlus = that.video.duration + 1;
- Popcorn.addTrack(that, {start: videoDurationPlus, end: videoDurationPlus});
+ Popcorn.addTrackEvent(that, {start: videoDurationPlus, end: videoDurationPlus});
that.video.addEventListener( "timeupdate", function( event ) {
var currentTime = this.currentTime,
- previousTime = that.data.tracks.previousUpdateTime
- tracks = that.data.tracks,
+ previousTime = that.data.trackEvents.previousUpdateTime
+ tracks = that.data.trackEvents,
tracksByEnd = tracks.byEnd,
tracksByStart = tracks.byStart;
return dest;
};
- Popcorn.addTrack = function( obj, track ) {
+ Popcorn.addTrackEvent = function( obj, track ) {
console.log(obj);
// Store this definition in an array sorted by times
- obj.data.tracks.byStart.push( track );
- obj.data.tracks.byEnd.push( track );
- obj.data.tracks.byStart.sort( function( a, b ){
+ obj.data.trackEvents.byStart.push( track );
+ obj.data.trackEvents.byEnd.push( track );
+ obj.data.trackEvents.byStart.sort( function( a, b ){
return ( a.start - b.start );
});
- obj.data.tracks.byEnd.sort( function( a, b ){
+ obj.data.trackEvents.byEnd.sort( function( a, b ){
return ( a.end - b.end );
});
};
this.video.addEventListener( type, function( event ) {
Popcorn.forEach( self.data.events[type], function ( obj, key ) {
-
if ( typeof obj === "function" ) {
obj.call(self, event);
}
play: function () {
// renders all of the interally stored track commands
}
+ },
+ removePlugin: function( name ) {
+
+ this[name] = undef;
+
+ // remove plugin reference from registry
+ for (var i = 0, rl = Popcorn.registry.length; i < rl; i++) {
+ if (Popcorn.registry[i].type === name) {
+ Popcorn.registry.splice(i, 1);
+ break; // plugin found, stop checking
+ }
+ }
+
+ // remove all trackEvents
+ for (var trackEvent in this.data.trackEvents) {
+ // still working on this, need to clear tracks, failing one test because of it
+ }
+
}
}
};
// Extend listen and trigger to all Popcorn instances
- Popcorn.forEach( ["trigger", "listen", "unlisten"], function ( key ) {
+ Popcorn.forEach( ["trigger", "listen", "unlisten", "removePlugin"], function ( key ) {
Popcorn.p[key] = Popcorn.events.fn[key];
});
var natives = Popcorn.events.all,
reserved = [ "start", "end"],
- plugin = {},
+ plugin = {type: name},
pluginFn,
setup;
}
- Popcorn.addTrack( this, options );
+ Popcorn.addTrackEvent( this, options );
// Future support for plugin event definitions
test("Utility", function () {
- expect(6);
+ expect(7);
// TODO: comprehensive tests for these utilities
equals( typeof Popcorn.forEach, "function" , "Popcorn.forEach is a provided utility function");
equals( typeof Popcorn.guid, "function" , "Popcorn.guid is a provided utility function");
equals( typeof Popcorn.sizeOf, "function" , "Popcorn.sizeOf is a provided utility function");
equals( typeof Popcorn.nop, "function" , "Popcorn.nop is a provided utility function");
+ equals( typeof Popcorn.addTrackEvent, "function" , "Popcorn.addTrackEvent is a provided utility function");
ok( "data" in popped, "instance has `data` property" );
ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" );
- ok( "tracks" in popped.data, "instance has `tracks` property" );
- ok( Object.prototype.toString.call(popped.data.tracks) === "[object Object]", "tracks property is an object" )
+ ok( "trackEvents" in popped.data, "instance has `trackEvents` property" );
+ ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "trackEvents property is an object" )
popped.play();
var p = Popcorn("#video"),
count = 0,
fired = 0,
- wants = 4
- ;
+ wants = 4;
function plus(){
});
module("Popcorn Plugin")
+
+test("Update Timer", function () {
+
+ QUnit.reset();
+
+ var p2 = Popcorn("#video"),
+ expects = 4,
+ count = 0,
+ // These make sure events are only fired once
+ // any second call will produce a failed test
+ forwardStart = false,
+ forwardEnd = false,
+ backwardStart = false,
+ backwardEnd = false;
+
+ function plus() {
+ if ( ++count === expects ) {
+ start();
+ // clean up added events after tests
+ p2.removePlugin("forwards");
+ p2.removePlugin("backwards");
+ }
+ }
+
+ stop();
+
+ Popcorn.plugin("forwards", function () {
+ return {
+ start: function () {
+ forwardStart = !forwardStart;
+ ok( forwardStart, "forward's start fired");
+ plus();
+ },
+ end: function () {
+ forwardEnd = !forwardEnd;
+ p2.currentTime(1).play();
+ ok( forwardEnd, "forward's end fired");
+ plus();
+ }
+ };
+ });
+
+ p2.forwards({
+ start: 3,
+ end: 4
+ });
+
+ Popcorn.plugin("backwards", function () {
+ return {
+ start: function () {
+ backwardStart = !backwardStart;
+ p2.currentTime(0).play();
+ ok( true, "backward's start fired");
+ plus();
+ },
+ end: function () {
+ backwardEnd = !backwardEnd;
+ ok( backwardEnd, "backward's end fired");
+ plus();
+ }
+ };
+ });
+
+ p2.backwards({
+ start: 1,
+ end: 2
+ });
+
+ p2.currentTime(3).play();
+
+});
+
test("Plugin Factory", function () {
QUnit.reset();
ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" );
plus();
- ok( "tracks" in this.data, "executor instance has `tracks` property" );
+ ok( "trackEvents" in this.data, "executor instance has `trackEvents` property" );
plus();
- ok( Object.prototype.toString.call(popped.data.tracks) === "[object Object]", "executor tracks property is an object" )
+ ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "executor trackEvents property is an object" )
plus();
},
end: function () {
ok( Object.prototype.toString.call(popped.data) === "[object Object]", "complicator data property is an object" );
plus();
- ok( "tracks" in this.data, " complicatorinstance has `tracks` property" );
+ ok( "trackEvents" in this.data, " complicatorinstance has `trackEvents` property" );
plus();
- ok( Object.prototype.toString.call(popped.data.tracks) === "[object Object]", "complicator tracks property is an object" )
+ ok( Object.prototype.toString.call(popped.data.trackEvents) === "[object Object]", "complicator trackEvents property is an object" )
plus();
},
end: function () {