diff options
author | Manuel Carrasco Moñino <manolo@apache.org> | 2014-12-30 14:04:07 +0100 |
---|---|---|
committer | Manuel Carrasco Moñino <manolo@apache.org> | 2014-12-30 14:04:07 +0100 |
commit | 26cc9ab92f71ffe2836c00764c1e0d92f9816642 (patch) | |
tree | fd35b661bedd1c9a5e54ed91ed0dea6125bbf479 | |
parent | 2317f553eb2fe1c61e0680caf361859fa2ce3a28 (diff) | |
parent | 9d1a308b92d23304f3843da7908f6851d83d38a0 (diff) | |
download | gwtquery-26cc9ab92f71ffe2836c00764c1e0d92f9816642.tar.gz gwtquery-26cc9ab92f71ffe2836c00764c1e0d92f9816642.zip |
Merge pull request #326 from manolo/mcm_ready_method
Implement GQuery.ready missing method
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java | 27 |
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() { |