]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#725] Adds Popcorn.noConflict(); Includes 6 unit tests and updates to popcorn.unit...
authorRick Waldron <waldron.rick@gmail.com>
Fri, 23 Sep 2011 19:02:37 +0000 (15:02 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Fri, 23 Sep 2011 19:02:37 +0000 (15:02 -0400)
popcorn.js
test/popcorn.unit.js
test/popcorn.unit.setup.js

index fa99b4e747e7cff432fa6067d003ad137c4a6a32..d7af3f4fdf8d5f3fdaacb6cb8c0d68b98a0a36d4 100644 (file)
@@ -24,6 +24,9 @@
   hasOwn = OP.hasOwnProperty,
   toString = OP.toString,
 
+  // Copy global Popcorn (may not exist)
+  _Popcorn = global.Popcorn,
+
   //  ID string matching
   rIdExp  = /^(#([\w\-\_\.]+))$/,
 
 
   // 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 );
     },
         break;
       }
     }
-    
+
     this.timeUpdate( obj, null );
 
     // Store references to user added trackevents in ref table
index 5a6f18e9f49c6994ea9e228850e7f4d87d65bc77..3ee16ed475b8d1c0b50f0ebea8db06f8102ce728 100644 (file)
@@ -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 = [
-                       "<video id='video-fixture' preload='auto' controls='' style='display:;width:300px' tabindex='0'>",
-                       document.getElementById( "video" ).innerHTML,
-                       "</video>"
-                       ].join( "\n" ),
+      "<video id='video-fixture' preload='auto' controls='' style='display:;width:300px' tabindex='0'>",
+      document.getElementById( "video" ).innerHTML,
+      "</video>"
+      ].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");
index 7f1d11acdc72873ad43004eba1a73d4023f296f0..d043f4c41d16c45b3f10e977d543198b9378331f 100644 (file)
@@ -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 = {};