diff options
Diffstat (limited to 'gwtquery-core')
3 files changed, 39 insertions, 10 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 9af3215c..0f07729b 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 @@ -399,6 +399,9 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { // TODO: fix IE link tag serialization
// TODO: fix IE <script> tag
+ // TODO: add fixes for IE TBODY issue
+
+ // We use a temporary element to wrap the elements
Element div = doc.createDivElement();
div.setInnerHTML(wrapper.preWrap + elem.trim() + wrapper.postWrap);
Node n = div;
@@ -406,8 +409,12 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> { while (depth-- != 0) {
n = n.getLastChild();
}
- // TODO: add fixes for IE TBODY issue
- return $((NodeList<Element>) n.getChildNodes().cast());
+
+ return
+ // return all nodes added to the wrapper
+ $(n.getChildNodes())
+ // detach nodes from their temporary parent
+ .remove();
}
/**
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 |