aboutsummaryrefslogtreecommitdiffstats
path: root/gwtquery-core
diff options
context:
space:
mode:
authorManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>2013-02-07 15:59:18 +0100
committerManuel Carrasco Moñino <manuel.carrasco.m@gmail.com>2013-02-07 15:59:18 +0100
commit6c36a6ef2221026713b9d6146bd4fb50afc6b663 (patch)
treeeb5e97148dbe53e1e9458af2fafba704826eedab /gwtquery-core
parentb678c4a1dabf499fa8bf02c28c238347a38fc62a (diff)
downloadgwtquery-6c36a6ef2221026713b9d6146bd4fb50afc6b663.tar.gz
gwtquery-6c36a6ef2221026713b9d6146bd4fb50afc6b663.zip
Remove attribute after the property is set to null. Fixes issue 165
Diffstat (limited to 'gwtquery-core')
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeImpl.java2
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java13
-rw-r--r--gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java12
3 files changed, 24 insertions, 3 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeImpl.java
index 76fd335c..fcdba699 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeImpl.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeImpl.java
@@ -170,7 +170,6 @@ public class AttributeImpl {
if (e.getNodeType() != 1) {
continue;
}
- e.removeAttribute(key);
if (JsUtils.hasProperty(e, key)) {
if (BOOLEAN_ATTR_REGEX.test(key)) {
e.setPropertyBoolean(key, false);
@@ -178,6 +177,7 @@ public class AttributeImpl {
e.setPropertyObject(key, null);
}
}
+ e.removeAttribute(key);
}
}
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 962eccf1..c54ab588 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
@@ -245,13 +245,22 @@ public class JsUtils {
}
/**
- * Check if an object have already a property with name <code>name</code>
+ * Check if an object has already a property with name <code>name</code>
* defined.
*/
public static native boolean hasProperty(JavaScriptObject o, String name)/*-{
return o && name in o;
}-*/;
-
+
+ /**
+ * Check whether an element has an attribute, this is here since GWT Element.getAttribute
+ * implementation returns an empty string instead of null when the attribute is not
+ * present
+ */
+ public static native boolean hasAttribute(JavaScriptObject o, String name)/*-{
+ return !!(o && o.getAttribute(name));
+ }-*/;
+
/**
* Hyphenize style property names. for instance: fontName -> font-name
*/
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java
index 34fafb99..f4081011 100644
--- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java
+++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTestGwt.java
@@ -1148,6 +1148,18 @@ public class GQueryCoreTestGwt extends GWTTestCase {
assertEquals("disabled", ie.getAttribute("disabled"));
}
+
+ public void testAttr_Issue165() {
+ $(e).html("<a href='#' title='a title'>anchor</a>");
+ Element a = $("a", e).get(0);
+
+ assertEquals("a title", a.getAttribute("title"));
+ assertTrue(JsUtils.hasAttribute(a, "title"));
+
+ $(a).removeAttr("title");
+ assertEquals("", a.getAttribute("title"));
+ assertFalse(JsUtils.hasAttribute(a, "title"));
+ }
@DoNotRunWith({Platform.Prod})
// FIXME: the hidden part does not work in FF nor Chrome