diff options
author | Manolo Carrasco <manolo@apache.org> | 2012-10-12 20:28:47 +0200 |
---|---|---|
committer | Manolo Carrasco <manolo@apache.org> | 2012-10-12 20:28:47 +0200 |
commit | eb0ef954258a36db8fa2fc72c09ac63232e2202a (patch) | |
tree | 777765c880f69adcb68b0e256d5dd4598b899a0c | |
parent | c661cbf469dd9f1d798a72b6e69a8f938442d7ca (diff) | |
download | gwtquery-eb0ef954258a36db8fa2fc72c09ac63232e2202a.tar.gz gwtquery-eb0ef954258a36db8fa2fc72c09ac63232e2202a.zip |
Append temporary dettached elements to the document so as we can correctly compute certain values
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java | 29 | ||||
-rw-r--r-- | gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java | 9 |
2 files changed, 30 insertions, 8 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java index 39e8ee09..6fcfca31 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java @@ -93,16 +93,29 @@ public class DocumentStyleImpl { name = fixPropertyName(name); //value defined in the element style String ret = elem.getStyle().getProperty(name); - - if (force && sizeRegex.test(name)) { - return getVisibleSize(elem, name) + "px"; - } - if (force && "opacity".equalsIgnoreCase(name)) { - return String.valueOf(getOpacity(elem)); - } + if (force) { - ret = getComputedStyle(elem, JsUtils.hyphenize(name), name, null); + // If the element is dettached to the DOM we attach temporary to it + Element parent = null; + if (JsUtils.isDettached(elem)) { + parent = elem.getParentElement(); + Document.get().getBody().appendChild(elem); + } + + if (sizeRegex.test(name)) { + ret = getVisibleSize(elem, name) + "px"; + } else if ("opacity".equalsIgnoreCase(name)) { + ret = String.valueOf(getOpacity(elem)); + } else { + ret = getComputedStyle(elem, JsUtils.hyphenize(name), name, null); + } + + // If the element had a parent previously to be attached, append to it. + if (parent != null) { + parent.appendChild(elem); + } } + return ret == null ? "" : ret; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java index e9649b19..9d384a19 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java @@ -274,6 +274,15 @@ public class JsUtils { return e.defaultPrevented || e.returnValue === false || e.getPreventDefault && e.getPreventDefault() ? true : false; }-*/; + + /** + * Return whether a node is dettached to the dom + */ + public static native boolean isDettached(Node n) /*-{ + while (n.parentNode) + n = n.parentNode; + return !n.body; + }-*/; /** * Check is a javascript object can be cast to an Element |