From f3c92755f53a72180469b2220da5d9b017112ec9 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Tue, 10 Mar 2015 10:20:17 +0100 Subject: [PATCH] Fix a disanbiguity introduced with SafeHtml patch When using gwt-2.8.0 and java8 gwt compiler is more restrictive and when you override a method(Object) with certain classes like Interfaces or JSO, there is an error like: The method $(Object) is ambiguous for the type GQuery. Also updated lazy interface with new methods. --- .../com/google/gwt/query/client/GQuery.java | 12 ++-- .../google/gwt/query/client/LazyGQuery.java | 68 +++++++++++++++++++ 2 files changed, 72 insertions(+), 8 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 a4b92733..4ed7cad8 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 @@ -225,6 +225,9 @@ public class GQuery implements Lazy { if (o instanceof String) { return $((String) o); } + if (o instanceof SafeHtml) { + return $(((SafeHtml) o).asString()); + } if (o instanceof GQuery) { return (GQuery) o; } @@ -300,13 +303,6 @@ public class GQuery implements Lazy { return $(selectorOrHtml, document); } - /** - * This function accepts a SafeHtml creating a GQuery element containing those elements. - */ - public static GQuery $(SafeHtml safeHtml) { - return $(safeHtml.asString()); - } - /** * This function accepts a string containing a CSS selector which is then used to match a set of * elements, or it accepts raw HTML creating a GQuery element containing those elements. The @@ -4941,7 +4937,7 @@ public class GQuery implements Lazy { * its structure -- it is that element that will enwrap everything else. */ public GQuery wrap(SafeHtml safeHtml) { - return wrap(safeHtml.asString()); + return wrap($(safeHtml)); } /** diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java index df766f9a..c9f43345 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java @@ -25,6 +25,7 @@ import com.google.gwt.query.client.js.JsNamedArray; import com.google.gwt.query.client.js.JsNodeArray; import com.google.gwt.query.client.plugins.Effects; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; +import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.user.client.ui.Widget; import java.util.List; @@ -78,6 +79,12 @@ public interface LazyGQuery extends LazyBase { */ LazyGQuery after(String html); + /** + * Insert content after each of the matched elements. The elements must already be inserted into + * the document (you can't insert an element after another if it's not in the page). + */ + LazyGQuery after(SafeHtml safeHtml); + /** * * The animate() method allows you to create animation effects on any numeric HTML Attribute, @@ -264,6 +271,12 @@ public interface LazyGQuery extends LazyBase { */ LazyGQuery append(String html); + /** + * Append content to the inside of every matched element. This operation is similar to doing an + * appendChild to all the specified elements, adding them into the document. + */ + LazyGQuery append(SafeHtml safeHtml); + /** * All of the matched set of elements will be inserted at the end of the element(s) specified by * the parameter other. @@ -291,6 +304,15 @@ public interface LazyGQuery extends LazyBase { */ LazyGQuery appendTo(String html); + /** + * All of the matched set of elements will be inserted at the end of the element(s) specified by + * the parameter other. + * + * The operation $(A).appendTo(B) is, essentially, the reverse of doing a regular $(A).append(B), + * instead of appending B to A, you're appending A to B. + */ + LazyGQuery appendTo(SafeHtml safeHtml); + /** * Convert to Plugin interface provided by Class literal. */ @@ -1122,6 +1144,11 @@ public interface LazyGQuery extends LazyBase { */ LazyGQuery html(String html); + /** + * Set the innerHTML of every matched element. + */ + LazyGQuery html(SafeHtml safeHtml); + /** * Get the id of the first matched element. */ @@ -1940,6 +1967,16 @@ public interface LazyGQuery extends LazyBase { */ LazyGQuery queue(String queueName, Function... f); + /** + * 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. + */ + Promise ready(Function... fncs); + /** * Removes all matched elements from the DOM. */ @@ -2489,6 +2526,15 @@ public interface LazyGQuery extends LazyBase { */ LazyGQuery wrap(String html); + /** + * Wrap each matched element with the specified SafeHtml content. This wrapping process is most useful + * for injecting additional structure into a document, without ruining the original semantic + * qualities of a document. This works by going through the first element provided (which is + * generated, on the fly, from the provided SafeHtml) and finds the deepest descendant element within + * its structure -- it is that element that will enwrap everything else. + */ + LazyGQuery wrap(SafeHtml safeHtml); + /** * Wrap all the elements in the matched set into a single wrapper element. This is different from * .wrap() where each element in the matched set would get wrapped with an element. This wrapping @@ -2525,6 +2571,18 @@ public interface LazyGQuery extends LazyBase { */ LazyGQuery wrapAll(String html); + /** + * Wrap all the elements in the matched set into a single wrapper element. This is different from + * .wrap() where each element in the matched set would get wrapped with an element. This wrapping + * process is most useful for injecting additional structure into a document, without ruining the + * original semantic qualities of a document. + * + * This works by going through the first element provided (which is generated, on the fly, from + * the provided SafeHtml) and finds the deepest descendant element within its structure -- it is that + * element that will enwrap everything else. + */ + LazyGQuery wrapAll(SafeHtml safeHtml); + /** * Wrap the inner child contents of each matched element (including text nodes) with an HTML * structure. This wrapping process is most useful for injecting additional structure into a @@ -2555,4 +2613,14 @@ public interface LazyGQuery extends LazyBase { */ LazyGQuery wrapInner(String html); + /** + * Wrap the inner child contents of each matched element (including text nodes) with an SafeHtml + * structure. This wrapping process is most useful for injecting additional structure into a + * document, without ruining the original semantic qualities of a document. This works by going + * through the first element provided (which is generated, on the fly, from the provided SafeHtml) and + * finds the deepest ancestor element within its structure -- it is that element that will enwrap + * everything else. + */ + LazyGQuery wrapInner(SafeHtml safeHtml); + } -- 2.39.5