<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>
<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[
</property-provider>
<!-- Cross Site -->
- <add-linker name="xs"/>
+ <add-linker name="xslinker"/>
+
+ <!-- Minimize JS -->
<set-property name="compiler.stackMode" value="strip"/>
</module>
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;
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;
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")
public boolean f(Element e, int i);
}
- @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()
@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.$();
}
}
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;}
@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;}
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;}
// 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;}
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();
}
}
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
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;
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();
if ( this.settings.onOpen )
this.settings.onOpen.call(this);
}
+
if ( visibleMenus.length == 0 )
$(document).bind('mousedown', $.Menu.checkMouse).bind('keydown', $.Menu.checkKey);
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();
<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> -->\r
-<!-- <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>\r
-<script type="text/javascript" src="http://p.sohei.org/wp-content/plugins/syntaxhighlighter-plus/files/shBrushXml.js"></script>\r
-<script type="text/javascript" src="http://p.sohei.org/wp-content/plugins/syntaxhighlighter-plus/files/shBrushJScript.js"></script>\r
--->
<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() + '"');
}};
], 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';\r
- 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>