From 7822e013f689e39acbe6f37f05f3ced842af209d Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Wed, 14 Mar 2012 13:27:22 +0000 Subject: [PATCH] Fixes in js-menu plugin and some code clean up --- .../java/gwtquery/jsquery/JsQuery.gwt.xml | 7 +- .../java/gwtquery/jsquery/JsQueryXs.gwt.xml | 11 ++- .../main/java/gwtquery/jsquery/client/JQ.java | 62 +++++++++------ .../java/gwtquery/jsquery/client/JsMenu.java | 17 ++++- .../java/gwtquery/jsquery/client/JsQuery.java | 75 ++++--------------- .../java/gwtquery/jsquery/public/demo.html | 23 ++---- 6 files changed, 90 insertions(+), 105 deletions(-) diff --git a/jsquery/src/main/java/gwtquery/jsquery/JsQuery.gwt.xml b/jsquery/src/main/java/gwtquery/jsquery/JsQuery.gwt.xml index 6ccb43e2..2dc6ab94 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/JsQuery.gwt.xml +++ b/jsquery/src/main/java/gwtquery/jsquery/JsQuery.gwt.xml @@ -1,8 +1,11 @@ + - - + + + + diff --git a/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml b/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml index 27d5c680..5cb9179f 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml +++ b/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml @@ -1,7 +1,12 @@ - + - + + + diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/JQ.java b/jsquery/src/main/java/gwtquery/jsquery/client/JQ.java index f008a7f6..f34b223e 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/JQ.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/JQ.java @@ -1,6 +1,9 @@ package gwtquery.jsquery.client; +import static com.google.gwt.user.client.Window.alert; + import org.timepedia.exporter.client.Export; +import org.timepedia.exporter.client.ExportAfterCreateMethod; import org.timepedia.exporter.client.ExportClosure; import org.timepedia.exporter.client.ExportInstanceMethod; import org.timepedia.exporter.client.ExportJsInitMethod; @@ -10,6 +13,7 @@ import org.timepedia.exporter.client.Exportable; import org.timepedia.exporter.client.ExporterUtil; import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.core.client.JsArray; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; @@ -19,12 +23,12 @@ import com.google.gwt.query.client.GQuery.Offset; import com.google.gwt.query.client.Predicate; import com.google.gwt.query.client.Properties; import com.google.gwt.query.client.js.JsCache; +import com.google.gwt.query.client.js.JsNodeArray; import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.query.client.plugins.Effects; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; import com.google.gwt.user.client.Event; -import static com.google.gwt.user.client.Window.*; @ExportPackage("jsQuery") @@ -49,15 +53,6 @@ public class JQ implements ExportOverlay { public boolean f(Element e, int i); } - @ExportPackage("jsQuery") - @Export("jOffset") - public static class JOffset implements ExportOverlay{ - public int left; - public int top; - public JOffset(int left, int top) { - } - } - @ExportPackage("jsQuery") @Export("jEasing") @ExportClosure() @@ -85,17 +80,26 @@ public class JQ implements ExportOverlay { @Export("$wnd.$") public static GQuery staticDollar(Object o) { if (o instanceof String) { -// System.out.println("R A"); return GQuery.$((String)o); } else if (isFunction(o)) { -// System.out.println("R B"); runFunction(o); } else if (o instanceof JavaScriptObject) { - GQuery r = GQuery.$((JavaScriptObject)o); -// System.out.println("R C " + r); + JavaScriptObject jso = (JavaScriptObject)o; + GQuery r = GQuery.$(jso); + if (JsUtils.isArray(jso)) { + JsCache c = jso.cast(); + JsNodeArray elms = JsNodeArray.create(); + for (int i = 0 ; i < c.length(); i++) { + elms.addNode(c.getJavaScriptObject(i).cast()); + } + r = GQuery.$(elms); +// System.out.println(c.length() + " " + elms.getLength() + " " + r.length()); + } + return r; + } else { + System.out.println("Bad!!!! " + o); } -// System.out.println("R D"); return GQuery.$(); } @@ -157,10 +161,18 @@ public class JQ implements ExportOverlay { } return d; }-*/; + + @ExportAfterCreateMethod + public static native void afterCreate() /*-{ + }-*/; } // We have to stub all the method we want to export here. private JQ(){} + + @ExportJsInitMethod + public NodeList get() {return null;} + public String toString() {return null;} public GQuery add(GQuery previousObject) {return null;} public GQuery add(String selector) {return null;} @@ -172,7 +184,7 @@ public class JQ implements ExportOverlay { @ExportInstanceMethod public static GQuery animate(GQuery g, Object stringOrProperties, int duration, String easing, Function... funcs) { - return g.animate(stringOrProperties, duration, "linear".equalsIgnoreCase(easing)? PropertiesAnimation.Easing.SWING : PropertiesAnimation.Easing.SWING, funcs); + return g.animate(stringOrProperties, duration, "linear".equalsIgnoreCase(easing)? PropertiesAnimation.Easing.LINEAR : PropertiesAnimation.Easing.SWING, funcs); } // public GQuery animate(Object stringOrProperties, int duration, Easing easing, Function... funcs) {return null;} public GQuery animate(Object stringOrProperties, Function... funcs) {return null;} @@ -265,8 +277,6 @@ public int size() {return 0;} public GQuery find(String... filters) {return null;} public GQuery first() {return null;} public GQuery focus(Function... f) {return null;} - @ExportJsInitMethod - public NodeList get() {return null;} public Element get(int i) {return null;} public Node getContext() {return null;} public GQuery getPreviousObject() {return null;} @@ -409,8 +419,8 @@ public int size() {return 0;} // public GQuery trigger(int eventbits, int... keys) {return null;} // public GQuery unbind(int eventbits) {return null;} @ExportInstanceMethod - public static GQuery unbind(GQuery g, String s, Object o) { - return g; + public static GQuery unbind(GQuery g, String s, Function o) { + return g.unbind(s); } public GQuery undelegate() {return null;} public GQuery undelegate(String selector) {return null;} @@ -435,9 +445,15 @@ public int size() {return 0;} public GQuery wrapInner(String html) {return null;} @ExportInstanceMethod - public static GQuery ready(Function f) { - alert("ready ...."); - return null; + public static GQuery ready(GQuery g, Function f) { + f.fe(); + return g; + } + + @ExportInstanceMethod + public static String imprime(GQuery g, Function f) { + System.out.println("Imprime " + g.size() + " " + g.toString(true)); + return g.toString(); } } diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java b/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java index 1479d9a2..6c30de6a 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java @@ -1,10 +1,17 @@ package gwtquery.jsquery.client; public abstract class JsMenu { + + static void log(Object l) { + System.out.println(l); + } + public static native void loadPlugin() /*-{ (function($) { + var l = @gwtquery.jsquery.client.JsMenu::log(Ljava/lang/Object;); + var window = $wnd; var document = $doc; var menus = [], //list of all menus @@ -111,7 +118,6 @@ public abstract class JsMenu { checkMouse : function(e) { var t = e.target; - //the user clicked on the target of the currenty open menu if ( visibleMenus.length && t == visibleMenus[0].target ) return; @@ -121,6 +127,14 @@ public abstract class JsMenu { t = t.parentNode; //is the found node one of the visible menu elements? + for (k in visibleMenus) { + if (visibleMenus[k].$eDIV[0] == t) { + // FIXME: why do we need a timeout + setTimeout($.Menu.closeAll, 100); + break; + } + } + // FIXME: JsQuery each doesn't work with arrays if ( !$(visibleMenus).filter(function(){ return this.$eDIV[0] == t }).length ) { $.Menu.closeAll(); @@ -387,6 +401,7 @@ public abstract class JsMenu { if ( this.settings.onOpen ) this.settings.onOpen.call(this); } + if ( visibleMenus.length == 0 ) $(document).bind('mousedown', $.Menu.checkMouse).bind('keydown', $.Menu.checkKey); diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java b/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java index 4f35f964..98b9cca3 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java @@ -3,84 +3,35 @@ package gwtquery.jsquery.client; import gwtquery.jsquery.client.JQ.Dollar; import gwtquery.jsquery.client.JQ.JEasing; import gwtquery.jsquery.client.JQ.JFunction; -import gwtquery.jsquery.client.JQ.JOffset; import gwtquery.jsquery.client.JQ.JPredicate; +import java.util.logging.Logger; + import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.Scheduler; -import com.google.gwt.user.client.Timer; -import static com.google.gwt.user.client.Window.*; public class JsQuery implements EntryPoint { public void onModuleLoad() { -// GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() { -// public void onUncaughtException(Throwable e) { -// String r = ""; -// for (StackTraceElement s :e.getStackTrace()) { -// r += s + "\n"; -// } -// Window.alert(r); -// } -// }); + GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() { + Logger l = Logger.getLogger("jsQuery"); + public void onUncaughtException(Throwable e) { + String r = ""; + for (StackTraceElement s :e.getStackTrace()) { + r += s + "\n"; + } + l.info(r); + } + }); GWT.create(JFunction.class); GWT.create(JPredicate.class); - GWT.create(JOffset.class); GWT.create(JEasing.class); GWT.create(JQ.class); -// new JQExporterImpl(); GWT.create(Dollar.class); -// new DollarExporterImpl(); -// System.out.println(testExtend("kaka")); JsMenu.loadPlugin(); - myJs(); -// onJsQueryLoad(); + onJsQueryLoad(); } - - private native static void myJs() /*-{ - try { - $ = $wnd.$; - var options = {minWidth: 120, arrowSrc: 'arrow_right.gif', copyClassAttr: true, onClick: function(e, menuItem){ - alert('you clicked item "' + $(this).text() + '"'); - }}; - $('#menuone').menu(options); - var items = [ {src: 'test', url:'http://www.jquery.com'}, - {src: ''}, // separator - {src: 'test2', subMenu: [ {src: 'sub 1'}, - {src: 'sub 2', url: 'http://p.sohei.org', target: '_blank'}, - {src: 'sub 3'}]}]; - $('#menutwo').menu(options, items); - $('#menuthree').menu(options); - $('#menufive>img').menu(options, '#menufivelist'); - - // creating a menu without items - var menu = new $.Menu('#menufour', null, options); - // adding items to the menu - menu.addItems([ - new $.MenuItem({src: 'test', url:'http://www.jquery.com'}, options), - new $.MenuItem({src: ''}) // separator - ]); - var itemWithSubmenu = new $.MenuItem({src: 'test2'}, options); - // creating a menu with items (as child of itemWithSubmenu) - new $.Menu(itemWithSubmenu, [ - new $.MenuItem({src: 'sub 1'}, options), - new $.MenuItem({src: 'sub 2', url: 'http://p.sohei.org', target: '_blank'}, options), - new $.MenuItem({src: 'sub 3'}, options) - ], options); - // adding the submenu to the main menu - menu.addItem(itemWithSubmenu); - - - } catch(e){alert(e);} - }-*/; - - private native static String testExtend(String s) /*-{ - $wnd.$.extend({hola: function(){return s;}}); - return $wnd.$('*').hola(); - }-*/; - private native static void onJsQueryLoad() /*-{ $wnd.onJsQueryLoad && $wnd.onJsQueryLoad(); diff --git a/jsquery/src/main/java/gwtquery/jsquery/public/demo.html b/jsquery/src/main/java/gwtquery/jsquery/public/demo.html index f5d5efc2..4168afe8 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/public/demo.html +++ b/jsquery/src/main/java/gwtquery/jsquery/public/demo.html @@ -4,20 +4,11 @@ jQuery menu plugin demo page - - - - -- 2.39.5