From f0dcf5ef3d7dc73a232edc45fd0a9f1fe03993ce Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Wed, 19 Oct 2011 17:01:51 +0000 Subject: [PATCH] Strip js, first try to implement extend --- jsquery/pom.xml | 2 + .../java/gwtquery/jsquery/JsQueryXs.gwt.xml | 2 + .../main/java/gwtquery/jsquery/client/JQ.java | 57 +++++++++++++++---- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/jsquery/pom.xml b/jsquery/pom.xml index 453e2df6..36e4e912 100644 --- a/jsquery/pom.xml +++ b/jsquery/pom.xml @@ -61,6 +61,8 @@ 9 ${gwtversion} true + + true gwtquery.jsquery.JsQueryXs diff --git a/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml b/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml index 2e847db4..27d5c680 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml +++ b/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml @@ -15,6 +15,7 @@ $wnd.JsQuery.onLoadArray.push(f); } }; + $wnd._$_ = $wnd.$; $wnd.$ = function() {return $wnd.JsQuery;} return 'default'; ]]> @@ -22,5 +23,6 @@ + diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/JQ.java b/jsquery/src/main/java/gwtquery/jsquery/client/JQ.java index b7a3b0b1..c580b70a 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/JQ.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/JQ.java @@ -22,11 +22,11 @@ import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; import com.google.gwt.user.client.Event; -@ExportPackage("") -@Export(value="jQuery", all=false) +@ExportPackage("jsQuery") +@Export(value="fn", all=false) public class JQ implements ExportOverlay { - @ExportPackage("") + @ExportPackage("jsQuery") @Export("jFunction") @ExportClosure() public interface JFunction extends ExportOverlay { @@ -37,14 +37,14 @@ public class JQ implements ExportOverlay { public Object f(Element e, int i); } - @ExportPackage("") + @ExportPackage("jsQuery") @Export("jPredicate") @ExportClosure() public interface JPredicate extends ExportOverlay { public boolean f(Element e, int i); } - @ExportPackage("") + @ExportPackage("jsQuery") @Export("jOffset") public static class JOffset implements ExportOverlay{ public int left; @@ -53,22 +53,24 @@ public class JQ implements ExportOverlay { } } - @ExportPackage("") + @ExportPackage("jsQuery") @Export("jEasing") @ExportClosure() public interface JEasing extends ExportOverlay { public double interpolate(double progress); } + @ExportPackage("") + @Export("jsQuery") // Used to export $ method public static class Dollar implements Exportable { - public native static String dumpObject(JavaScriptObject o) /*-{ + native static String dumpObject(JavaScriptObject o) /*-{ var s = "" ; for (k in o) s += " " + k; return s; }-*/; - public native static boolean isEvent(JavaScriptObject o) /*-{ + native static boolean isEvent(JavaScriptObject o) /*-{ return o.preventDefault ? true : false; }-*/; - public native static boolean isElement(JavaScriptObject o) /*-{ + native static boolean isElement(JavaScriptObject o) /*-{ return o.getElementById ? true : false; }-*/; @Export("$wnd.$") @@ -82,6 +84,39 @@ public class JQ implements ExportOverlay { } return GQuery.$(); } + @Export("$wnd.$") + public static GQuery StaticDollar(String s, Element ctx) { + return GQuery.$(s, ctx); + } + // FIXME: does not work + @Export("$wnd.$.extend") + public static JavaScriptObject extend(JavaScriptObject...objs) { + int l = objs.length; + boolean me = l < 2; + JavaScriptObject ctx = me ? getDefaultPrototype() : objs[0]; + for (int i = me ? 0 : 1; i < l; i++) { + extend(ctx, objs[i]); + } + return ctx; + } + private static native JavaScriptObject getDefaultPrototype() /*-{ + return $wnd.jsQuery && $wnd.jsQuery.fn ? $wnd.jsQuery.fn.prototype : null; + }-*/; + private static native void extend(JavaScriptObject d, JavaScriptObject s) /*-{ + for (k in s) d[k] = s[k]; + }-*/; + /*-{ + try{ + var me = objs.length < 2; + var t = me ? $wnd.jsQuery.fn : objs[0]; + for (i = me ? 0 : 1; i < objs.length; i++) { + for (k in objs[i]) { + t[k] = objs[i][k]; + } + } + return t; + } catch(e) { alert(e); return({});} + }-*/; } // We have to stub all the method we want to export here. @@ -110,7 +145,7 @@ public class JQ implements ExportOverlay { public GQuery appendTo(String html) {return null;} public T as(Class plugin) {return null;} // public GQuery attr(Properties properties) {return null;} - public String attr(String name) {return null;} +// public String attr(String name) {return null;} // public GQuery attr(String key, Function closure) {return null;} public GQuery attr(String key, Object value) {return null;} public GQuery before(GQuery query) {return null;} @@ -328,4 +363,4 @@ public class JQ implements ExportOverlay { public GQuery wrapInner(Element elem) {return null;} public GQuery wrapInner(GQuery query) {return null;} public GQuery wrapInner(String html) {return null;} -} \ No newline at end of file +} -- 2.39.5