From: unknown Date: Tue, 1 Feb 2011 22:52:07 +0000 (-0500) Subject: testing instances X-Git-Tag: v0.4~26^2~8 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=ed48ad6a693e85777b7e7ece0408fe56f1949438;p=popcorn-js.git testing instances --- diff --git a/popcorn.js b/popcorn.js index 48123cf..2e80729 100644 --- a/popcorn.js +++ b/popcorn.js @@ -21,7 +21,27 @@ // Return new Popcorn object return new Popcorn.p.init( entity ); }; + + Popcorn.instances = []; + Popcorn.instanceIds = {}; + Popcorn.removeInstance = function(id) { + Popcorn.instances.splice(Popcorn.instanceIds[id], 1); + delete Popcorn.instanceIds[id]; + }; + + Popcorn.addInstance = function(popcornInstance) { + if (popcornInstance.video.id === "undefined" || !popcornInstance.video.id.length) { + popcornInstance.video.id = "__popcorn" + Popcorn.instances.length; + } + Popcorn.instanceIds[popcornInstance.video.id] = Popcorn.instances.length; + Popcorn.instances.push(popcornInstance); + }; + 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 = { @@ -86,7 +106,7 @@ this.video = elem ? elem : null; - + Popcorn.addInstance(this); this.data = { history: [], events: {}, diff --git a/test/instanceTester.html b/test/instanceTester.html new file mode 100644 index 0000000..39ff91b --- /dev/null +++ b/test/instanceTester.html @@ -0,0 +1,53 @@ + + + + Popcorn API + + + + + + + + + +