From 334d9f88bc8e625e7eab6c0ce8450c7aa7066126 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Thu, 15 Mar 2012 09:39:53 +0000 Subject: [PATCH] JsQuery: Fix inArray static method --- .../java/gwtquery/jsquery/client/JsMenu.java | 11 +++-- .../java/gwtquery/jsquery/client/JsQuery.java | 13 ++--- .../jsquery/client/OverlayGQuery.java | 9 +++- .../java/gwtquery/jsquery/client/jsmenu.diff | 49 ++++++++----------- .../gwtquery/jsquery/client/utils/JsQAux.java | 24 ++++----- 5 files changed, 54 insertions(+), 52 deletions(-) diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java b/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java index 9c1cf373..7051a711 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java @@ -3,13 +3,13 @@ package gwtquery.jsquery.client; public abstract class JsMenu { public static native void loadPlugin() /*-{ - -(function($) -{ var l = @gwtquery.jsquery.client.utils.JsQAux::log(Ljava/lang/Object;); - var window = $wnd; var document = $doc; + var jQuery = $wnd.$; + +(function($) +{ var menus = [], //list of all menus visibleMenus = [], //list of all visible menus activeMenu = activeItem = null, @@ -135,6 +135,7 @@ public abstract class JsMenu { { $.Menu.closeAll(); } + return true; }, checkKey : function(e) { @@ -937,7 +938,7 @@ public abstract class JsMenu { return r; }; -})($wnd.$); +})(jQuery); }-*/; } diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java b/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java index bf9559ee..2180b5bb 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java @@ -20,23 +20,24 @@ public class JsQuery implements EntryPoint { }); OverlayGQuery.export(); - + JsMenu.loadPlugin(); onJsQueryLoad(); - - testJs(); +// testJs(); } private native static void testJs() /*-{ var l = @gwtquery.jsquery.client.utils.JsQAux::log(Ljava/lang/Object;); - $ = $wnd.$; l($.each); $.each(["a","b"], function(a, b){ l("kk " + " " + a + " " + b); - } - ); + }); }-*/; private native static void onJsQueryLoad() /*-{ + $ = $wnd.$; + window = $wnd; + document = $doc; + $wnd.onJsQueryLoad && $wnd.onJsQueryLoad(); $wnd.JsQuery && $wnd.JsQuery.onLoad && $wnd.JsQuery.onLoad(); }-*/; diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/OverlayGQuery.java b/jsquery/src/main/java/gwtquery/jsquery/client/OverlayGQuery.java index 20b7139b..8515883c 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/OverlayGQuery.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/OverlayGQuery.java @@ -96,12 +96,17 @@ public class OverlayGQuery implements ExportOverlay { public static JavaScriptObject extend(Object...objs) { return JsQAux.extend(objs); } - + @ExportStaticMethod("$wnd.$.each") - public static Object[] each(Object[] objs, Function f) { + public static JavaScriptObject[] each(JavaScriptObject[] objs, Function f) { return JsQAux.each(objs, f); } + @ExportStaticMethod("$wnd.$.inArray") + public static int inArray(Object o, Object arr) { + return JsQAux.inArray(o, arr); + } + @ExportInstanceMethod public static GQuery ready(GQuery g, Function f) { f.fe(); diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/jsmenu.diff b/jsquery/src/main/java/gwtquery/jsquery/client/jsmenu.diff index 6aa3328a..f5ce17a2 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/jsmenu.diff +++ b/jsquery/src/main/java/gwtquery/jsquery/client/jsmenu.diff @@ -1,19 +1,21 @@ ---- mplugins/jquery.menu.js 2012-03-13 00:35:46.000000000 +0100 -+++ jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java 2012-03-13 00:40:53.000000000 +0100 -@@ -1,5 +1,12 @@ -+package gwtquery.jsquery.client; -+ -+public abstract class JsMenu { -+ public static native void loadPlugin() /*-{ -+ - (function($) - { -+ var window = $wnd; -+ var document = $doc; - var menus = [], //list of all menus - visibleMenus = [], //list of all visible menus - activeMenu = activeItem = null, -@@ -221,9 +225,7 @@ +--- jquery.menu.js 2012-03-15 10:34:24.000000000 +0100 ++++ JsMenu.jsni 2012-03-15 10:36:20.000000000 +0100 +@@ -134,6 +113,14 @@ + 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(); +@@ -239,9 +226,7 @@ $.extend(defaults, d); }, prototype : { @@ -24,7 +26,7 @@ init : function() { var self = this; -@@ -379,7 +381,7 @@ +@@ -397,7 +382,7 @@ this.$eDIV.css({display:'none', visibility: ''}).show(); //IEs default width: auto is bad! ie6 and ie7 have are producing different errors.. (7 = 5px shadowbox + 2px border) @@ -33,7 +35,7 @@ this.$eUL.css('width', parseInt($.browser.version) == 6 ? this.$eDIV.width() - 7 : this.$eUL.width()); if ( this.settings.onOpen ) -@@ -422,7 +424,7 @@ +@@ -439,7 +426,7 @@ } //y-pos @@ -42,7 +44,7 @@ { wst = $(window).scrollTop(); if ( wh < height ) //menu is bigger than the window -@@ -461,7 +463,7 @@ +@@ -478,7 +465,7 @@ } } //x-pos @@ -51,12 +53,3 @@ { wsl = $(window).scrollLeft(); if ( ww + wsl < posX + width ) -@@ -925,4 +926,7 @@ - return r; - }; - --})(jQuery); -+})($wnd.$); -+ -+ }-*/; -+} diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/utils/JsQAux.java b/jsquery/src/main/java/gwtquery/jsquery/client/utils/JsQAux.java index 72cc100c..a4748647 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/utils/JsQAux.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/utils/JsQAux.java @@ -1,6 +1,7 @@ package gwtquery.jsquery.client.utils; import java.util.ArrayList; +import java.util.List; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.dom.client.Element; @@ -57,15 +58,16 @@ public abstract class JsQAux { public static void ready(Function f) { f.f(); } - - public static int inArray(Object o, Object a) { - if (o instanceof JavaScriptObject) { - JavaScriptObject jso = (JavaScriptObject) o; - if (JsUtils.isElement(jso)) { - return dollar(a).index((Element) o); - } else if (JsUtils.isArray(jso)) { - return ((JsCache) a).indexOf(o); - } + + public static int inArray(Object object, Object array) { + if (array instanceof List) { + return ((List)array).indexOf(object); + } else if (object instanceof JavaScriptObject + && JsUtils.isElement((JavaScriptObject) object)) { + return dollar(array).index((Element) object); + } else if (array instanceof JavaScriptObject + && JsUtils.isArray((JavaScriptObject) array)) { + return ((JsCache) array).indexOf(object); } return -1; } @@ -111,7 +113,7 @@ public abstract class JsQAux { return d; }-*/; - public static Object[] each(Object[] objs, Function f) { + public static JavaScriptObject[] each(JavaScriptObject[] objs, Function f) { ArrayList ret = new ArrayList(); for (Object o : objs) { f.setDataObject(o); @@ -119,7 +121,7 @@ public abstract class JsQAux { ret.add(o); } } - return ret.toArray(new Object[0]); + return ret.toArray(new JavaScriptObject[0]); } public static void log(Object l) { -- 2.39.5