From b2fe136c07bd889106f7995544a30811d6d9411b Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Tue, 12 Jul 2011 19:47:44 +0000 Subject: [PATCH] adding :odd :even :first :last pseudo selectors in xpath implementation. Related issue86 --- .../gwt/query/client/impl/SelectorEngineCssToXPath.java | 9 ++++++++- .../gwt/query/client/impl/SelectorEngineNative.java | 2 +- .../gwt/query/client/impl/SelectorEngineNativeIE8.java | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) 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)) { -- 2.39.5