From: Manolo Carrasco Date: Tue, 21 Dec 2010 08:26:38 +0000 (+0000) Subject: checking nulls when creating or adding elements to JSArray. Added a couple of shortcu... X-Git-Tag: release-1.3.2~594 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=62bfc5d33a0746103d853a475f3b4b0a7a0922f6;p=gwtquery.git checking nulls when creating or adding elements to JSArray. Added a couple of shortcuts to clip effects --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index e99527cb..a14216d6 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -1030,7 +1030,7 @@ public class GQuery implements Lazy { } /** - * Returns the working set of nodes as a Java array. Do NOTDo NOT attempt to * modify this array, e.g. assign to its elements, or call Arrays.sort() */ public Element[] elements() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/JSArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/JSArray.java index 302219a0..47a5e807 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/JSArray.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/JSArray.java @@ -29,7 +29,7 @@ public class JSArray extends NodeList { } public static native JSArray create(Node node) /*-{ - return [node]; + return node ? [node] : []; }-*/; public static JSArray create(NodeList nl) { @@ -48,11 +48,11 @@ public class JSArray extends NodeList { }-*/; public final native void addNode(Node n) /*-{ - this[this.length]=n; + if (n) this[this.length]=n; }-*/; - public final native void addNode(Node ci, int i) /*-{ - this[i]=ci; + public final native void addNode(Node n, int i) /*-{ + if (n) this[i]=n; }-*/; public final native void concat(JSArray ary) /*-{ diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java index d3302452..f26352e5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java @@ -362,7 +362,7 @@ public interface LazyGQuery extends LazyBase{ LazyGQuery each(Function... f); /** - * Returns the working set of nodes as a Java array. Do NOTDo NOT attempt to * modify this array, e.g. assign to its elements, or call Arrays.sort() */ Element[] elements(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java index 2c331dbe..563eb9dc 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java @@ -117,6 +117,9 @@ public class DocumentStyleImpl { * Set the value of a style property of an element. */ public void setStyleProperty(Element e, String prop, String val) { + if (e == null || prop == null) { + return; + } prop = fixPropertyName(prop); // put it in lower-case only when all letters are upper-case, to avoid // modifying already camelized properties diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ClipAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ClipAnimation.java index 6aa219e6..9f1b291d 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ClipAnimation.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ClipAnimation.java @@ -29,7 +29,7 @@ public class ClipAnimation extends Animation { * Type of the effect action. */ public static enum Action { - HIDE, SHOW + HIDE, SHOW, TOGGLE } /** @@ -60,6 +60,9 @@ public class ClipAnimation extends Animation { public ClipAnimation(Element elem, Action a, Corner c, Direction d, final Function... funcs) { + if (a == Action.TOGGLE) { + a = GQuery.$(elem).visible() ? Action.HIDE : Action.SHOW; + } this.action = a; this.corner = c; this.direction = d; @@ -101,7 +104,6 @@ public class ClipAnimation extends Animation { } g.css("overflow", "hidden"); g.css("visivility", "visible"); - g.css("white-space", "nowrap"); super.onStart(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java index 1c95f833..62fdb0ce 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java @@ -245,6 +245,26 @@ public class Effects extends GQueryQueue { return clip(Action.SHOW, ClipAnimation.Corner.TOP_LEFT, ClipAnimation.Direction.BIDIRECTIONAL, millisecs, f); } + + /** + * Toggle the visibility of all matched elements by adjusting the clip property + * and firing an optional callback after completion. + * The effect goes from the bottom to the top. + */ + public Effects clipToggle(Function... f) { + return clipToggle(Speed.DEFAULT, f); + } + + /** + * Toggle the visibility of all matched elements by adjusting the clip property + * and firing an optional callback after completion. + * The effect goes from the bottom to the top. + */ + public Effects clipToggle(int millisecs, Function... f) { + return clip(Action.TOGGLE, ClipAnimation.Corner.TOP_LEFT, + ClipAnimation.Direction.VERTICAL, millisecs, f); + } + /** * Hide all matched elements by adjusting the clip property firing an diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java index 7596e8b0..8521baf0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java @@ -149,6 +149,20 @@ public interface LazyEffects extends LazyBase{ */ LazyEffects clipDown(int millisecs, Function... f); + /** + * Toggle the visibility of all matched elements by adjusting the clip property + * and firing an optional callback after completion. + * The effect goes from the bottom to the top. + */ + LazyEffects clipToggle(Function... f); + + /** + * Toggle the visibility of all matched elements by adjusting the clip property + * and firing an optional callback after completion. + * The effect goes from the bottom to the top. + */ + LazyEffects clipToggle(int millisecs, Function... f); + /** * Hide all matched elements by adjusting the clip property firing an * optional callback after completion.