this.video = elem ? elem : null;
this.data = {
- events: {},
- timelines: []
+ events: {},
+ tracks: []
};
return this;
this.data.events[type] = {};
}
- // setup for custom event system
+ // Register
this.data.events[type][ fn.toString() + Popcorn.guid() ] = fn;
if ( Popcorn.events.all.indexOf( type ) > -1 ) {
Popcorn.p[key] = Popcorn.events.fn[key];
});
+ // Plugins are registered
+ Popcorn.registry = [];
// An interface for extending Popcorn
// with plugin functionality
Popcorn.plugin = function( name, definition ) {
Popcorn.extend( Popcorn.p, plugin );
-
-
-
+ if ( Popcorn.registry ) {
+ Popcorn.registry.push({
+ name: name,
+ plugin: plugin
+ });
+ }
// within the context of a plugin, the `timeupdate` or any of the events can be listened to
-
};
+
global.Popcorn = Popcorn;
ok( "data" in popped, "instance has `data` property" );
ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" );
- ok( "timelines" in popped.data, "instance has `timelines` property" );
- ok( Object.prototype.toString.call(popped.data.timelines) === "[object Array]", "timelines property is an array" )
+ ok( "tracks" in popped.data, "instance has `tracks` property" );
+ ok( Object.prototype.toString.call(popped.data.tracks) === "[object Array]", "tracks property is an array" )
});
test("Popcorn Plugin", function () {
-
-
- Popcorn.plugin("subtitles", function ( ) {
-
- console.log(this);
+ // needs expectation
+
+ var popped = Popcorn("#video"),
+ methods = "load play pause currentTime mute volume";
+ Popcorn.plugin("subtitles", function ( ) {
+
+ var self = this;
+
+ // These ensure that a popcorn instance is the value of `this` inside a plugin definition
+
+ methods.split(/\s+/g).forEach(function (k,v) {
+ ok( k in self, "instance has method: " + k );
+ });
+
+ ok( "video" in this, "instance has `video` property" );
+ ok( Object.prototype.toString.call(popped.video) === "[object HTMLVideoElement]", "video property is a HTMLVideoElement" );
+
+ ok( "data" in this, "instance has `data` property" );
+ ok( Object.prototype.toString.call(popped.data) === "[object Object]", "data property is an object" );
+
+ ok( "tracks" in this.data, "instance has `tracks` property" );
+ ok( Object.prototype.toString.call(popped.data.tracks) === "[object Array]", "tracks property is an array" )
});
- var popped = Popcorn("#video");
ok( "subtitles" in popped, "plugin is now available to instance" );
+ popped.subtitles();
-
+ ok( Popcorn.registry.length === 1, "One item in the registry");
});
-test("Popcorn Events", function () {
+
+
+test("Popcorn Events Simulated", function () {
var p = Popcorn("#video"),
eventtest = "loadstart progress suspend emptied stalled play pause " +
"loadedmetadata loadeddata waiting playing canplay canplaythrough " +
"seeking seeked timeupdate ended ratechange durationchange volumechange",
+ events = eventtest.split(/\s+/g);
+
+
+ var expects = events.length,
+ count = 0;
+
+ expect(expects);
+
+ function plus(){
+ if ( ++count == expects ) start();
+ }
+
+ stop();
+ events.forEach(function ( name ) {
+ p.listen( name, function (event) {
+
+ if ( completed.indexOf(name) === -1 ) {
+ ok(true, name + " fired");
+ plus();
+
+ completed.push(name);
+ }
+
+
+ });
+ });
+
+ events.forEach(function ( name ) {
+ p.trigger( name );
+ });
+});
+
+
+test("Popcorn Events Real", function () {
+
+
+ var p = Popcorn("#video"),
+ completed = [],
+ eventtest = "loadstart progress suspend emptied stalled play pause " +
+ "loadedmetadata loadeddata waiting playing canplay canplaythrough " +
+ "seeking seeked timeupdate ended ratechange durationchange volumechange",
events = eventtest.split(/\s+/g);