From ed48ad6a693e85777b7e7ece0408fe56f1949438 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 1 Feb 2011 17:52:07 -0500 Subject: [PATCH] testing instances --- popcorn.js | 22 ++++++++++++++++- test/instanceTester.html | 53 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 test/instanceTester.html 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 + + + + + + + + + + -- 2.43.0