From: Rick Waldron Date: Fri, 23 Sep 2011 19:02:37 +0000 (-0400) Subject: [#725] Adds Popcorn.noConflict(); Includes 6 unit tests and updates to popcorn.unit... X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=fd709de12f047f3ebed56e4154eb19947465cf01;p=popcorn-js.git [#725] Adds Popcorn.noConflict(); Includes 6 unit tests and updates to popcorn.unit.setup.js --- diff --git a/popcorn.js b/popcorn.js index fa99b4e..d7af3f4 100644 --- a/popcorn.js +++ b/popcorn.js @@ -24,6 +24,9 @@ hasOwn = OP.hasOwnProperty, toString = OP.toString, + // Copy global Popcorn (may not exist) + _Popcorn = global.Popcorn, + // ID string matching rIdExp = /^(#([\w\-\_\.]+))$/, @@ -280,6 +283,14 @@ // A Few reusable utils, memoized onto Popcorn Popcorn.extend( Popcorn, { + noConflict: function( deep ) { + + if ( deep ) { + global.Popcorn = _Popcorn; + } + + return Popcorn; + }, error: function( msg ) { throw new Error( msg ); }, @@ -784,7 +795,7 @@ break; } } - + this.timeUpdate( obj, null ); // Store references to user added trackevents in ref table diff --git a/test/popcorn.unit.js b/test/popcorn.unit.js index 5a6f18e..3ee16ed 100644 --- a/test/popcorn.unit.js +++ b/test/popcorn.unit.js @@ -1,46 +1,60 @@ -module("Popcorn API"); -test("API", function() { +module("Core"); +test( "Core", function() { var expects = 3, count = 0; - expect(expects); + expect( expects ); - function plus(){ if ( ++count == expects ) start(); } + function plus() { + if ( ++count == expects ) { + start(); + } + } stop( 10000 ); - try { - ok( Popcorn, "Popcorn exists"); plus(); - } catch (e) {}; - try { - ok( typeof Popcorn === "function", "Popcorn is a function"); plus(); - } catch (e) {}; try { - Popcorn(function() { - ok(1, "Popcorn calls its function argument"); plus(); + }); + } catch (e) {}; +}); +test( "noConflict", function() { - }); + expect( 6 ); - } catch (e) {}; + ok( Popcorn.noConflict, "Popcorn.noConflict exists" ); + equal( typeof Popcorn.noConflict, "function", "Popcorn.noConflict is a function" ); + var $$ = Popcorn; + deepEqual( Popcorn, Popcorn.noConflict(), "noConflict returned the Popcorn object" ); + deepEqual( Popcorn, $$, "Make sure Popcorn wasn't touched." ); + + + Popcorn = $$; + + deepEqual( Popcorn.noConflict( true ), $$, "noConflict returned the Popcorn object" ); + deepEqual( Popcorn, originalPopcorn, "Make sure Popcorn was reverted." ); + + Popcorn = $$; }); + + test("Popcorn.* Static Methods", function() { var statics = [ "forEach", "extend", "error", "guid", "sizeOf", "nop", @@ -580,10 +594,10 @@ test( "play(n)/pause(n) custom stop()", function() { }; var outerHTML = [ - "" - ].join( "\n" ), + "" + ].join( "\n" ), count = 0, expects = 2, $pop; @@ -3041,7 +3055,7 @@ test( "Popcorn.disable/enable/toggle (timeupdate)", function() { stop( 10000 ); - $pop.currentTime( 39 ).play(); + $pop.currentTime( 39 ).play(); }); module("Popcorn XHR"); diff --git a/test/popcorn.unit.setup.js b/test/popcorn.unit.setup.js index 7f1d11a..d043f4c 100644 --- a/test/popcorn.unit.setup.js +++ b/test/popcorn.unit.setup.js @@ -2,6 +2,11 @@ if ( !window[ "console" ] ) { jQuery.getScript( "https://getfirebug.com/firebug-lite-debug.js" ); } +// .noConflict() setup +var Popcorn = this.Popcorn || "Popcorn", + pop = this.pop || "pop", + originalPopcorn = Popcorn; + (function( global ) { var Setup = {};