From d2f6d18ef72f401a4cc32582c3a0d4817a6063bf Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 11 Feb 2011 17:44:27 -0500 Subject: [PATCH] Fixed white space --- popcorn.js | 21 ++++++++++++++------- test/popcorn.unit.js | 29 ++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/popcorn.js b/popcorn.js index 1d07986..e6344ae 100644 --- a/popcorn.js +++ b/popcorn.js @@ -25,11 +25,13 @@ 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 ); @@ -39,22 +41,25 @@ }; //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 ] ]; + }; @@ -122,7 +127,9 @@ this.video = elem ? elem : null; + Popcorn.addInstance(this); + this.data = { history: [], events: {}, diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 62b0f1e..c016b4a 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -69,37 +69,52 @@ test("Utility", function () { }); 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 () { -- 2.43.0