Popcorn.instances = [];
Popcorn.instanceIds = {};
- Popcorn.removeInstance = function(id) {
+ Popcorn.removeInstance = function( id ) {
// If called prior to any instances being created
// Return early to avoid splicing on nothing
if ( !Popcorn.instances.length ) {
+
return;
+
}
Popcorn.instances.splice( Popcorn.instanceIds[ id ], 1 );
};
//addes a Popcorn instance to the Popcorn instance array
- Popcorn.addInstance = function(popcornInstance) {
- if (!popcornInstance.video.id ) {
+ Popcorn.addInstance = function( popcornInstance ) {
+
+ if ( !popcornInstance.video.id ) {
popcornInstance.video.id = "__popcorn" + Popcorn.instances.length;
}
- Popcorn.instanceIds[popcornInstance.video.id] = Popcorn.instances.length;
+ Popcorn.instanceIds[ popcornInstance.video.id ] = Popcorn.instances.length;
- Popcorn.instances.push(popcornInstance);
+ Popcorn.instances.push( popcornInstance );
};
//User passes in the name of the Popcorn instance and receive a popcorn object
- Popcorn.getInstanceById = function(name) {
- return Popcorn.instances[Popcorn.instanceIds[name]];
+ Popcorn.getInstanceById = function( name ) {
+
+ return Popcorn.instances[ Popcorn.instanceIds[ name ] ];
+
};
this.video = elem ? elem : null;
+
Popcorn.addInstance(this);
+
this.data = {
history: [],
events: {},
});
test("Instances", function() {
- var popped = Popcorn("#video");
+ var popped = Popcorn("#video");
var popped2 = Popcorn("#video");
var popped3 = Popcorn("#video");
var expects = 9,
- count = 0;
+ count = 0;
expect(expects);
- function plus(){ if ( ++count == expects ) start(); }
+ function plus(){
+ if ( ++count == expects ) {
+ start();
+ }
+ }
stop();
+
ok( typeof Popcorn.addInstance === "function" , "Popcorn.addInstance is a provided utility function");
plus();
+
ok( typeof Popcorn.removeInstance === "function" , "Popcorn.removeInstance is a provided utility function");
plus();
+
ok( typeof Popcorn.getInstanceById === "function" , "Popcorn.getInstanceById is a provided utility function");
plus();
+
ok( typeof Popcorn.instanceIds === "object" , "Popcorn.instanceIds is a provided cache object");
plus();
+
ok( "length" in Popcorn.instances && "join" in Popcorn.instances, "Popcorn.instances is a provided cache array");
plus();
+
var instance;
instance = Popcorn.getInstanceById("video");
+
ok( instance.video, "Stored instance as a `video` property" );
- plus();
+ plus();
+
ok( instance.data, "Stored instance as a `data` property" );
- plus();
+ plus();
+
ok( instance instanceof Popcorn, "Instance instanceof Popcorn" );
- plus();
+ plus();
+
ok( 3 === Popcorn.instances.length, "There are the correct number of Popcorn instances" );
- plus();
+ plus();
+
});
test("guid", function () {