]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#414] Implements .toggle shorthand; Updates to tests; Changes per review
authorrwldrn <waldron.rick@gmail.com>
Wed, 11 May 2011 18:04:33 +0000 (14:04 -0400)
committerrwldrn <waldron.rick@gmail.com>
Wed, 11 May 2011 18:04:33 +0000 (14:04 -0400)
popcorn.js
test/popcorn.unit.js

index f80c100a2c93c5f6e9b2ad83f50a666c2c0e1162..586936bb01151499cccaceb25516fb1a16837e39 100644 (file)
     })()
   );
 
+  Popcorn.forEach( "enable disable".split(" "), function( method ) {
+    Popcorn.p[ method ] = function( plugin ) {
+      return Popcorn[ method ]( this, plugin );
+    };
+  });
+
   Popcorn.extend(Popcorn.p, {
 
     //  Rounded currentTime
     },
     position: function() {
       return Popcorn.position( this.media );
+    }, 
+    toggle: function( plugin ) {
+      return Popcorn[ this.data.disabled.indexOf( plugin ) > -1 ? "enable" : "disable" ]( this, plugin );
     }
   });
 
-  Popcorn.forEach( "enable disable".split(" "), function( method ) {
-    Popcorn.p[ method ] = function( plugin ) {
-      return Popcorn[ method ]( this, plugin );
-    };
-  });
-
   Popcorn.Events  = {
     UIEvents: "blur focus focusin focusout load resize scroll unload  ",
     MouseEvents: "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave click dblclick",
index 84d13ec1ca3a7f613be1f47b4a28e915ec2f0afe..a45f06f71729fd79c3e65f8930c9e3660025609d 100644 (file)
@@ -1696,50 +1696,79 @@ test("Index Integrity", function () {
 
 });
 
-test("Popcorn.disable/enable", function() {
+test("Popcorn.disable/enable/toggle", function() {
 
 
-  var $pop = Popcorn.getInstanceById( "video" ),
+  var $pop = Popcorn( "#video" ),
       count = 0,
-      expects = 4;
+      expects = 5;
 
   expect( expects );
 
   function plus() {
     if ( ++count === expects ) {
       start();
+
+      Popcorn.removeInstance( $pop );
     }
   }
 
-  stop( 10000 );
+  Popcorn.plugin("toggler", function () {
+    return {
+      start: function () {
+        var div = document.createElement("div");
+        div.id = "toggler-test";
+        div.innerHTML = "foo";
 
-       // rw/ff
+        document.body.appendChild(div);
+      },
+      end: function () {
+        document.getElementById("toggler-test").parentNode.removeChild(document.getElementById("toggler-test"));
+      }
+    };
+  });
 
-       // Test static function call
-       Popcorn.disable( $pop, "rw" );
+  $pop.exec( 40, function() {
 
-       ok( $pop.data.disabled.indexOf("rw") > -1, "Plugin: rw is disabled" );
-       plus();
+    console.log( "WOO!" );
+    //  make sure toggler never happened
+    // look for: "toggler-test"
 
-       // Test per-instance function call
-       $pop.disable( "ff" );
-       
-       ok( $pop.data.disabled.indexOf("ff") > -1, "Plugin: ff is disabled" );
-       plus();
+    ok( !document.getElementById("toggler-test"), "No toggler container, disabled toggler plugin correctly never ran" );
+    plus();
 
-       // Test static function call
-       Popcorn.enable( $pop, "rw" );
+    // Test per-instance toggle on
+    $pop.toggle( "toggler" );  
+    ok( $pop.data.disabled.indexOf("toggler") === -1, "toggle() plugin: toggler is re-enabled" );
+    plus();
+  });
+
+  $pop.toggler({
+    start: 40, 
+    end: 50
+  });
+
+  // rw/ff
+
+  // Test per-instance function call
+  $pop.disable( "toggler" );
+  
+  ok( $pop.data.disabled.indexOf("toggler") > -1, "disable() plugin: toggler is disabled" );
+  plus();
 
-       ok( $pop.data.disabled.indexOf("rw") === -1, "Plugin: rw is enabled" );
-       plus();
+  // Test per-instance function call
+  $pop.enable( "toggler" );  
+  
+  ok( $pop.data.disabled.indexOf("toggler") === -1, "enable() plugin: toggler is enabled" );
+  plus();
 
-       // Test per-instance function call
-       $pop.enable( "ff" );    
-       
-       ok( $pop.data.disabled.indexOf("ff") === -1, "Plugin: ff is enabled" );
-       plus();
+  // Test per-instance toggle off
+  $pop.toggle( "toggler" );  
+  
+  ok( $pop.data.disabled.indexOf("toggler") > -1, "toggle() plugin: toggler is disabled" );
+  plus();
 
-  //console.log( Popcorn.instances[ Popcorn.instanceIds.video ],  );
+  stop( 10000 );
 });
 
 module("Popcorn XHR");