From 74e91e7fc6a0ed4e8674bf287b83a722d72a3b97 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Thu, 1 Jan 2015 20:07:28 +0100 Subject: [PATCH] move jsni start marks to new line so as eclipse formatter ignores them --- .../com/google/gwt/query/client/GQuery.java | 15 ++- .../google/gwt/query/client/LazyGQuery.java | 1 - .../google/gwt/query/client/Properties.java | 8 +- .../css/BackgroundAttachmentProperty.java | 1 - .../css/BackgroundPositionProperty.java | 1 - .../client/css/BorderCollapseProperty.java | 1 - .../client/css/BorderSpacingProperty.java | 1 - .../com/google/gwt/query/client/css/CSS.java | 12 -- .../gwt/query/client/css/HasCssValue.java | 2 +- .../gwt/query/client/css/MarginProperty.java | 4 - .../gwt/query/client/css/PaddingProperty.java | 4 - .../gwt/query/client/css/SimpleCssSetter.java | 3 +- .../gwt/query/client/css/TakesCssValue.java | 1 - .../gwt/query/client/css/TakesInteger.java | 2 +- .../gwt/query/client/css/TakesNumber.java | 2 +- .../gwt/query/client/css/ZIndexProperty.java | 5 +- .../client/impl/AttributeTridentImpl.java | 8 +- .../gwt/query/client/impl/ConsoleBrowser.java | 64 +++++++--- .../query/client/impl/DocumentStyleImpl.java | 12 +- .../client/impl/DocumentStyleImplIE.java | 8 +- .../gwt/query/client/impl/HasSelector.java | 1 - .../gwt/query/client/impl/SelectorEngine.java | 40 ++++-- .../query/client/impl/SelectorEngineImpl.java | 1 - .../client/impl/SelectorEngineSizzle.java | 10 +- .../client/impl/SelectorEngineSizzleIE.java | 10 +- .../impl/research/SelectorEngineJS.java | 44 +++++-- .../impl/research/SelectorEngineJSIE.java | 4 +- .../research/SelectorEngineSizzleGwt.java | 42 +++++-- .../impl/research/SelectorEngineXPath.java | 9 +- .../google/gwt/query/client/js/JsCache.java | 68 +++++++--- .../google/gwt/query/client/js/JsClosure.java | 4 +- .../gwt/query/client/js/JsNodeArray.java | 4 +- .../google/gwt/query/client/js/JsRegexp.java | 20 ++- .../google/gwt/query/client/js/JsUtils.java | 116 +++++++++++++----- .../gwt/query/client/plugins/Events.java | 3 - .../gwt/query/client/plugins/LazyEffects.java | 1 - .../gwt/query/client/plugins/LazyEvents.java | 1 - .../gwt/query/client/plugins/LazyWidgets.java | 1 - .../query/client/plugins/MouseOptions.java | 2 +- .../gwt/query/client/plugins/MousePlugin.java | 13 +- .../gwt/query/client/plugins/UiPlugin.java | 4 +- .../plugins/deferred/PromiseReqBuilder.java | 8 +- .../deferred/PromiseReqBuilderJSONP.java | 4 +- .../gwt/query/client/plugins/effects/Fx.java | 1 - .../client/plugins/effects/Transitions.java | 2 +- .../client/plugins/events/EventsListener.java | 24 ++-- .../query/client/plugins/events/GqEvent.java | 20 ++- .../plugins/widgets/WidgetsHtmlPanel.java | 5 +- .../client/plugins/widgets/WidgetsUtils.java | 18 ++- .../query/linker/IFrameWithDocTypeLinker.java | 1 - 50 files changed, 429 insertions(+), 207 deletions(-) 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 c8edace5..a88427e4 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 @@ -695,7 +695,6 @@ public class GQuery implements Lazy { wrapperMap.put("col", new TagWrapper(2, "", "
")); wrapperMap.put("area", new TagWrapper(1, "", "")); - } private static GQuery innerHtml(String html, Document doc) { @@ -778,12 +777,16 @@ public class GQuery implements Lazy { return engine; } - private static native void scrollIntoViewImpl(Node n) /*-{ + private static native void scrollIntoViewImpl(Node n) + /*-{ + if (n) n.scrollIntoView() }-*/; - private static native void setElementValue(Element e, String value) /*-{ + private static native void setElementValue(Element e, String value) + /*-{ + e.value = value; }-*/; @@ -1465,7 +1468,6 @@ public class GQuery implements Lazy { } return $(unique(result)); - } /** @@ -2378,7 +2380,9 @@ public class GQuery implements Lazy { return end(); } - private native Element getPreviousSiblingElement(Element elem) /*-{ + private native Element getPreviousSiblingElement(Element elem) + /*-{ + var sib = elem.previousSibling; while (sib && sib.nodeType != 1) sib = sib.previousSibling; @@ -3982,7 +3986,6 @@ public class GQuery implements Lazy { $(el).remove(); } return this; - } /** 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 8addc6db..3dbf86db 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 @@ -2549,5 +2549,4 @@ public interface LazyGQuery extends LazyBase{ * everything else. */ LazyGQuery wrapInner(String html); - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java index 0997404e..027f8840 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java @@ -89,7 +89,9 @@ public class Properties extends JavaScriptObject implements IsProperties { return this.cast(); } - public final native Properties cloneProps() /*-{ + public final native Properties cloneProps() + /*-{ + var props = {}; for(p in this) { props[p] = this[p]; @@ -180,7 +182,9 @@ public class Properties extends JavaScriptObject implements IsProperties { * Its useful for exporting or importing to javascript. * */ - public final native void setFunction(T name, Function f) /*-{ + public final native void setFunction(T name, Function f) + /*-{ + if (!f) return; this[name] = function() { f.@com.google.gwt.query.client.Function::fe(Ljava/lang/Object;)(arguments); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java index 6460b350..2be77855 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundAttachmentProperty.java @@ -46,7 +46,6 @@ public class BackgroundAttachmentProperty extends }; public abstract String getCssName(); - } private static final String CSS_PROPERTY = "backgroundAttachment"; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java index c0b37fb4..e16a5daf 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundPositionProperty.java @@ -134,7 +134,6 @@ public class BackgroundPositionProperty extends RIGHT_TOP = new BackgroundPosition(RIGHT_VALUE + " " + TOP_VALUE); TOP = new BackgroundPosition(TOP_VALUE); BOTTOM = new BackgroundPosition(BOTTOM_VALUE); - } /** diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderCollapseProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderCollapseProperty.java index 7a626105..3f5c4e66 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderCollapseProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderCollapseProperty.java @@ -45,7 +45,6 @@ public class BorderCollapseProperty extends public static void init() { CSS.BORDER_COLLAPSE = new BorderCollapseProperty(); - } private BorderCollapseProperty() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderSpacingProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderSpacingProperty.java index eee9f71d..979b5933 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderSpacingProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BorderSpacingProperty.java @@ -66,7 +66,6 @@ public class BorderSpacingProperty extends public static void init() { CSS.BORDER_SPACING = new BorderSpacingProperty(); - } private BorderSpacingProperty() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java index f55e648d..c72fa5ee 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/CSS.java @@ -15,17 +15,6 @@ */ package com.google.gwt.query.client.css; -import com.google.gwt.dom.client.Style.VerticalAlign; -import com.google.gwt.query.client.css.BackgroundAttachmentProperty.BackgroundAttachment; -import com.google.gwt.query.client.css.BackgroundPositionProperty.BackgroundPosition; -import com.google.gwt.query.client.css.BackgroundRepeatProperty.BackgroundRepeat; -import com.google.gwt.query.client.css.BorderCollapseProperty.BorderCollapse; -import com.google.gwt.query.client.css.BorderSpacingProperty.BorderSpacing; -import com.google.gwt.query.client.css.BorderWidthProperty.BorderWidth; -import com.google.gwt.query.client.css.CaptionSideProperty.CaptionSide; -import com.google.gwt.query.client.css.EmptyCellsProperty.EmptyCells; -import com.google.gwt.query.client.css.FontVariantProperty.FontVariant; -import com.google.gwt.query.client.css.ListStylePositionProperty.ListStylePosition; import com.google.gwt.query.client.css.MarginProperty.ShorthandMarginProperty; import com.google.gwt.query.client.css.PaddingProperty.ShorthandPaddingProperty; import com.google.gwt.query.client.css.UnicodeBidiProperty.UnicodeBidi; @@ -1296,6 +1285,5 @@ public class CSS { WhiteSpaceProperty.init(); WordSpacingProperty.init(); ZIndexProperty.init(); - } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HasCssValue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HasCssValue.java index e219b4d8..f6ea511a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HasCssValue.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/HasCssValue.java @@ -19,7 +19,7 @@ import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.HasCssName; /** - * Minimal contract for an object defining a css property + * Minimal contract for an object defining a css property. * */ public interface HasCssValue extends HasCssName { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java index a6cf8e41..1355276c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/MarginProperty.java @@ -40,7 +40,6 @@ public class MarginProperty extends CssProperty { */ public CssSetter with(Length margin) { return new MultipleValueCssSetter(getCssName(), margin); - } /** @@ -49,7 +48,6 @@ public class MarginProperty extends CssProperty { */ public CssSetter with(Length topAndBottom, Length leftAndRight) { return new MultipleValueCssSetter(getCssName(), topAndBottom, leftAndRight); - } /** @@ -58,7 +56,6 @@ public class MarginProperty extends CssProperty { */ public CssSetter with(Length top, Length leftAndRight, Length bottom) { return new MultipleValueCssSetter(getCssName(), top, leftAndRight, bottom); - } /** @@ -68,7 +65,6 @@ public class MarginProperty extends CssProperty { Length margin4) { return new MultipleValueCssSetter(getCssName(), margin1, margin2, margin3, margin4); - } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java index 8dbca5d3..dac18f81 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/PaddingProperty.java @@ -41,7 +41,6 @@ public class PaddingProperty extends CssProperty { */ public CssSetter with(Length padding) { return new MultipleValueCssSetter(getCssName(), padding); - } /** @@ -51,7 +50,6 @@ public class PaddingProperty extends CssProperty { public CssSetter with(Length topAndBottom, Length leftAndRight) { return new MultipleValueCssSetter(getCssName(), topAndBottom, leftAndRight); - } /** @@ -60,7 +58,6 @@ public class PaddingProperty extends CssProperty { */ public CssSetter with(Length top, Length leftAndRight, Length bottom) { return new MultipleValueCssSetter(getCssName(), top, leftAndRight, bottom); - } /** @@ -70,7 +67,6 @@ public class PaddingProperty extends CssProperty { Length padding4) { return new MultipleValueCssSetter(getCssName(), padding1, padding2, padding3, padding4); - } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/SimpleCssSetter.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/SimpleCssSetter.java index 468a1edf..fb605568 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/SimpleCssSetter.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/SimpleCssSetter.java @@ -21,7 +21,7 @@ import com.google.gwt.query.client.css.TakesCssValue.CssSetter; /** * Simple implementation of {@link CssSetter} interface. It does its job for the - * most CSS property + * most CSS property. * */ public class SimpleCssSetter implements CssSetter { @@ -41,6 +41,5 @@ public class SimpleCssSetter implements CssSetter { public void applyCss(Element e) { assert e != null : "Impossible to apply css to a null object"; e.getStyle().setProperty(property, value != null ? value : ""); - } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesCssValue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesCssValue.java index 5f9d922d..62947bb5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesCssValue.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesCssValue.java @@ -27,5 +27,4 @@ public interface TakesCssValue extends HasCssValue { } CssSetter with(T value); - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesInteger.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesInteger.java index f298feaa..1ec7fadf 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesInteger.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesInteger.java @@ -19,7 +19,7 @@ import com.google.gwt.query.client.css.TakesCssValue.CssSetter; /** * Interface to be implemented by properties which take a integer as defined in - * css2 specification + * css2 specification. * * @see http://www.w3.org/TR/CSS21/syndata.html#value-def-number */ diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesNumber.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesNumber.java index fb443198..5fefe271 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesNumber.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/TakesNumber.java @@ -19,7 +19,7 @@ import com.google.gwt.query.client.css.TakesCssValue.CssSetter; /** * Interface to be implemented by properties which take a number as defined in - * css2 specification + * css2 specification. * * @see http://www.w3.org/TR/CSS21/syndata.html#value-def-number */ diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ZIndexProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ZIndexProperty.java index 76c9bcb3..7202f5f3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ZIndexProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/ZIndexProperty.java @@ -62,9 +62,10 @@ public class ZIndexProperty implements TakesInteger { * See GWT issue 5548 * http://code.google.com/p/google-web-toolkit/issues/detail?id=5548 */ - private native String getZIndex(Style s) /*-{ + private native String getZIndex(Style s) + /*-{ + //force to return a string return "" + s["zIndex"]; }-*/; - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java index 2e22ceda..7b10f69e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java @@ -60,7 +60,9 @@ public class AttributeTridentImpl extends AttributeImpl { } } - private static native String getAttributeNode(Element e, String name)/*-{ + private static native String getAttributeNode(Element e, String name) + /*-{ + var attrNode = e.getAttributeNode(name); if (attrNode && attrNode.nodeValue !== "") { return attrNode.nodeValue; @@ -69,7 +71,9 @@ public class AttributeTridentImpl extends AttributeImpl { }-*/; private static native boolean setAttributeNode(Element e, String name, - Object value)/*-{ + Object value) + /*-{ + var attrNode = e.getAttributeNode(name); if (attrNode) { attrNode.nodeValue = value; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java index 6b7fb162..ace13666 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java @@ -31,7 +31,9 @@ public class ConsoleBrowser implements Console { */ private static class ConsoleIe8 extends ConsoleIe9 { @Override - protected native void init()/*-{ + protected native void init() + /*-{ + try { Function.prototype.call.call($wnd.console.log, $wnd.console, Array.prototype.slice.call(arguments)); this.@com.google.gwt.query.client.impl.ConsoleBrowser.ConsoleIe9::initialized = true; @@ -51,7 +53,9 @@ public class ConsoleBrowser implements Console { init(); } - protected native void init()/*-{ + protected native void init() + /*-{ + try { [ "log", "info", "warn", "error", "dir", "clear", "profile", "profileEnd" ] .forEach(function(method) { @@ -108,59 +112,87 @@ public class ConsoleBrowser implements Console { * Default implementation: webkit, opera, FF, ie10 */ private static class ConsoleImpl { - public native void clear() /*-{ + public native void clear() + /*-{ + $wnd.console.clear(); }-*/; - public native void dir(Object arg) /*-{ + public native void dir(Object arg) + /*-{ + $wnd.console.dir(arg); }-*/; - public native void error(JavaScriptObject arg) /*-{ + public native void error(JavaScriptObject arg) + /*-{ + $wnd.console.error.apply($wnd.console, arg); }-*/; - public native void group(Object arg) /*-{ + public native void group(Object arg) + /*-{ + $wnd.console.group(arg); }-*/; - public native void groupCollapsed(Object arg) /*-{ + public native void groupCollapsed(Object arg) + /*-{ + $wnd.console.groupCollapsed(arg); }-*/; - public native void groupEnd() /*-{ + public native void groupEnd() + /*-{ + $wnd.console.groupEnd(); }-*/; - public native void info(JavaScriptObject arg) /*-{ + public native void info(JavaScriptObject arg) + /*-{ + $wnd.console.info.apply($wnd.console, arg); }-*/; - public native void log(JavaScriptObject arg) /*-{ + public native void log(JavaScriptObject arg) + /*-{ + $wnd.console.log.apply($wnd.console, arg); }-*/; - public native void profile(String title) /*-{ + public native void profile(String title) + /*-{ + $wnd.console.profile(title); }-*/; - public native void profileEnd(String title) /*-{ + public native void profileEnd(String title) + /*-{ + $wnd.console.profileEnd(title); }-*/; - public native void time(String title) /*-{ + public native void time(String title) + /*-{ + $wnd.console.time(title); }-*/; - public native void timeEnd(String title) /*-{ + public native void timeEnd(String title) + /*-{ + $wnd.console.timeEnd(title); }-*/; - public native void timeStamp(Object arg) /*-{ + public native void timeStamp(Object arg) + /*-{ + $wnd.console.timeStamp(arg); }-*/; - public native void warn(JavaScriptObject arg) /*-{ + public native void warn(JavaScriptObject arg) + /*-{ + $wnd.console.warn.apply($wnd.console, arg); }-*/; } 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 4bd133ec..585cb4a1 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 @@ -251,7 +251,9 @@ public class DocumentStyleImpl { } protected native String getComputedStyle(Element elem, String hyphenName, - String camelName, String pseudo) /*-{ + String camelName, String pseudo) + /*-{ + try { var cStyle = $doc.defaultView.getComputedStyle(elem, pseudo); return cStyle && cStyle.getPropertyValue ? cStyle.getPropertyValue(hyphenName) : null; @@ -278,14 +280,18 @@ public class DocumentStyleImpl { return ret; } - public native Document getContentDocument(Node n) /*-{ + public native Document getContentDocument(Node n) + /*-{ + var d = n.contentDocument || n.document || n.contentWindow.document; if (!d.body) this.@com.google.gwt.query.client.impl.DocumentStyleImpl::emptyDocument(Lcom/google/gwt/dom/client/Document;)(d); return d; }-*/; - public native void emptyDocument(Document d) /*-{ + public native void emptyDocument(Document d) + /*-{ + d.open(); d.write(""); d.close(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java index 04074656..6193dff3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java @@ -62,7 +62,9 @@ public class DocumentStyleImplIE extends DocumentStyleImpl { /** * Remove a style property from an element. */ - public native void removeStyleProperty(Element e, String prop) /*-{ + public native void removeStyleProperty(Element e, String prop) + /*-{ + if (e && e.style && 'removeAttribute' in e) e.style.removeAttribute(prop); }-*/; @@ -82,7 +84,9 @@ public class DocumentStyleImplIE extends DocumentStyleImpl { @Override protected native String getComputedStyle(Element elem, String hyphenName, - String camelName, String pseudo) /*-{ + String camelName, String pseudo) + /*-{ + // code lifted from jQuery if (!elem.style || !'currentStyle' in elem || !'runtimeStyle' in elem) return null; var style = elem.style; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/HasSelector.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/HasSelector.java index 8ca0a3b7..b8e6fc67 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/HasSelector.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/HasSelector.java @@ -29,5 +29,4 @@ public interface HasSelector { * @return a list of matched nodes */ NodeList select(String selector, Node ctx); - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java index 858ee141..9a8d16d0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java @@ -41,15 +41,21 @@ public class SelectorEngine implements HasSelector { private static DocumentStyleImpl styleImpl; public static native NodeList getElementsByClassName(String clazz, - Node ctx) /*-{ + Node ctx) + /*-{ + return ctx.getElementsByClassName(clazz); }-*/; - public static native Node getNextSibling(Node n) /*-{ + public static native Node getNextSibling(Node n) + /*-{ + return n.nextSibling || null; }-*/; - public static native Node getPreviousSibling(Node n) /*-{ + public static native Node getPreviousSibling(Node n) + /*-{ + return n.previousSibling || null; }-*/; @@ -65,17 +71,23 @@ public class SelectorEngine implements HasSelector { } public static native NodeList querySelectorAllImpl(String selector, - Node ctx) /*-{ + Node ctx) + /*-{ + return ctx.querySelectorAll(selector); }-*/; public static native NodeList elementsByTagName(String selector, - Node ctx) /*-{ + Node ctx) + /*-{ + return ctx.getElementsByTagName(selector); }-*/; public static native NodeList elementsByClassName(String selector, - Node ctx) /*-{ + Node ctx) + /*-{ + return ctx.getElementsByClassName(selector); }-*/; @@ -90,7 +102,9 @@ public class SelectorEngine implements HasSelector { } public static native NodeList xpathEvaluate(String selector, - Node ctx, JsNodeArray r) /*-{ + Node ctx, JsNodeArray r) + /*-{ + var node; var ownerDoc = ctx && (ctx.ownerDocument || ctx ); var evalDoc = ownerDoc ? ownerDoc : $doc; @@ -263,7 +277,9 @@ public class SelectorEngine implements HasSelector { } } - public native boolean contains(Element a, Element b) /*-{ + public native boolean contains(Element a, Element b) + /*-{ + return a.contains ? a != b && a.contains(b) : !!(a.compareDocumentPosition(b) & 16) }-*/; @@ -283,12 +299,16 @@ public class SelectorEngine implements HasSelector { /** * Check if the browser has native support for css selectors */ - public static native boolean hasQuerySelectorAll() /*-{ + public static native boolean hasQuerySelectorAll() + /*-{ + return $doc.location.href.indexOf("_force_no_native") < 0 && typeof $doc.querySelectorAll == 'function'; }-*/; - public static native boolean hasXpathEvaluate() /*-{ + public static native boolean hasXpathEvaluate() + /*-{ + return !!$doc.evaluate; }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java index a957334c..bc2a4587 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineImpl.java @@ -19,5 +19,4 @@ package com.google.gwt.query.client.impl; * Base/Utility class for runtime selector engine implementations. */ public abstract class SelectorEngineImpl implements HasSelector { - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzle.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzle.java index 718883bc..927a5259 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzle.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzle.java @@ -28,7 +28,9 @@ import com.google.gwt.dom.client.NodeList; */ public class SelectorEngineSizzle extends SelectorEngineImpl { - public static native void initialize() /*-{ + public static native void initialize() + /*-{ + (function(){ var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, @@ -1088,12 +1090,12 @@ var posProcess = function(selector, context){ window.GQS = GQS; $wnd.GQS = GQS; - })(); - }-*/; - private static native JsArray select(String selector, Node context, JsArray results, JsArray seed) /*-{ + private static native JsArray select(String selector, Node context, JsArray results, JsArray seed) + /*-{ + return $wnd.GQS(selector, context, results, seed); }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleIE.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleIE.java index b4130f97..227e1a4b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleIE.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineSizzleIE.java @@ -40,7 +40,9 @@ import com.google.gwt.dom.client.NodeList; */ public class SelectorEngineSizzleIE extends SelectorEngineImpl { - public static native void initialize() /*-{ + public static native void initialize() + /*-{ + (function(){ var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, @@ -928,12 +930,12 @@ var posProcess = function(selector, context){ window.IES = IES; $wnd.IES = IES; - })(); - }-*/; - private static native JsArray select(String selector, Node context, JsArray results, JsArray seed) /*-{ + private static native JsArray select(String selector, Node context, JsArray results, JsArray seed) + /*-{ + return $wnd.IES(selector, context, results, seed); }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java index 92da332d..733848f8 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java @@ -139,24 +139,34 @@ public class SelectorEngineJS extends SelectorEngineImpl { } } - public static native void clearAdded(Node node) /*-{ + public static native void clearAdded(Node node) + /*-{ + node.added = null; }-*/; public static native NodeList getElementsByClassName(String clazz, - Node ctx) /*-{ + Node ctx) + /*-{ + return ctx.getElementsByClassName(clazz); }-*/; - public static native boolean isAdded(Node prevRef) /*-{ + public static native boolean isAdded(Node prevRef) + /*-{ + return prevRef.added || false; }-*/; - public static native void setAdded(Node prevRef, boolean added) /*-{ + public static native void setAdded(Node prevRef, boolean added) + /*-{ + prevRef.added = added; }-*/; - public static native void setSkipTag(JsNodeArray prevElem, boolean skip) /*-{ + public static native void setSkipTag(JsNodeArray prevElem, boolean skip) + /*-{ + prevElem.skipTag = skip; }-*/; @@ -179,7 +189,9 @@ public class SelectorEngineJS extends SelectorEngineImpl { return JsUtils.truth(attrVal) ? "^" + attrVal + "$" : null; } - private static native boolean checked(Node previous) /*-{ + private static native boolean checked(Node previous) + /*-{ + return previous.checked || false; }-*/; @@ -189,7 +201,9 @@ public class SelectorEngineJS extends SelectorEngineImpl { } } - private static native boolean enabled(Node node) /*-{ + private static native boolean enabled(Node node) + /*-{ + return !node.disabled; }-*/; @@ -238,20 +252,28 @@ public class SelectorEngineJS extends SelectorEngineImpl { } } - private static native boolean hasChildElms(Node prevParent) /*-{ + private static native boolean hasChildElms(Node prevParent) + /*-{ + return prevParent.childElms || false; }-*/; - private static native boolean isSkipped(JsNodeArray prevElem) /*-{ + private static native boolean isSkipped(JsNodeArray prevElem) + /*-{ + return prevElem.skipTag || false; }-*/; - private static native void setHasChildElms(Node prevParent, boolean bool) /*-{ + private static native void setHasChildElms(Node prevParent, boolean bool) + /*-{ + prevParent.childElms = bool ? bool : null; }-*/; private static native JsNodeArray subtractArray(JsNodeArray previousMatch, - JsNodeArray elementsByPseudo) /*-{ + JsNodeArray elementsByPseudo) + /*-{ + for (var i=0, src1; (src1=arr1[i]); i++) { var found = false; for (var j=0, src2; (src2=arr2[j]); j++) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java index f02eb857..3bd5da24 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJSIE.java @@ -23,7 +23,9 @@ import com.google.gwt.dom.client.Element; */ public class SelectorEngineJSIE extends SelectorEngineJS { - public native String getAttr(Element elm, String attr) /*-{ + public native String getAttr(Element elm, String attr) + /*-{ + switch (attr) { case "id": return elm.id; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java index c536c3c8..2374cf96 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineSizzleGwt.java @@ -28,12 +28,14 @@ import com.google.gwt.query.client.js.JsUtils; * Sizzle CSS Selector Engine v1.0. * * It has so many JSNI code, the idea is to make an entire implementation - * using Java. Right now it performs worse than pure JSNI implementation + * using Java. Right now it performs worse than pure JSNI implementation. * */ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { - public static native boolean contains(Object a, Object b) /*-{ + public static native boolean contains(Object a, Object b) + /*-{ + var ret = document.compareDocumentPosition ? (a.compareDocumentPosition(b) & 16): @@ -41,7 +43,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { return ret ? true : false; }-*/; - public static native JavaScriptObject createExpr() /*-{ + public static native JavaScriptObject createExpr() + /*-{ + var done = 0; $wnd.Expr = { order: [ "ID", "NAME", "TAG" ], @@ -431,7 +435,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { return $wnd.Expr; }-*/; - public static native void dirCheck(String dir, Object cur, int doneName, Object checkSet) /*-{ + public static native void dirCheck(String dir, Object cur, int doneName, Object checkSet) + /*-{ + for ( var i = 0, l = checkSet.length; i < l; i++ ) { var elem = checkSet[i]; if ( elem ) { @@ -462,7 +468,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { } }-*/; - public static native void dirNodeCheck(String dir, Object cur, int doneName, Object checkSet) /*-{ + public static native void dirNodeCheck(String dir, Object cur, int doneName, Object checkSet) + /*-{ + for ( var i = 0, l = checkSet.length; i < l; i++ ) { var elem = checkSet[i]; if ( elem ) { @@ -492,7 +500,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { throw new IllegalArgumentException("Syntax error, unrecognized expression: " + msg); } - public static native JsArray filter(String expr, JsArray set, boolean inplace, Object not) /*-{ + public static native JsArray filter(String expr, JsArray set, boolean inplace, Object not) + /*-{ + var old = expr, result = [], curLoop = set, match, anyFound; while ( expr && set.length ) { for ( var type in $wnd.Expr.filter ) { @@ -558,7 +568,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { return curLoop; }-*/; - public static native JavaScriptObject find(String expr, Node context) /*-{ + public static native JavaScriptObject find(String expr, Node context) + /*-{ + var set, match; if ( !expr ) { return []; @@ -586,7 +598,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { return {set: set, expr: expr}; }-*/; - public static native String getText(Object elems) /*-{ + public static native String getText(Object elems) + /*-{ + var ret = "", elem; for ( var i = 0; elems[i]; i++ ) { elem = elems[i]; @@ -601,7 +615,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { return ret; }-*/; - public static native JsArray makeArray(NodeList array, JsArray results) /*-{ + public static native JsArray makeArray(NodeList array, JsArray results) + /*-{ + var ret = results || []; if ( Object.prototype.toString.call(array) === "[object Array]" ) { Array.prototype.push.apply( ret, array ); @@ -619,7 +635,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { return ret; }-*/; - public static native JsArray posProcess(String selector, Node context) /*-{ + public static native JsArray posProcess(String selector, Node context) + /*-{ + var tmpSet = [], later = "", match, root = context.nodeType ? [context] : context; // Position selectors must be done after the filter // And so must :not(positional) so we move all PSEUDOs to the end @@ -634,7 +652,9 @@ public class SelectorEngineSizzleGwt extends SelectorEngineImpl { return @com.google.gwt.query.client.impl.research.SelectorEngineSizzleGwt::filter(Ljava/lang/String;Lcom/google/gwt/core/client/JsArray;ZLjava/lang/Object;)( later, tmpSet, false ); }-*/; - private static native JsArray select(String selector, Node context, JsArray results, JsArray seed) /*-{ + private static native JsArray select(String selector, Node context, JsArray results, JsArray seed) + /*-{ + results = results || []; var origContext = context = context || document; var parts = [], m, set, checkSet, extra, prune = true, soFar = selector; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java index 47322d6c..c2de9b6d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java @@ -234,16 +234,19 @@ public class SelectorEngineXPath extends SelectorEngineImpl { return xpath; } - private native String replaceAttr(String allAttr) /*-{ + private native String replaceAttr(String allAttr) + /*-{ + if(!allAttr) return ""; return allAttr.replace(/["']+/g,'').replace(/(\w+)(\^|\$|\*|\||~)?=?([\w\u00C0-\uFFFF\s\-_\.]+)?/g, function(a,b,c,d) { return @com.google.gwt.query.client.impl.research.SelectorEngineXPath::attrToXPath(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)(a,b || "",c || "",d || ""); }); - }-*/; - private native String replaceAttr2(String allAttr) /*-{ + private native String replaceAttr2(String allAttr) + /*-{ + if(!allAttr) return ""; return allAttr.replace(/\[(\w+)(\^|\$|\*|\||~)?=?([\w\u00C0-\uFFFF\s\-_\.]+)?\]/g, @com.google.gwt.query.client.impl.research.SelectorEngineXPath::attrToXPath(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)); }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java index dff21481..e63eb076 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java @@ -32,7 +32,9 @@ public class JsCache extends JavaScriptObject { return createObject().cast(); } - public final native void concat(Object ary) /*-{ + public final native void concat(Object ary) + /*-{ + if (ary) this.concat(ary); }-*/; @@ -50,7 +52,9 @@ public class JsCache extends JavaScriptObject { } } - public final native void delete(Object name) /*-{ + public final native void delete(Object name) + /*-{ + delete this[name]; }-*/; @@ -60,7 +64,9 @@ public class JsCache extends JavaScriptObject { } } - public final native boolean exists(Object name) /*-{ + public final native boolean exists(Object name) + /*-{ + return !!this[name]; }-*/; @@ -84,7 +90,9 @@ public class JsCache extends JavaScriptObject { return (T)o; } - public final native T get(Object id) /*-{ + public final native T get(Object id) + /*-{ + return @com.google.gwt.query.client.js.JsCache::gwtBox(*)([ this && this[id] ]); }-*/; @@ -112,11 +120,15 @@ public class JsCache extends JavaScriptObject { return r == null ? 0 : r; } - public final native String getString(Object id) /*-{ + public final native String getString(Object id) + /*-{ + return this[id] == null ? null : String(this[id]); }-*/; - public final native JsArrayMixed getArray(Object id) /*-{ + public final native JsArrayMixed getArray(Object id) + /*-{ + var r = this[id]; if (Object.prototype.toString.call(r) == '[object Array]') { return r; @@ -129,31 +141,43 @@ public class JsCache extends JavaScriptObject { return (o != null && o instanceof JavaScriptObject) ? ((JavaScriptObject)o).cast() : null; } - public final native boolean isEmpty() /*-{ + public final native boolean isEmpty() + /*-{ + for (k in this) return false; return true; }-*/; - public final native boolean contains(Object o)/*-{ + public final native boolean contains(Object o) + /*-{ + return this.indexOf(o) >= 0; }-*/; - public final native void remove(Object o) /*-{ + public final native void remove(Object o) + /*-{ + var i = this.indexOf(o); if (i >= 0) this.splice(i, 1); }-*/; - public final native int indexOf(Object o) /*-{ + public final native int indexOf(Object o) + /*-{ + // HtmlUnit fails when this returns 0 return this.indexOf(o); }-*/; - public final native JsCache putBoolean(Object id, boolean b) /*-{ + public final native JsCache putBoolean(Object id, boolean b) + /*-{ + this[id] = b; return this; }-*/; - public final native JsCache putNumber(Object id, double n) /*-{ + public final native JsCache putNumber(Object id, double n) + /*-{ + this[id] = n; return this; }-*/; @@ -169,12 +193,16 @@ public class JsCache extends JavaScriptObject { return this; } - public final native JsCache putObject(Object id, Object obj) /*-{ + public final native JsCache putObject(Object id, Object obj) + /*-{ + this[id] = obj; return this; }-*/; - public final native int length() /*-{ + public final native int length() + /*-{ + if (typeof(this.length) == 'number') return this.length; @@ -231,7 +259,9 @@ public class JsCache extends JavaScriptObject { checkNull(this); } - private final native JsArrayString keysImpl() /*-{ + private final native JsArrayString keysImpl() + /*-{ + var key, keys=[]; // Chrome in DevMode sets '__gwt_ObjectId' to JS objects // GWT sets '$H' when calling getHashCode (see com/google/gwt/core/client/impl/Impl.java) @@ -260,14 +290,18 @@ public class JsCache extends JavaScriptObject { * * Example *
-   * native Object myMethod() /*-{
+   * native Object myMethod()
+  /*-{
+
    *   var myJsVar = ... ;
    *   return @com.google.gwt.query.client.js.JsCache::gwtBox(*)([ myJsVar ]);
    * }-* /
    * 
* */ - public static native Object gwtBox(JavaScriptObject oneElementArray) /*-{ + public static native Object gwtBox(JavaScriptObject oneElementArray) + /*-{ + var r = oneElementArray; if (typeof r == 'object' && r.length == 1) { var r = r[0], t = typeof r; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsClosure.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsClosure.java index 2481325d..ceb5fe51 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsClosure.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsClosure.java @@ -28,7 +28,9 @@ public class JsClosure extends JavaScriptObject { /** * Invoke the closure with no arguments and expecting no return value. */ - public final native void invoke() /*-{ + public final native void invoke() + /*-{ + return this(); }-*/; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java index 8b989a50..7101f840 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java @@ -29,7 +29,9 @@ public class JsNodeArray extends NodeList { return create((Node)null); } - public static native JsNodeArray create(Node node) /*-{ + public static native JsNodeArray create(Node node) + /*-{ + return node ? [node] : []; }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java index b4018cf8..d5c977ba 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java @@ -24,11 +24,15 @@ import com.google.gwt.core.client.JavaScriptObject; @Deprecated public class JsRegexp { - public static native JavaScriptObject compile(String pat) /*-{ + public static native JavaScriptObject compile(String pat) + /*-{ + return new RegExp(pat); }-*/; - public static native JavaScriptObject compileFlags(String pat, String flags) /*-{ + public static native JavaScriptObject compileFlags(String pat, String flags) + /*-{ + return new RegExp(pat, flags); }-*/; @@ -36,7 +40,9 @@ public class JsRegexp { return new JsRegexp(regexp, flags).match(string); } - private static native JsObjectArray exec0(JavaScriptObject regexp, String str) /*-{ + private static native JsObjectArray exec0(JavaScriptObject regexp, String str) + /*-{ + return regexp.exec(str); }-*/; @@ -70,11 +76,15 @@ public class JsRegexp { return test0(regexp, rule); } - private native JsObjectArray match0(JavaScriptObject regexp, String currentRule)/*-{ + private native JsObjectArray match0(JavaScriptObject regexp, String currentRule) + /*-{ + return currentRule.match(regexp); }-*/; - private native boolean test0(JavaScriptObject regexp, String rule) /*-{ + private native boolean test0(JavaScriptObject regexp, String rule) + /*-{ + return regexp.test(rule); }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java index f59a2b75..73438417 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java @@ -49,7 +49,9 @@ public class JsUtils { return jso.equals(obj); } - private native Object exec(JavaScriptObject f, Object data) /*-{ + private native Object exec(JavaScriptObject f, Object data) + /*-{ + return @com.google.gwt.query.client.js.JsCache::gwtBox(*)([ f(data) ]); }-*/; @@ -68,7 +70,9 @@ public class JsUtils { * Wraps a GQuery function into a native javascript one so as we can * export Java methods without using JSNI. */ - public static native JavaScriptObject wrapFunction (Function f) /*-{ + public static native JavaScriptObject wrapFunction (Function f) + /*-{ + return function(r) { var o = @java.util.ArrayList::new()(); for (i in arguments) { @@ -82,15 +86,21 @@ public class JsUtils { }-*/; public static class JsUtilsImpl { - public native Properties parseJSON(String json) /*-{ + public native Properties parseJSON(String json) + /*-{ + return $wnd.JSON.parse(json); }-*/; - public native String JSON2String(JavaScriptObject o) /*-{ + public native String JSON2String(JavaScriptObject o) + /*-{ + return $wnd.JSON.stringify(o); }-*/; - public native Element parseXML(String xml) /*-{ + public native Element parseXML(String xml) + /*-{ + return new DOMParser().parseFromString(xml, "text/xml").documentElement; }-*/; @@ -112,13 +122,17 @@ public class JsUtils { return ret; } - public native String XML2String(JavaScriptObject o) /*-{ + public native String XML2String(JavaScriptObject o) + /*-{ + return (new XMLSerializer()).serializeToString(o); }-*/; } public static class JsUtilsImplIE6 extends JsUtilsImpl { - public static final native Properties evalImpl(String properties) /*-{ + public static final native Properties evalImpl(String properties) + /*-{ + return eval(properties); }-*/; @@ -165,7 +179,9 @@ public class JsUtils { } @Override - public native Element parseXML(String xml) /*-{ + public native Element parseXML(String xml) + /*-{ + var d = new ActiveXObject("Microsoft.XmlDom"); d.loadXML(xml); return d.documentElement; @@ -186,11 +202,15 @@ public class JsUtils { } @Override - public native String XML2String(JavaScriptObject o) /*-{ + public native String XML2String(JavaScriptObject o) + /*-{ + return o.xml; }-*/; - private native String xmlText(Element e) /*-{ + private native String xmlText(Element e) + /*-{ + return e.text; }-*/; } @@ -223,7 +243,9 @@ public class JsUtils { /** * Camelize style property names. for instance: font-name -> fontName */ - public static native String camelize(String s)/*-{ + public static native String camelize(String s) + /*-{ + return s.replace(/\-(\w)/g, function(all, letter) { return letter.toUpperCase(); }); @@ -266,14 +288,18 @@ public class JsUtils { /** * Compare two numbers using javascript equality. */ - public static native boolean eq(double s1, double s2) /*-{ + public static native boolean eq(double s1, double s2) + /*-{ + return s1 == s2; }-*/; /** * Compare two objects using javascript equality. */ - public static native boolean eq(Object s1, Object s2) /*-{ + public static native boolean eq(Object s1, Object s2) + /*-{ + return s1 == s2; }-*/; @@ -289,7 +315,9 @@ public class JsUtils { * Check if an object has already a property with name name * defined. */ - public static native boolean hasProperty(JavaScriptObject o, String name)/*-{ + public static native boolean hasProperty(JavaScriptObject o, String name) + /*-{ + return o && name in o; }-*/; @@ -298,21 +326,27 @@ public class JsUtils { * implementation returns an empty string instead of null when the attribute is not * present */ - public static native boolean hasAttribute(Element o, String name)/*-{ + public static native boolean hasAttribute(Element o, String name) + /*-{ + return !!(o && o.getAttribute(name)); }-*/; /** * Hyphenize style property names. for instance: fontName -> font-name */ - public static native String hyphenize(String name) /*-{ + public static native String hyphenize(String name) + /*-{ + return name.replace(/([A-Z])/g, "-$1").toLowerCase(); }-*/; /** * Check is a javascript object can be used as an array */ - public static native boolean isArray(JavaScriptObject o) /*-{ + public static native boolean isArray(JavaScriptObject o) + /*-{ + return Object.prototype.toString.call(o) == '[object Array]' || typeof o.length == 'number'; }-*/; @@ -320,14 +354,18 @@ public class JsUtils { /** * Check is a javascript object is a FormData */ - public static native boolean isFormData(JavaScriptObject o) /*-{ + public static native boolean isFormData(JavaScriptObject o) + /*-{ + return Object.prototype.toString.call(o) == '[object FormData]'; }-*/; /** * Return whether the event was prevented */ - public static native boolean isDefaultPrevented(JavaScriptObject e)/*-{ + public static native boolean isDefaultPrevented(JavaScriptObject e) + /*-{ + return e.defaultPrevented || e.returnValue === false || e.getPreventDefault && e.getPreventDefault() ? true : false; }-*/; @@ -349,7 +387,9 @@ public class JsUtils { /** * Check is a javascript object can be cast to an Element */ - public static native boolean isElement(Object o) /*-{ + public static native boolean isElement(Object o) + /*-{ + return o && o.nodeType && o.nodeName ? true : false; }-*/; @@ -363,14 +403,18 @@ public class JsUtils { /** * Check is a javascript object is a function */ - public static native boolean isFunction(JavaScriptObject o) /*-{ + public static native boolean isFunction(JavaScriptObject o) + /*-{ + return Object.prototype.toString.call(o) == '[object Function]'; }-*/; /** * Check is a javascript can be cast to a node list */ - public static native boolean isNodeList(JavaScriptObject o) /*-{ + public static native boolean isNodeList(JavaScriptObject o) + /*-{ + var r = Object.prototype.toString.call(o); return r == '[object HTMLCollection]' || r == '[object NodeList]' || (typeof o == 'object' && o.length && o[0].tagName) ? true : false; @@ -411,14 +455,18 @@ public class JsUtils { /** * Return the element which is truth in the double scope. */ - public static native double or(double s1, double s2) /*-{ + public static native double or(double s1, double s2) + /*-{ + return s1 || s2; }-*/; /** * Return the element which is truth in the javascript scope. */ - public static native T or(T s1, T s2) /*-{ + public static native T or(T s1, T s2) + /*-{ + return s1 || s2; }-*/; @@ -454,14 +502,18 @@ public class JsUtils { * Utility method to cast objects in production. * Useful for casting native implementations to interfaces like JsInterop */ - public static native T cast(Object o) /*-{ + public static native T cast(Object o) + /*-{ + return o; }-*/; /** * Utility method to cast objects to array of string in production. */ - public static native String[] castArrayString(Object a)/*-{ + public static native String[] castArrayString(Object a) + /*-{ + return a }-*/; @@ -488,7 +540,9 @@ public class JsUtils { return runJavascriptFunctionImpl(o, meth, JsObjectArray.create().add(args).cast()); } - private static native T runJavascriptFunctionImpl(JavaScriptObject o, String meth, JsArrayMixed args) /*-{ + private static native T runJavascriptFunctionImpl(JavaScriptObject o, String meth, JsArrayMixed args) + /*-{ + return (f = o && o[meth]) && @com.google.gwt.query.client.js.JsUtils::isFunction(*)(f) && @com.google.gwt.query.client.js.JsCache::gwtBox(*)([f.apply(o, args)]); @@ -497,14 +551,18 @@ public class JsUtils { /** * Check if a number is true in the javascript scope. */ - public static native boolean truth(double a) /*-{ + public static native boolean truth(double a) + /*-{ + return a ? true : false; }-*/; /** * Check if an object is true in the javascript scope. */ - public static native boolean truth(Object a) /*-{ + public static native boolean truth(Object a) + /*-{ + return a ? true : false; }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java index 901e3892..c614a08c 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java @@ -130,14 +130,12 @@ public class Events extends GQuery { public GQuery live(int eventbits, final Object data, Function... funcs) { return live(eventbits, null, data, funcs); - } public GQuery live(int eventbits, String nameSpace, final Object data, Function... funcs) { EventsListener.getInstance(Element.is(currentContext) ? (Element) currentContext : body).live( eventbits, nameSpace, null, null, currentSelector, data, funcs); return this; - } public GQuery live(String eventName, final Object data, Function... funcs) { @@ -183,7 +181,6 @@ public class Events extends GQuery { } return bind("mouseleave", null, fs); - } /** 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 5178862d..6827487c 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 @@ -386,5 +386,4 @@ public interface LazyEffects extends LazyBase{ * layout of the page. */ LazyEffects toggle(int millisecs, Function... f); - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java index 7ba49eed..830f91df 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java @@ -180,5 +180,4 @@ public interface LazyEvents extends LazyBase{ LazyEvents unbind(String name, Function f); LazyEvents undelegate(); - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java index fac96f09..fbc994f3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java @@ -107,5 +107,4 @@ public interface LazyWidgets extends LazyBase{ * */ LazyWidgets textArea(WidgetInitializer