*/
package com.google.gwt.query.client;
-import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Widget;
/**
* Override this for methods which invoke a cancel action.
*
- * @param e takes a com.google.gwt.user.client.Element.
+ * @param e takes a com.google.gwt.dom.client.Element.
*
*/
- public void cancel(Element e) {
+ public void cancel(com.google.gwt.dom.client.Element e) {
// This has to be the order of calls
- cancel(e.<com.google.gwt.dom.client.Element>cast());
+ cancel(e.<com.google.gwt.user.client.Element>cast());
}
/**
* Override this for methods which invoke a cancel action.
*
- * @param e takes a com.google.gwt.dom.client.Element.
+ * @param e takes a com.google.gwt.user.client.Element.
*
*/
- public void cancel(com.google.gwt.dom.client.Element e) {
+ public void cancel(com.google.gwt.user.client.Element e) {
}
/**
* Override this for GQuery methods which loop over matched elements and
* invoke a callback on each element.
*
- * @param e takes a com.google.gwt.user.client.Element.
+ * @param e takes a com.google.gwt.dom.client.Element.
*
*/
- public Object f(Element e, int i) {
+ public Object f(com.google.gwt.dom.client.Element e, int i) {
// This has to be the order of calls
- return f(e.<com.google.gwt.dom.client.Element>cast(), i);
+ return f(e.<com.google.gwt.user.client.Element>cast(), i);
}
/**
* Override this for GQuery methods which loop over matched elements and
* invoke a callback on each element.
*
- * @param e takes a com.google.gwt.dom.client.Element.
+ * @param e takes a com.google.gwt.user.client.Element.
*
*/
- public Object f(com.google.gwt.dom.client.Element e, int i) {
+ public Object f(com.google.gwt.user.client.Element e, int i) {
Widget w = GQuery.getAssociatedWidget(e);
if (w != null){
f(w, i);
} else {
- f(e);
+ f(e.<com.google.gwt.dom.client.Element>cast());
}
return null;
}
* avoid a runtime exception.
*/
public Object f(Widget w, int i) {
- f(w.getElement());//f(w) will be called later in f(Element)
+ f(w);
return null;
}
* Override this method for bound event handlers.
*/
public boolean f(Event e) {
- f((Element)e.getCurrentEventTarget().cast());
+ f(e.getCurrentEventTarget().<com.google.gwt.dom.client.Element>cast());
return true;
}
* Override this for GQuery methods which take a callback and do not expect a
* return value.
*
- * @param e takes a com.google.gwt.user.client.Element
+ * @param e takes a com.google.gwt.dom.client.Element
*/
- public void f(Element e) {
+ public void f(com.google.gwt.dom.client.Element e) {
// This has to be the order of calls
- f(e.<com.google.gwt.dom.client.Element>cast());
+ f(e.<com.google.gwt.user.client.Element>cast());
}
/**
* Override this for GQuery methods which take a callback and do not expect a
* return value.
*
- * @param e takes a com.google.gwt.dom.client.Element
+ * @param e takes a com.google.gwt.user.client.Element
*/
- public void f(com.google.gwt.dom.client.Element e) {
+ private boolean loop = false;
+ public void f(com.google.gwt.user.client.Element e) {
Widget w = GQuery.getAssociatedWidget(e);
if (w != null){
+ loop = true;
f(w);
- }else{
+ } else {
f();
}
}
* avoid a runtime exception.
*/
public void f(Widget w){
- // Do not call f(e) here to avoid loop
- f();
+ if (loop) {
+ loop = false;
+ f();
+ } else {
+ f(w.getElement().<com.google.gwt.dom.client.Element>cast());
+ }
}
}
import com.google.gwt.dom.client.Style.Display;\r
import com.google.gwt.dom.client.Style.HasCssName;\r
import com.google.gwt.dom.client.TextAreaElement;\r
-import com.google.gwt.event.logical.shared.ResizeEvent;\r
-import com.google.gwt.event.logical.shared.ResizeHandler;\r
import com.google.gwt.query.client.css.CSS;\r
import com.google.gwt.query.client.css.HasCssValue;\r
import com.google.gwt.query.client.css.TakesCssValue;\r
public GQuery attr(String key, Function closure) {\r
for (int i = 0; i < elements.getLength(); i++) {\r
Element e = elements.getItem(i);\r
- e.setAttribute(key, String.valueOf(closure.f(e, i)));\r
+ Object val = closure.f(e.<com.google.gwt.dom.client.Element>cast(), i);\r
+ if (val != null) {\r
+ e.setAttribute(key, String.valueOf(val));\r
+ }\r
}\r
return this;\r
}\r
if (f != null) {\r
for (Function f1 : f) {\r
for (int i = 0; i < elements.getLength(); i++) {\r
- f1.f(elements.getItem(i), i);\r
+ f1.f(elements.getItem(i).<com.google.gwt.dom.client.Element>cast(), i);\r
}\r
}\r
}\r
ArrayList<W> ret = new ArrayList<W>();\r
for (int i = 0; i < elements().length; i++) {\r
@SuppressWarnings("unchecked")\r
- W o = (W)f.f(elements()[i], i);\r
+ W o = (W)f.f(elements()[i].<com.google.gwt.dom.client.Element>cast(), i);\r
if (o != null) {\r
ret.add(o);\r
}\r
$(el).remove();\r
}\r
return this;\r
-\r
}\r
\r
/**\r
public void run() {
dequeue();
}
-
}
private int delay;
Object f = q.peek();
if (f != null) {
if (f instanceof Function) {
- ((Function) f).f(elem);
+ ((Function) f).f(elem.<com.google.gwt.dom.client.Element>cast());
}
}
}
}
if (q.size() == 1 && func != null) {
if (func instanceof Function) {
- ((Function) func).f(elem);
+ ((Function) func).f(elem.<com.google.gwt.dom.client.Element>cast());
}
}
return q;
handlerManager.fireEvent(e);
}
if (callback != null) {
- callback.f(element);
+ callback.f(element.<com.google.gwt.dom.client.Element>cast());
}
}
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
+import com.google.gwt.user.client.ui.Widget;
/**
* Test class for testing gwtquery-core api.
});
assertHtmlEquals("<p>0</p><p>1</p><p>2</p>", $("p", e));
}
-
+
public void testIFrameManipulation() {
$(e).html("<iframe name='miframe' id='miframe' src=\"javascript:''\">");
// FF has to call empty to open and close the document before
assertTrue(w.width() > 0);
assertTrue(w.height() > 0);
}
+
+ public void testFunction() {
+ $(e).html("<div id=fid>0</div>");
+ GQuery g = $("#fid");
+ assertEquals("0", g.text());
+
+ // EACH
+ g.each(new Function() {
+ @Override
+ public void f(com.google.gwt.user.client.Element e) {
+ $(e).text("U");
+ }
+ });
+ assertEquals("U", g.text());
+ g.each(new Function() {
+ @Override
+ public void f(com.google.gwt.dom.client.Element e) {
+ $(e).text("D");
+ }
+ });
+ assertEquals("D", g.text());
+ g.each(new Function() {
+ @Override
+ public Object f(com.google.gwt.user.client.Element e, int idx) {
+ $(e).text("U" + idx);
+ return "";
+ }
+ });
+ assertEquals("U0", g.text());
+ g.each(new Function() {
+ @Override
+ public Object f(com.google.gwt.user.client.Element e, int idx) {
+ $(e).text("D" + idx);
+ return "";
+ }
+ });
+ assertEquals("D0", g.text());
+
+ // EVENTS
+ g.unbind(Event.ONCLICK).click(new Function(){
+ @Override
+ public void f(com.google.gwt.user.client.Element e) {
+ $(e).text("U");
+ }
+ }).click();
+ assertEquals("U", g.text());
+ g.unbind(Event.ONCLICK).click(new Function(){
+ @Override
+ public void f(com.google.gwt.dom.client.Element e) {
+ $(e).text("D");
+ }
+ }).click();
+ assertEquals("D", g.text());
+ g.unbind(Event.ONCLICK).click(new Function(){
+ @Override
+ public boolean f(Event e) {
+ $(e).text("E");
+ return false;
+ }
+ }).click();
+ assertEquals("E", g.text());
+ g.unbind(Event.ONCLICK).bind(Event.ONCLICK, "D", new Function(){
+ @Override
+ public boolean f(Event e, Object o) {
+ $(e).text("E" + o);
+ return false;
+ }
+ }).click();
+ assertEquals("ED", g.text());
+
+ // ELEMENTS AND WIDGETS
+ Label label = new Label("1");
+ RootPanel.get().add(label);
+ g = g.add($(label));
+ assertEquals(2, g.size());
+
+ g.each(new Function() {
+ @Override
+ public void f(com.google.gwt.user.client.Element e) {
+ $(e).text("U");
+ }
+ });
+ assertEquals("UU", g.text());
+ g.each(new Function() {
+ @Override
+ public void f(com.google.gwt.dom.client.Element e) {
+ $(e).text("D");
+ }
+ });
+ assertEquals("DD", g.text());
+
+ g.each(new Function() {
+ @Override
+ public void f(com.google.gwt.user.client.Element e) {
+ $(e).text("U");
+ }
+ @Override
+ public void f(Widget w) {
+ $(w).text("W");
+ }
+ });
+ assertEquals("UW", g.text());
+ g.each(new Function() {
+ @Override
+ public void f(com.google.gwt.dom.client.Element e) {
+ $(e).text("D");
+ }
+ @Override
+ public void f(Widget w) {
+ $(w).text("W");
+ }
+ });
+ assertEquals("DW", g.text());
+
+ g.each(new Function() {
+ @Override
+ public Object f(com.google.gwt.user.client.Element e, int idx) {
+ $(e).text("U" + idx);
+ return "";
+ }
+ });
+ assertEquals("U0U1", g.text());
+ g.each(new Function() {
+ @Override
+ public Object f(com.google.gwt.user.client.Element e, int idx) {
+ $(e).text("D" + idx);
+ return "";
+ }
+ });
+ assertEquals("D0D1", g.text());
+
+ g.each(new Function() {
+ @Override
+ public Object f(com.google.gwt.user.client.Element e, int idx) {
+ $(e).text("U" + idx);
+ return "";
+ }
+ @Override
+ public Object f(Widget w, int idx) {
+ $(w).text("W" + idx);
+ return "";
+ }
+ });
+ assertEquals("U0U1", g.text());
+ g.each(new Function() {
+ @Override
+ public Object f(com.google.gwt.dom.client.Element e, int idx) {
+ $(e).text("D" + idx);
+ return "";
+ }
+ @Override
+ public Object f(Widget w, int idx) {
+ $(w).text("W" + idx);
+ return "";
+ }
+ });
+ assertEquals("D0D1", g.text());
+
+ g.each(new Function() {
+ @Override
+ public void f(com.google.gwt.user.client.Element e) {
+ $(e).text("U");
+ }
+ @Override
+ public Object f(Widget w, int idx) {
+ $(w).text("W" + idx);
+ return "";
+ }
+ });
+ assertEquals("UW1", g.text());
+ g.each(new Function() {
+ @Override
+ public void f(com.google.gwt.dom.client.Element e) {
+ $(e).text("D");
+ }
+ @Override
+ public Object f(Widget w, int idx) {
+ $(w).text("W" + idx);
+ return "";
+ }
+ });
+ assertEquals("DW1", g.text());
+
+ label.removeFromParent();
+ }
}