]> source.dussan.org Git - gwtquery.git/commitdiff
-correct implementation of toggle.
authorJulien Dramaix <julien.dramaix@gmail.com>
Tue, 18 Jan 2011 22:11:49 +0000 (22:11 +0000)
committerJulien Dramaix <julien.dramaix@gmail.com>
Tue, 18 Jan 2011 22:11:49 +0000 (22:11 +0000)
-add fadeToggle methods

gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java

index 62fdb0ce5ff14a27be6b41b494af8e4015b711ab..25e5077eb9848b207d6501f3aab9183f58e65c25 100755 (executable)
@@ -44,7 +44,7 @@ public class Effects extends GQueryQueue<Effects>  {
   public static final Class<Effects> Effects = Effects.class;\r
 \r
   private static final String EFFECTS_RUNNNING = "EffectsRunnning";\r
-  \r
+\r
   static {\r
     GQuery.registerPlugin(Effects.class, new Plugin<Effects>() {\r
       public Effects init(GQuery gq) {\r
@@ -94,6 +94,7 @@ public class Effects extends GQueryQueue<Effects>  {
           anim.cancel();\r
         }\r
       }\r
+\r
       public void f(Element e) {\r
         Animation anim = new PropertiesAnimation(easing, e, p, funcs);\r
         anim.run(duration);\r
@@ -102,7 +103,7 @@ public class Effects extends GQueryQueue<Effects>  {
     });\r
     return this;\r
   }\r
-  \r
+\r
   /**\r
    * The animate() method allows us to create animation effects on any numeric CSS property. \r
    * The only required parameter is a map of CSS properties. \r
@@ -153,12 +154,12 @@ public class Effects extends GQueryQueue<Effects>  {
       ClipAnimation.Direction d, Function... f) {\r
     return clip(a, c, d, Speed.DEFAULT, f);\r
   }\r
-  \r
+\r
   /**\r
-   * Animate the set of matched elements using the clip property.\r
-   * It is possible to show or hide a set of elements, \r
-   * specify the direction of the animation and the start corner of the effect.\r
-   * Finally it executes the set of functions passed as arguments.\r
+   * Animate the set of matched elements using the clip property. It is possible\r
+   * to show or hide a set of elements, specify the direction of the animation\r
+   * and the start corner of the effect. Finally it executes the set of\r
+   * functions passed as arguments.\r
    */\r
   public Effects clip(final ClipAnimation.Action a, final ClipAnimation.Corner c, \r
       final ClipAnimation.Direction d, final int duration, final Function... f) {\r
@@ -169,12 +170,13 @@ public class Effects extends GQueryQueue<Effects>  {
           anim.cancel();\r
         }\r
       }\r
+\r
       public void f(Element e) {\r
         Animation anim = new ClipAnimation(e, a, c, d, f);\r
         anim.run(duration);\r
         data(e, EFFECTS_RUNNNING, a);\r
       }\r
-    });    \r
+    });\r
     return this;\r
   }\r
 \r
@@ -197,7 +199,7 @@ public class Effects extends GQueryQueue<Effects>  {
   public Effects clipAppear(Function... f) {\r
     return clipAppear(Speed.DEFAULT, f);\r
   }\r
-  \r
+\r
   /**\r
    * Reveal all matched elements by adjusting the clip property firing an\r
    * optional callback after completion.\r
@@ -216,7 +218,7 @@ public class Effects extends GQueryQueue<Effects>  {
   public Effects clipDisappear(Function... f) {\r
     return clipDisappear(Speed.DEFAULT, f);\r
   }\r
-  \r
+\r
   /**\r
    * Hide all matched elements by adjusting the clip property firing an\r
    * optional callback after completion.\r
@@ -245,7 +247,7 @@ public class Effects extends GQueryQueue<Effects>  {
     return clip(Action.SHOW, ClipAnimation.Corner.TOP_LEFT,\r
         ClipAnimation.Direction.BIDIRECTIONAL, millisecs, f);\r
   }\r
-  \r
+\r
   /**\r
    * Toggle the visibility of all matched elements by adjusting the clip property\r
    * and firing an optional callback after completion.\r
@@ -265,7 +267,6 @@ public class Effects extends GQueryQueue<Effects>  {
         ClipAnimation.Direction.VERTICAL, millisecs, f);\r
   }\r
 \r
-\r
   /**\r
    * Hide all matched elements by adjusting the clip property firing an\r
    * optional callback after completion.\r
@@ -336,7 +337,27 @@ public class Effects extends GQueryQueue<Effects>  {
   public Effects fadeTo(int millisecs, double opacity, Function... f) {\r
     return animate("opacity: " + opacity, millisecs, f);\r
   }\r
-  \r
+\r
+  /**\r
+   * Display or hide the matched elements by animating their opacity. and firing\r
+   * an optional callback after completion. Only the opacity is adjusted for\r
+   * this animation, meaning that all of the matched elements should already\r
+   * have some form of height and width associated with them.\r
+   */\r
+  public Effects fadeToggle(Function... f) {\r
+    return fadeToggle(Speed.DEFAULT, f);\r
+  }\r
+\r
+  /**\r
+   * Display or hide the matched elements by animating their opacity. and firing\r
+   * an optional callback after completion. Only the opacity is adjusted for\r
+   * this animation, meaning that all of the matched elements should already\r
+   * have some form of height and width associated with them.\r
+   */\r
+  public Effects fadeToggle(int millisecs, Function... f) {\r
+    return animate("opacity: 'toggle'", millisecs, f);\r
+  };\r
+\r
   /**\r
    * Reveal all matched elements by adjusting their height and firing an\r
    * optional callback after completion.\r
@@ -390,7 +411,7 @@ public class Effects extends GQueryQueue<Effects>  {
    * firing an optional callback after completion. Only the height is adjusted\r
    * for this animation, causing all matched elements to be hidden or shown in a\r
    * "sliding" manner\r
-   */  \r
+   */\r
   public Effects slideToggle(int millisecs, Function... f) {\r
     return animate("height: 'toggle'", millisecs, f);\r
   }\r
@@ -414,15 +435,41 @@ public class Effects extends GQueryQueue<Effects>  {
   /**\r
    * Toggle displaying each of the set of matched elements.\r
    */\r
-  @Override\r
-  public Effects toggle() {\r
-    return toggle(Speed.DEFAULT);\r
-  }\r
+  /*\r
+   * -> already implemented in GQuery and this is the good one\r
+   * \r
+   * @Override public Effects toggle() { return toogle(Speed.DEFAULT); }\r
+   */\r
 \r
   /**\r
    * Toggle displaying each of the set of matched elements.\r
+   * \r
+   * @param showOrHide A Boolean indicating whether to show or hide the\r
+   *          elements.\r
+   */\r
+  // maybe move this function in GQuery class directly ?\r
+  public Effects toggle(boolean showOrHide) {\r
+    for (Element element : elements()) {\r
+      GQuery $element = $(element);\r
+      if (!showOrHide) {\r
+        $element.hide();\r
+      } else {\r
+        $element.show();\r
+      }\r
+\r
+    }\r
+    return this;\r
+  }\r
+\r
+  /**\r
+   * Toggle displaying each of the set of matched elements by animating the\r
+   * width, height, and opacity of the matched elements simultaneously. When\r
+   * these properties reach 0 after a hiding animation, the display style\r
+   * property is set to none to ensure that the element no longer affects the\r
+   * layout of the page.\r
    */\r
   public Effects toggle(int millisecs, Function... f) {\r
-    return animate("opacity: 'toggle'", millisecs, f);\r
+    return animate("opacity: 'toggle', width : 'toggle', height : 'toggle'",\r
+        millisecs, f);\r
   }\r
 }\r
index 8521baf0266314ba173b2bb9d80603ad90ae827a..ff16308cf7547315f050d7489743d44b615bce2e 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.google.gwt.query.client.plugins;
 import com.google.gwt.animation.client.Animation;
+import com.google.gwt.core.client.GWT;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.NodeList;
 import com.google.gwt.query.client.Function;
@@ -219,6 +220,22 @@ public interface LazyEffects<T> extends LazyBase<T>{
    */
   LazyEffects<T> fadeTo(int millisecs, double opacity, Function... f);
 
+  /**
+   * Display or hide the matched elements by animating their opacity. and firing
+   * an optional callback after completion. Only the opacity is adjusted for
+   * this animation, meaning that all of the matched elements should already
+   * have some form of height and width associated with them.
+   */
+  LazyEffects<T> fadeToggle(Function... f);
+
+  /**
+   * Display or hide the matched elements by animating their opacity. and firing
+   * an optional callback after completion. Only the opacity is adjusted for
+   * this animation, meaning that all of the matched elements should already
+   * have some form of height and width associated with them.
+   */
+  LazyEffects<T> fadeToggle(int millisecs, Function... f);
+
   /**
    * Reveal all matched elements by adjusting their height and firing an
    * optional callback after completion.
@@ -277,11 +294,18 @@ public interface LazyEffects<T> extends LazyBase<T>{
 
   /**
    * Toggle displaying each of the set of matched elements.
+   * 
+   * @param showOrHide
+   *          A Boolean indicating whether to show or hide the elements.
    */
-  LazyEffects<T> toggle();
+  LazyEffects<T> toggle(boolean showOrHide);
 
   /**
-   * Toggle displaying each of the set of matched elements.
+   * Toggle displaying each of the set of matched elements by animating the
+   * width, height, and opacity of the matched elements simultaneously. When
+   * these properties reach 0 after a hiding animation, the display style
+   * property is set to none to ensure that the element no longer affects the
+   * layout of the page.
    */
   LazyEffects<T> toggle(int millisecs, Function... f);