}
}
+ /**
+ * Assign a function to a property of the window object.
+ */
+ public static void export(String name, Function f) {
+ export(GQuery.window, name, f);
+ }
+
+ /**
+ * Export a function as a property of a javascript object.
+ */
+ public static void export(JavaScriptObject o, String name, Function f) {
+ prop(o, name, (Object)(f != null ? wrapFunction(f) : null));
+ }
+
/**
* Camelize style property names.
* for instance: font-name -> fontName
}
private static native <T> T runJavascriptFunctionImpl(JavaScriptObject o, String meth, JsArrayMixed args) /*-{
- var f = o || window, p = meth.split('.');
+ var f = o || $wnd, p = meth.split('.');
for (var i in p) {
o = f;
f = f[p[i]];
import static com.google.gwt.query.client.GQuery.document;
import static com.google.gwt.query.client.GQuery.window;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import junit.framework.Assert;
+
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.InputElement;
import com.google.gwt.query.client.js.JsUtils;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;
-import junit.framework.Assert;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
/**
* Test class for testing gwtquery-core api.
*/
assertNull(e);
}
+ public void testUtilsJsniExport() {
+ JsUtils.export("foo", new Function() {
+ public Object f(Object... args) {
+ assertEquals("bar", (String)args[0]);
+ assertEquals(3.5, (Double)args[1]);
+ return "OK";
+ }
+ });
+ assertTrue(JsUtils.hasProperty(window, "foo"));
+ assertEquals("OK", JsUtils.jsni("foo", "bar", 3.5));
+ }
+
public void testVal_issue98() {
$(e).html(""
+"<input type='text' id='inputText' name='inputText' value='original' />"