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
return this;\r
\r
}\r
+ \r
+ /**\r
+ * Bind a set of functions to the resize event of each matched element, or\r
+ * tigger the resize event if no functions are provided.\r
+ * \r
+ * Note that although all elements can be configured to handle resize\r
+ * events, by default only window will trigger it when it is resized, \r
+ * for an arbitrary element you have to trigger the event after resizing \r
+ * the object. \r
+ * \r
+ */\r
+ public GQuery resize(Function... f) {\r
+ return bindOrFire(EventsListener.ONRESIZE, null, f);\r
+ }\r
\r
/**\r
* Save a set of Css properties of every matched element.\r
}\r
}\r
}\r
+ \r
+ /**\r
+ * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. \r
+ */\r
+ public void resize(final Function f) {\r
+ \r
+ }\r
\r
/**\r
* Restore a set of previously saved Css properties in every matched element.\r
return as(Effects).stop(clearQueue);\r
}\r
\r
- public GQuery submit() {\r
- return as(Events).trigger(EventsListener.ONSUBMIT);\r
+ /**\r
+ * Bind a set of functions to the submit event of each matched element. \r
+ * Or submit a form if no functions are provided.\r
+ */\r
+ public GQuery submit(Function... funcs) {\r
+ return bindOrFire(EventsListener.ONSUBMIT, null, funcs);\r
}\r
\r
/**\r
import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.HasCssName;
import com.google.gwt.dom.client.TextAreaElement;
+import com.google.gwt.event.logical.shared.ResizeEvent;
+import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.query.client.css.CSS;
import com.google.gwt.query.client.css.HasCssValue;
import com.google.gwt.query.client.css.TakesCssValue;
*/
LazyGQuery<T> replaceWith(String html);
+ /**
+ * Bind a set of functions to the resize event of each matched element, or
+ * tigger the resize event if no functions are provided.
+ *
+ * Note that although all elements can be configured to handle resize
+ * events, by default only window will trigger it when it is resized,
+ * for an arbitrary element you have to trigger the event after resizing
+ * the object.
+ *
+ */
+ LazyGQuery<T> resize(Function... f);
+
/**
* Save a set of Css properties of every matched element.
*/
void restoreCssAttrs(String... cssProps);
+ /**
+ * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element.
+ */
+ void resize(Function f);
+
/**
* Restore a set of previously saved Css properties in every matched element.
*/
*/
LazyGQuery<T> stop(boolean clearQueue);
- LazyGQuery<T> submit();
+ /**
+ * Bind a set of functions to the submit event of each matched element.
+ * Or submit a form if no functions are provided.
+ */
+ LazyGQuery<T> submit(Function... funcs);
/**
* Return the text contained in the first matched element.
0, 0, 0, false, false, false, false, NativeEvent.BUTTON_LEFT, null));
if (eventbits == EventsListener.ONSUBMIT)
triggerHtmlEvent("submit");
+ if (eventbits == EventsListener.ONRESIZE)
+ triggerHtmlEvent("resize");
return this;
}
// Gwt Events class has not this event defined, so we have to select ane available power of 2
public static int ONSUBMIT = 0x8000000;
+ public static int ONRESIZE = 0x4000000;
+
public static void clean(Element e) {
EventsListener ret = getGQueryEventListener(e);
if (elem.__gwtlistener) {
elem.__listener = elem.__gwtlistener;
}
- elem.__gquerysubmit = null;
elem.__gqueryevent = null
+ elem.__gquery = null;
}-*/;
}
}-*/;
- // Gwt does't handle submit events in DOM.sinkEvents
- private static native void sinkSubmitEvent(Element elem) /*-{
- if (elem.__gquerysubmit)
- return;
- elem.__gquerysubmit = true;
+ // Gwt does't handle submit nor resize events in DOM.sinkEvents
+ private static native void sinkEvent(Element elem, String name) /*-{
+ if (!elem.__gquery) elem.__gquery = [];
+ if (elem.__gquery[name]) return;
+ elem.__gquery[name] = true;
var handle = function(event) {
elem.__gqueryevent.@com.google.gwt.query.client.plugins.events.EventsListener::dispatchEvent(Lcom/google/gwt/user/client/Event;)(event);
};
if (elem.addEventListener)
- elem.addEventListener("submit", handle, true);
+ elem.addEventListener(name, handle, true);
else
- elem.attachEvent("onsubmit", handle);
+ elem.attachEvent("on" + name, handle);
}-*/;
+
int eventBits = 0;
double lastEvnt = 0;
setGQueryEventListener(element, this);
DOM.setEventListener((com.google.gwt.user.client.Element) element, this);
if (eventBits == ONSUBMIT) {
- sinkSubmitEvent(element);
+ sinkEvent(element, "submit");
+ } else if (eventBits == ONRESIZE) {
+ sinkEvent(element, "resize");
} else {
if ((eventBits | Event.FOCUSEVENTS) == Event.FOCUSEVENTS
&& element.getAttribute("tabIndex").length() == 0) {
for (String s : parts) {
if ("submit".equals(s)) {
ret |= ONSUBMIT;
+ } else if ("resize".equals(s)) {
+ ret |= ONRESIZE;
} else {
int event = Event.getTypeInt(s);
if (event > 0) {
}
private int getTypeInt(String eventName) {
- return "submit".equals(eventName) ? ONSUBMIT : Event.getTypeInt(eventName);
+ return "submit".equals(eventName) ? ONSUBMIT : "resize".equals(eventName) ? ONRESIZE : Event.getTypeInt(eventName);
}
public void cleanEventDelegation() {
import com.google.gwt.query.client.plugins.events.EventsListener;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
+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.RootPanel;
assertEquals("red", $(b).css("color"));
}
+ @DoNotRunWith({Platform.HtmlUnitLayout})
+ public void testResizeWindowEvent() {
+ GQuery w = $(GQuery.window);
+
+ delayTestFinish(100);
+ w.bind("resize", null, new Function() {
+ public void f(Element e) {
+ finishTest();
+ }
+ });
+
+ Window.resizeTo(w.width(), w.height() + 100);
+ }
+
+ public void testResizeEvent() {
+ $(e).html("<div id=ra></div>");
+ GQuery g = $("#ra", e);
+
+ delayTestFinish(100);
+ g.bind("resize", null, new Function() {
+ public void f(Element e) {
+ finishTest();
+ }
+ });
+
+ g.width(400);
+ g.resize();
+ }
+
public void testSubmitEvent() {
// Add a form and an iframe to the dom. The form target is the iframe
$(e).html("<form action='whatever' target='miframe'><input type='text' value='Hello'><input type='submit' value='Go'></form><iframe name='miframe' id='miframe' src=\"javascript:''\">");