From: unknown Date: Tue, 1 Mar 2011 20:49:40 +0000 (-0500) Subject: Merge branch '0.4' of https://github.com/annasob/popcorn-js into bug95 X-Git-Tag: v0.4~26^2~2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=9721e599a9f4d1ffa85398374babb08ed06b2d68;p=popcorn-js.git Merge branch '0.4' of https://github.com/annasob/popcorn-js into bug95 Conflicts: popcorn.js --- 9721e599a9f4d1ffa85398374babb08ed06b2d68 diff --cc popcorn.js index ff6dd32,17d20e3..e2df62f --- a/popcorn.js +++ b/popcorn.js @@@ -21,50 -21,9 +21,49 @@@ // 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 ); + + }; + // 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 + // Declare a shortcut (Popcorn.p) to and a definition of + // the new prototype for our Popcorn constructor Popcorn.p = Popcorn.prototype = { init: function( entity ) { @@@ -124,12 -83,10 +123,12 @@@ if ( matches.length && matches[2] ) { elem = document.getElementById(matches[2]); } - - + + this.video = elem ? elem : null; + + Popcorn.addInstance(this); - + this.data = { history: [], events: {}, diff --cc test/popcorn.unit.js index 66e1ce4,d264316..f6f0b6c mode 100644,100755..100755 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js