diff options
author | Manolo Carrasco <manolo@apache.org> | 2012-03-17 20:16:46 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2012-03-17 20:16:46 +0000 |
commit | 9884b3fdfacd81a9da581e24883be9c455dbc381 (patch) | |
tree | 0af64339fb93a992c739ffe5fcd35702f28ae049 /jsquery | |
parent | 41bd496f5a56a4d88f4acd6a95aad3129f049e03 (diff) | |
download | gwtquery-9884b3fdfacd81a9da581e24883be9c455dbc381.tar.gz gwtquery-9884b3fdfacd81a9da581e24883be9c455dbc381.zip |
exporting $.isArray and using it in example plugin because object.constructor == Array does not work when objects are in differen windows (gwt iframe)
Diffstat (limited to 'jsquery')
7 files changed, 107 insertions, 81 deletions
diff --git a/jsquery/src/main/java/gwtquery/jsquery/JsQuery.gwt.xml b/jsquery/src/main/java/gwtquery/jsquery/JsQuery.gwt.xml index ace3971e..77569711 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/JsQuery.gwt.xml +++ b/jsquery/src/main/java/gwtquery/jsquery/JsQuery.gwt.xml @@ -5,8 +5,5 @@ <set-property name="export" value="yes" /> <entry-point class="gwtquery.jsquery.client.JsQuery" /> - - <!-- cross-site --> - <add-linker name="xsiframe"/> </module> diff --git a/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml b/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml index 80ce12a6..22df149e 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml +++ b/jsquery/src/main/java/gwtquery/jsquery/JsQueryXs.gwt.xml @@ -2,8 +2,8 @@ <inherits name='gwtquery.jsquery.JsQuery' /> <!-- - Hack to put code into the jsquery.nocache.js so as $ is available - to use the $().ready method which is widely used in jquery pages. + Hack to put code into the jsquery.nocache.js so as $ is available early + and we can handle the $().ready method which is widely used in jquery pages. Otherwise $ wont be available until the async loading of the gwt permutation which happens after the page was ready. --> @@ -28,5 +28,8 @@ <!-- Minimize JS --> <set-property name="compiler.stackMode" value="strip"/> + <!-- cross-site --> + <add-linker name="xsiframe"/> + </module> diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java b/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java index 465b9ff2..3c73eef9 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/JsMenu.java @@ -113,7 +113,7 @@ public abstract class JsMenu { this.openTimer = null; this.init(); - if ( items && items.constructor == Array ) + if ( items && $.isArray(items) ) this.addItems(items); } }); @@ -129,19 +129,14 @@ public abstract class JsMenu { while ( t.parentNode && t.parentNode != $rootDiv[0] ) 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: why do we need a timeout + setTimeout($.Menu.closeAll, 100); + // FIXME: JsQuery each doesn't work with arrays - if ( !$(visibleMenus).filter(function(){ return this.$eDIV[0] == t }).length ) - { - $.Menu.closeAll(); - } + // if ( !$(visibleMenus).filter(function(){ return this.$eDIV[0] == t }).length ) + // { + // $.Menu.closeAll(); + // } return true; }, checkKey : function(e) @@ -638,7 +633,7 @@ public abstract class JsMenu { var i, isStr, src = this.src, self = this; - + this.$eLI = $(menuItemElement.cloneNode(1)); if ( this.addClass ) this.$eLI[0].setAttribute('class', this.addClass); @@ -902,7 +897,7 @@ public abstract class JsMenu { { return this.each(function() { - if ( items && items.constructor == Array ) + if ( items && $.isArray(items) ) new $.Menu(this, items, options); else { diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java b/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java index 0a929a87..d18a5d8c 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/JsQuery.java @@ -28,10 +28,20 @@ public class JsQuery implements EntryPoint { private native static void testJs() /*-{ var l = @gwtquery.jsquery.client.utils.JsQueryUtils::log(Ljava/lang/Object;); - l($.each); - $.each(["a","b"], function(a, b){ - l("kk " + " " + a + " " + b); - }); + + 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); + + }-*/; } diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/OverlayGQuery.java b/jsquery/src/main/java/gwtquery/jsquery/client/OverlayGQuery.java index 070c0cee..753489d8 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/OverlayGQuery.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/OverlayGQuery.java @@ -23,6 +23,7 @@ import com.google.gwt.query.client.GQuery; 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.JsUtils; import com.google.gwt.query.client.plugins.Effects; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation; import com.google.gwt.user.client.Event; @@ -38,7 +39,7 @@ import com.google.gwt.user.client.Event; * override some methods in order to deal with complex cases. * */ -@ExportPackage("jsQuery") +@ExportPackage("JsQuery") @Export(value="fn", all=false) public class OverlayGQuery implements ExportOverlay<GQuery> { @@ -55,7 +56,7 @@ public class OverlayGQuery implements ExportOverlay<GQuery> { $wnd.JsQuery && $wnd.JsQuery.onLoad && $wnd.JsQuery.onLoad(); }-*/; - @ExportPackage("jsQuery") + @ExportPackage("JsQuery") @Export("jFunction") @ExportClosure() protected interface OverlayFunction extends ExportOverlay<Function> { @@ -64,7 +65,7 @@ public class OverlayGQuery implements ExportOverlay<GQuery> { public Object f(Element e, int i); } - @ExportPackage("jsQuery") + @ExportPackage("JsQuery") @Export("jPredicate") @ExportClosure() protected interface OverlayPredicate extends ExportOverlay<Predicate> { @@ -116,6 +117,11 @@ public class OverlayGQuery implements ExportOverlay<GQuery> { return JsQueryUtils.inArray(o, arr); } + @ExportStaticMethod("$wnd.$.isArray") + public static boolean isArray(JavaScriptObject o) { + return JsUtils.isArray(o); + } + @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 9bcf60cd..a9ac0d20 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/jsmenu.diff +++ b/jsquery/src/main/java/gwtquery/jsquery/client/jsmenu.diff @@ -1,55 +1,69 @@ ---- jquery.menu.js 2012-03-15 10:34:24.000000000 +0100 -+++ JsMenu.java 2012-03-15 13:19:42.000000000 +0100 -@@ -134,6 +130,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 +243,7 @@ - $.extend(defaults, d);
- },
- prototype : {
-- /**
-- * create / initialize new menu
-- */
+--- query.menu.js 2012-03-17 21:13:29.000000000 +0100 ++++ JsMenu.java 2012-03-17 21:04:09.000000000 +0100 +@@ -114,7 +113,7 @@ + this.openTimer = null; + + this.init(); +- if ( items && items.constructor == Array ) ++ if ( items && $.isArray(items) ) + this.addItems(items); + } + }); +@@ -132,11 +129,15 @@ + while ( t.parentNode && t.parentNode != $rootDiv[0] ) + t = t.parentNode; + +- //is the found node one of the visible menu elements? +- if ( !$(visibleMenus).filter(function(){ return this.$eDIV[0] == t }).length ) +- { +- $.Menu.closeAll(); +- } ++ // FIXME: why do we need a timeout ++ setTimeout($.Menu.closeAll, 100); + - init : function()
- {
- var self = this;
-@@ -397,7 +399,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)
-- if ( $.browser.msie )
++ // FIXME: JsQuery each doesn't work with arrays ++ // if ( !$(visibleMenus).filter(function(){ return this.$eDIV[0] == t }).length ) ++ // { ++ // $.Menu.closeAll(); ++ // } ++ return true; + }, + checkKey : function(e) + { +@@ -395,7 +394,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) +- if ( $.browser.msie ) + if ( 0) //$.browser.msie ) - this.$eUL.css('width', parseInt($.browser.version) == 6 ? this.$eDIV.width() - 7 : this.$eUL.width());
-
- if ( this.settings.onOpen )
-@@ -439,7 +443,7 @@ - }
-
- //y-pos
-- if ( $.fn.scrollTop )
+ this.$eUL.css('width', parseInt($.browser.version) == 6 ? this.$eDIV.width() - 7 : this.$eUL.width()); + + if ( this.settings.onOpen ) +@@ -437,7 +438,7 @@ + } + + //y-pos +- if ( $.fn.scrollTop ) + if ($().scrollTop ) - {
- wst = $(window).scrollTop();
- if ( wh < height ) //menu is bigger than the window
-@@ -478,7 +482,7 @@ - }
- }
- //x-pos
-- if ( $.fn.scrollLeft )
+ { + wst = $(window).scrollTop(); + if ( wh < height ) //menu is bigger than the window +@@ -476,7 +477,7 @@ + } + } + //x-pos +- if ( $.fn.scrollLeft ) + if ($().scrollLeft ) - {
- wsl = $(window).scrollLeft();
- if ( ww + wsl < posX + width )
+ { + wsl = $(window).scrollLeft(); + if ( ww + wsl < posX + width ) +@@ -898,7 +897,7 @@ + { + return this.each(function() + { +- if ( items && items.constructor == Array ) ++ if ( items && $.isArray(items) ) + new $.Menu(this, items, options); + else + { + diff --git a/jsquery/src/main/java/gwtquery/jsquery/client/utils/JsQueryUtils.java b/jsquery/src/main/java/gwtquery/jsquery/client/utils/JsQueryUtils.java index 66550a1c..de01bab3 100644 --- a/jsquery/src/main/java/gwtquery/jsquery/client/utils/JsQueryUtils.java +++ b/jsquery/src/main/java/gwtquery/jsquery/client/utils/JsQueryUtils.java @@ -64,7 +64,7 @@ public abstract class JsQueryUtils { public static int inArray(Object object, Object array) { if (array instanceof List) { - return ((List)array).indexOf(object); + return ((List<?>)array).indexOf(object); } else if (object instanceof JavaScriptObject && JsUtils.isElement((JavaScriptObject) object)) { return dollar(array).index((Element) object); @@ -101,13 +101,14 @@ public abstract class JsQueryUtils { } private static native JavaScriptObject getDefaultPrototype() /*-{ - return $wnd.jsQuery && $wnd.jsQuery.fn ? $wnd.jsQuery.fn.prototype + return $wnd.JsQuery && $wnd.JsQuery.fn + ? $wnd.JsQuery.fn.prototype : null; }-*/; private static native JavaScriptObject extendImpl(boolean deep, JavaScriptObject ctx, Object s) /*-{ - var d = ctx ? ctx : $wnd.jsQuery.fn.prototype || {}; + var d = ctx ? ctx : $wnd.JsQuery.fn.prototype || {}; for (k in s) { d[k] = s[k]; if (!ctx) |