aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManolo Carrasco <manolo@apache.org>2014-12-25 14:28:23 +0100
committerManolo Carrasco <manolo@apache.org>2014-12-25 14:31:15 +0100
commit9d1a308b92d23304f3843da7908f6851d83d38a0 (patch)
tree3f2e9ea9446a2d7996a021696850c8ca7865747e
parent0cb9c0669152eb5d2a5301527a768bcb2e7097c6 (diff)
downloadgwtquery-9d1a308b92d23304f3843da7908f6851d83d38a0.tar.gz
gwtquery-9d1a308b92d23304f3843da7908f6851d83d38a0.zip
Implement GQuery.ready missing method
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
index 098cb2da..d5fb0d99 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
@@ -13,6 +13,8 @@
*/
package com.google.gwt.query.client;
+import static com.google.gwt.query.client.GQuery.$;
+import static com.google.gwt.query.client.GQuery.document;
import static com.google.gwt.query.client.plugins.QueuePlugin.Queue;
import com.google.gwt.core.client.GWT;
@@ -54,6 +56,7 @@ import com.google.gwt.query.client.plugins.Widgets;
import com.google.gwt.query.client.plugins.ajax.Ajax;
import com.google.gwt.query.client.plugins.ajax.Ajax.Settings;
import com.google.gwt.query.client.plugins.deferred.Deferred;
+import com.google.gwt.query.client.plugins.deferred.PromiseFunction;
import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing;
import com.google.gwt.query.client.plugins.events.EventsListener;
import com.google.gwt.query.client.plugins.widgets.WidgetsUtils;
@@ -3813,6 +3816,30 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
}
/**
+ * Specify a function to execute when the DOM is fully loaded.
+ *
+ * While JavaScript provides the load event for executing code when a page is rendered, this event
+ * is not seen if we attach an event listener after the document has been loaded.
+ * This guarantees that our gwt code will be executed either it's executed synchronously before the
+ * DOM has been rendered (ie: single script linker in header) or asynchronously.
+ */
+ public Promise ready(Function... fncs) {
+ return new PromiseFunction() {
+ public void f(final com.google.gwt.query.client.Promise.Deferred dfd) {
+ if ("complete" == $(document).prop("readyState")) {
+ dfd.resolve();
+ } else {
+ $(document).on("load", new Function() {
+ public void f() {
+ dfd.resolve();
+ }
+ });
+ }
+ }
+ }.done(fncs);
+ }
+
+ /**
* Removes all matched elements from the DOM.
*/
public GQuery remove() {