diff options
author | Manolo Carrasco <manolo@apache.org> | 2012-03-14 13:27:22 +0000 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2012-03-14 13:27:22 +0000 |
commit | 7822e013f689e39acbe6f37f05f3ced842af209d (patch) | |
tree | 82457a87883ab169f709a945179e5154225b8f3c /jsquery/src | |
parent | 557d0059c4bb2f03a53cc5eec5746be6b30b63c3 (diff) | |
download | gwtquery-7822e013f689e39acbe6f37f05f3ced842af209d.tar.gz gwtquery-7822e013f689e39acbe6f37f05f3ced842af209d.zip |
Fixes in js-menu plugin and some code clean up
Diffstat (limited to 'jsquery/src')
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 @@ <module rename-to='dev'> <inherits name='com.google.gwt.query.Query' /> + <inherits name='org.timepedia.exporter.Exporter' /> - <inherits name='com.google.gwt.junit.JUnit' /> - <entry-point class="gwtquery.jsquery.client.JsQuery" /> <set-property name="export" value="yes" /> + + <entry-point class="gwtquery.jsquery.client.JsQuery" /> + + <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 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 @@ <module rename-to='jsquery'> <inherits name='gwtquery.jsquery.JsQuery' /> - <!-- Hack to put code in jsquery.nocache.js --> + <!-- + 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. + Otherwise $ wont be available until the async loading of the gwt permutation + which happens after the page was ready. + --> <define-property name="onload" values="default, foo"/> <property-provider name="onload"> <![CDATA[ @@ -22,7 +27,9 @@ </property-provider> <!-- Cross Site --> - <add-linker name="xs"/> + <add-linker name="xslinker"/> + + <!-- Minimize JS --> <set-property name="compiler.stackMode" value="strip"/> </module> 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") @@ -50,15 +54,6 @@ public class JQ implements ExportOverlay<GQuery> { } @ExportPackage("jsQuery") - @Export("jOffset") - public static class JOffset implements ExportOverlay<Offset>{ - public int left; - public int top; - public JOffset(int left, int top) { - } - } - - @ExportPackage("jsQuery") @Export("jEasing") @ExportClosure() public interface JEasing extends ExportOverlay<Easing> { @@ -85,17 +80,26 @@ public class JQ implements ExportOverlay<GQuery> { @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).<Node>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<GQuery> { } 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<Element> 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<GQuery> { @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<Element> 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 @@ <head> <title>jQuery menu plugin demo page</title> <link rel="stylesheet" type="text/css" href="style.css" /> -<!-- <script type="text/javascript" src="http://p.sohei.org/wp-content/jquery/jquery-1.2.2.pack.js"></script> -->
-<!-- <script type="text/javascript" src="jquery.dimensions.min.js"></script> --> -<!-- <script type="text/javascript" src="../jquery.menu.js"></script> --> <script src="dev.nocache.js" ></script> -<!-- -<script type="text/javascript" src="http://p.sohei.org/wp-content/plugins/syntaxhighlighter-plus/files/shCore.js"></script>
-<script type="text/javascript" src="http://p.sohei.org/wp-content/plugins/syntaxhighlighter-plus/files/shBrushXml.js"></script>
-<script type="text/javascript" src="http://p.sohei.org/wp-content/plugins/syntaxhighlighter-plus/files/shBrushJScript.js"></script>
---> <script type="text/javascript"> -<!-- + +// JsQuery will run this function after it is asynchronously loaded onJsQueryLoad = function(){ -$(document).ready(function() -{ var options = {minWidth: 120, arrowSrc: 'arrow_right.gif', copyClassAttr: true, onClick: function(e, menuItem){ alert('you clicked item "' + $(this).text() + '"'); }}; @@ -48,12 +39,14 @@ $(document).ready(function() ], options); //adding the submenu to the main menu menu.addItem(itemWithSubmenu); +} - //highlight stuff.. - dp.SyntaxHighlighter.ClipboardSwf = 'http://p.sohei.org/wp-content/plugins/syntaxhighlighter-plus/files/clipboard.swf';
- dp.SyntaxHighlighter.HighlightAll('code'); -}); +// If jsQuery or jQuery was already loaded we use the normal way +if (window.$) { + $(document).ready(onJsQueryLoad); + onJsQueryLoad = null; } + --> </script> </head> |