aboutsummaryrefslogtreecommitdiffstats
path: root/gwtquery-core
diff options
context:
space:
mode:
authorManolo Carrasco <manolo@apache.org>2011-08-26 12:10:41 +0000
committerManolo Carrasco <manolo@apache.org>2011-08-26 12:10:41 +0000
commit6f5d12c06127d0704f36b07b220676b8cc7a33d8 (patch)
treea804c9d6c1ea5f1aedda3ab2e0f82422a095e538 /gwtquery-core
parent99b59641398f39d062899499931ec3e8522c4120 (diff)
downloadgwtquery-6f5d12c06127d0704f36b07b220676b8cc7a33d8.tar.gz
gwtquery-6f5d12c06127d0704f36b07b220676b8cc7a33d8.zip
support for :radio and :checkbox pseudoselectors. Fixes issue_100.
Diffstat (limited to 'gwtquery-core')
-rw-r--r--gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java12
-rw-r--r--gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java14
2 files changed, 18 insertions, 8 deletions
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java
index 65d735df..dd555bfd 100644
--- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java
+++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java
@@ -22,6 +22,8 @@ import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Node;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.query.client.js.JsNodeArray;
+import com.google.gwt.query.client.js.JsObjectArray;
+import com.google.gwt.query.client.js.JsRegexp;
import com.google.gwt.query.client.js.JsUtils;
/**
@@ -110,9 +112,11 @@ public class SelectorEngine implements HasSelector {
return res;
}
+ // :visible and :hidden pseudo selectors are computed by gquery
+ JsRegexp p = new JsRegexp(".*:(visible|hidden|radio|checkbox)\\s*(,|$).*");
+
public NodeList<Element> select(String selector, Node ctx) {
- if (selector.matches(".*:(visible|hidden)\\s*(,|$).*")) {
- // :visible and :hidden pseudo selectors are computed by gquery
+ if (p.test(selector)) {
JsNodeArray res = JsNodeArray.create();
for (String s : selector.trim().split("\\s*,\\s*")) {
NodeList<Element> nodes;
@@ -120,6 +124,10 @@ public class SelectorEngine implements HasSelector {
nodes = filterByVisibility(select(s.substring(0, s.length() - 8), ctx), true);
} else if (s.endsWith(":hidden")) {
nodes = filterByVisibility(select(s.substring(0, s.length() - 7), ctx), false);
+ } else if (s.endsWith(":radio")) {
+ nodes = select(s.replace(":radio", "[type='radio']"), ctx);
+ } else if (s.endsWith(":checkbox")) {
+ nodes = select(s.replace(":checkbox", "[type='checkbox']"), ctx);
} else {
nodes = select(s, ctx);
}
diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java
index 57a4f7fd..86428746 100644
--- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java
+++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQuerySelectorsTest.java
@@ -176,13 +176,15 @@ public class GQuerySelectorsTest extends GWTTestCase {
}
}
- public void testVisibleHidden() {
- $(e).html("<table border=1 id=idtest width=440><tr><td width=50%>A Text</td><td width=50%><a></a><p id=a></p><p id=b style='display: none'><span id=c></span></p></td></tr></table>");
+ public void testJQueryPseudoselectors() {
+ $(e).html("<table border=1 id=idtest width=440><tr><td width=50%>A Text</td><td width=50%><a></a><p id=a></p><p id=b style='display: none'><span id=c>s</span></p></td></tr></table>");
assertEquals(9, $("* ", e).size());
- assertEquals(1, $("*:hidden ", e).size());
- assertEquals(8, $("*:visible ", e).size());
- assertEquals(2, $("*:hidden , span", e).size());
- assertEquals(8, $("*:visible , span", e).size());
+ assertEquals(2, $("span:hidden, p:hidden ", e).size());
+ assertEquals(2, $("td:visible ", e).size());
+ $(e).html("<input type='checkbox' id='cb' name='cb' value='1' /><input type='radio' id='cb' name='cb' value='1' />");
+ assertEquals(1, $("input:checkbox ", e).size());
+ assertEquals(1, $(":radio ", e).size());
+ assertEquals(2, $("*:radio, *:checkbox", e).size());
}
public void testCompiledSelectors() {