// Return new Popcorn object
return new Popcorn.p.init( entity );
};
+
+ Popcorn.instances = [];
+ Popcorn.instanceIds = {};
+
+ 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 );
+
+ delete Popcorn.instanceIds[ id ];
+
+ };
+
+ // Addes a Popcorn instance to the Popcorn instance array
+ Popcorn.addInstance = function( popcornInstance ) {
+
+ if ( !popcornInstance.video.id ) {
+
+ popcornInstance.video.id = "__popcorn" + Popcorn.instances.length;
+
+ }
+
+ Popcorn.instanceIds[ popcornInstance.video.id ] = Popcorn.instances.length;
+
+ Popcorn.instances.push( popcornInstance );
+
+ };
-
- // Declare a shortcut (Popcorn.p) to and a definition of
- // the new prototype for our Popcorn constructor
+ // User passes in the name of the Popcorn instance and receive a popcorn object
+ Popcorn.getInstanceById = function( name ) {
+
+ return Popcorn.instances[ Popcorn.instanceIds[ name ] ];
+
+ };
+
+ // Declare a shortcut (Popcorn.p) to and a definition of
+ // the new prototype for our Popcorn constructor
Popcorn.p = Popcorn.prototype = {
init: function( entity ) {
if ( matches.length && matches[2] ) {
elem = document.getElementById(matches[2]);
}
-
-
+
+
this.video = elem ? elem : null;
-
+
+ Popcorn.addInstance(this);
+
this.data = {
history: [],
events: {},