From: Manolo Carrasco Date: Tue, 12 Jul 2011 19:47:44 +0000 (+0000) Subject: adding :odd :even :first :last pseudo selectors in xpath implementation. Related... X-Git-Tag: release-1.3.2~280 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b2fe136c07bd889106f7995544a30811d6d9411b;p=gwtquery.git adding :odd :even :first :last pseudo selectors in xpath implementation. Related issue86 --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java index 7426aa29..dad73d9a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java @@ -99,7 +99,7 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { // add @ for attrib "\\[([^@\\]~\\$\\*\\^\\|\\!]+)(=[^\\]]+)?\\]", "[@$1$2]", // multiple queries - "\\s*,\\s*", "|", + "\\s*,\\s*", "|.//", // , + ~ > "\\s*(\\+|~|>)\\s*", "$1", //* ~ + > @@ -120,7 +120,12 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { "([\\w\\-\\*]+):only-child", "*[last()=1]/self::$1", // :empty "([\\w\\-\\*]+):empty", "$1[not(*) and not(normalize-space())]", + // :odd :even, this is intentional since sizzle behaves so + ":odd" , ":nth-child(even)", + ":even" , ":nth-child(odd)", + // :not "(.+):not\\(([^\\)]*)\\)", rc_Not, + // :nth-child "([a-zA-Z0-9\\_\\-\\*]+):nth-child\\(([^\\)]*)\\)", rc_nth_child, // :contains(selectors) ":contains\\(([^\\)]*)\\)", "[contains(string(.),'$1')]", @@ -145,6 +150,8 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { ":(enabled)", "[not(@disabled)]", ":(checked)", "[@$1='$1']", ":(disabled)", "[@$1]", + ":(first)", "[1]", + ":(last)", "[last()]", // put '*' when tag is omitted "(^|\\|)(\\[)", "$1*$2", // Replace escaped dots and spaces diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java index 7996d107..d69148c4 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java @@ -26,7 +26,7 @@ import com.google.gwt.dom.client.NodeList; */ public class SelectorEngineNative extends SelectorEngineImpl { - public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=).*"; + public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:first|:last|:even|:odd).*"; private static HasSelector impl; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java index bc55b50c..9c405cd6 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java @@ -29,7 +29,7 @@ import com.google.gwt.dom.client.NodeList; */ public class SelectorEngineNativeIE8 extends SelectorEngineSizzleIE { - public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:checked|:not|:nth-|:last-|:only-).*"; + public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:checked|:not|:nth-|:only-|:first|:last|:even|:odd).*"; public NodeList select(String selector, Node ctx) { if (!SelectorEngine.hasQuerySelector || selector.matches(NATIVE_EXCEPTIONS_REGEXP)) {