- Added new selector classes for Ie8.
- Little re-factor in SelectorEngine.
Thanks to @johnthuss who spoted out the issue and sent a great patch.
Fixes issue37
<generate-with class="com.google.gwt.query.rebind.SelectorGeneratorNative">\r
<when-type-assignable class="com.google.gwt.query.client.Selectors"/>\r
<when-property-is name="selectorCapability" value="native"/>\r
- <none>\r
- <when-property-is name="user.agent" value="ie8"/>\r
- </none>\r
</generate-with>\r
+
+ <generate-with class="com.google.gwt.query.rebind.SelectorGeneratorNativeIE8">\r
+ <when-type-assignable class="com.google.gwt.query.client.Selectors"/>\r
+ <when-property-is name="selectorCapability" value="native"/>
+ <when-property-is name="user.agent" value="ie8"/>\r
+ </generate-with>
\r
<replace-with class="com.google.gwt.query.client.impl.DocumentStyleImpl">\r
- <when-type-assignable\r
- class="com.google.gwt.query.client.impl.DocumentStyleImpl"/>\r
+ <when-type-assignable class="com.google.gwt.query.client.impl.DocumentStyleImpl"/>\r
</replace-with>\r
\r
<replace-with class="com.google.gwt.query.client.impl.DocumentStyleImplIE">\r
- <when-type-assignable\r
- class="com.google.gwt.query.client.impl.DocumentStyleImpl"/>\r
+ <when-type-assignable class="com.google.gwt.query.client.impl.DocumentStyleImpl"/>\r
<any>\r
<when-property-is name="user.agent" value="ie6"/>\r
<when-property-is name="user.agent" value="ie8"/>\r
</replace-with>\r
\r
<replace-with class="com.google.gwt.query.client.impl.SelectorEngineSizzle">\r
- <when-type-assignable\r
- class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
+ <when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
</replace-with>\r
\r
<replace-with class="com.google.gwt.query.client.impl.SelectorEngineCssToXPath">\r
</any>\r
</replace-with>\r
\r
- <replace-with class="com.google.gwt.query.client.impl.SelectorEngineNative">\r
- <when-type-assignable\r
- class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
+ <replace-with class="com.google.gwt.query.client.impl.SelectorEngineNativeIE8">\r
+ <when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
+ <when-property-is name="selectorCapability" value="native"/>\r
+ </replace-with>\r
+ \r
+ <replace-with class="com.google.gwt.query.client.impl.SelectorEngineNativeIE8">\r
+ <when-type-assignable class="com.google.gwt.query.client.impl.SelectorEngineImpl"/>\r
<when-property-is name="selectorCapability" value="native"/>\r
- <none>\r
- <when-property-is name="user.agent" value="ie8"/>\r
- </none>\r
+ <when-property-is name="user.agent" value="ie8"/>\r
</replace-with>\r
+
+ <define-linker name="stddoctype" class="com.google.gwt.query.linker.IFrameWithDocTypeLinker"/>
+ <add-linker name="stddoctype"/>
\r
<entry-point class='com.google.gwt.query.client.css.CSS'/>\r
\r
private static native <T extends Node> T[] reinterpretCast(NodeList<T> nl) /*-{\r
return nl;\r
}-*/;\r
+ \r
+ private static SelectorEngine engine;\r
\r
private static NodeList<Element> select(String selector, Node context) {\r
- NodeList<Element> n = new SelectorEngine().select(selector, context);\r
+ if (engine == null) {\r
+ engine = new SelectorEngine();\r
+ }\r
+ NodeList<Element> n = engine.select(selector, context);\r
JSArray res = copyNodeList(n);\r
return res;\r
}\r
return r;\r
}-*/;\r
\r
- private SelectorEngineImpl impl;\r
+ protected SelectorEngineImpl impl;\r
+\r
+ protected Node root = Document.get();\r
\r
public SelectorEngine() {\r
impl = (SelectorEngineImpl) GWT.create(SelectorEngineImpl.class);\r
}\r
\r
+ public Node getRoot() {\r
+ return root;\r
+ }\r
+ \r
public NodeList<Element> select(String selector, Node ctx) {\r
return impl.select(selector, ctx);\r
}\r
-\r
+ \r
+ public void setRoot(Node root) {\r
+ assert root != null;\r
+ this.root = root;\r
+ }\r
+ \r
protected JSArray veryQuickId(Node context, String id) {\r
JSArray r = JSArray.create();\r
if (context.getNodeType() == Node.DOCUMENT_NODE) {\r
}\r
}\r
\r
- protected Node root = Document.get();\r
- \r
- public void setRoot(Node root) {\r
- assert root != null;\r
- this.root = root;\r
- }\r
- \r
- public Node getRoot() {\r
- return root;\r
- }\r
- \r
}\r
--- /dev/null
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client.impl;
+
+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.SelectorEngine;
+
+/**
+ * Runtime selector engine implementation for browsers with native
+ * querySelectorAll support.
+ */
+public class SelectorEngineNativeIE8 extends SelectorEngineSizzle {
+
+ public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:checked|:not|:nth-|:last-|:only-).*";
+
+ public NodeList<Element> select(String selector, Node ctx) {
+ if (selector.matches(NATIVE_EXCEPTIONS_REGEXP)) {
+ return super.select(selector, ctx);
+ } else {
+ return SelectorEngine.querySelectorAll(selector, ctx);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.linker;
+
+import com.google.gwt.core.ext.LinkerContext;
+import com.google.gwt.core.ext.TreeLogger;
+import com.google.gwt.core.linker.IFrameLinker;
+import com.google.gwt.core.ext.linker.LinkerOrder;
+
+/**
+ * Adds doctype to the iframe used to load the application.
+ * Without this code, IE8 does not enable document.querySelectorAll feature.
+ */
+@LinkerOrder(LinkerOrder.Order.PRIMARY)
+public class IFrameWithDocTypeLinker extends IFrameLinker {
+
+ private static final String DOCTYPE = "<!doctype html>\n";
+
+ protected String getModulePrefix(TreeLogger logger, LinkerContext context,
+ String strongName) {
+ return DOCTYPE + super.getModulePrefix(logger, context, strongName);
+ }
+
+ @Override
+ protected String getModulePrefix(TreeLogger logger, LinkerContext context,
+ String strongName, int numFragments) {
+ return DOCTYPE
+ + super.getModulePrefix(logger, context, strongName, numFragments);
+ }
+}
}\r
\r
protected String getImplSuffix() {\r
- return "XPath" + super.getImplSuffix();\r
+ return "CssToXPath" + super.getImplSuffix();\r
}\r
\r
}\r
protected void generateMethodBody(SourceWriter sw, JMethod method,\r
TreeLogger treeLogger, boolean hasContext)\r
throws UnableToCompleteException {\r
-\r
String selector = method.getAnnotation(Selector.class).value();\r
-\r
- sw.println("return " + wrap(method,\r
- "new SelectorEngine().select(\"" + selector + "\", root)") + ";");\r
+ sw.println("return "\r
+ + wrap(method, "impl.select(\"" + selector + "\", root)") + ";");\r
}\r
}\r
String selector = method.getAnnotation(Selector.class).value();\r
\r
sw.println("return " + wrap(method,\r
- "new SelectorEngine().select(\"" + selector + "\", root)") + ";");\r
+ "impl.select(\"" + selector + "\", root)") + ";");\r
// sw.println("JSArray n = JSArray.create();");\r
// if(!hasContext) { \r
// sw.println("Node root = Document.get();");\r
protected void generateMethodBody(SourceWriter sw, JMethod method,\r
TreeLogger treeLogger, boolean hasContext)\r
throws UnableToCompleteException {\r
+\r
String selector = method.getAnnotation(Selector.class).value();\r
if (selector.matches(SelectorEngineNative.NATIVE_EXCEPTIONS_REGEXP)) {\r
super.generateMethodBody(sw, method, treeLogger, hasContext);\r
--- /dev/null
+/*\r
+ * Copyright 2009 Google Inc.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
+ * use this file except in compliance with the License. You may obtain a copy of\r
+ * the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+ * License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+package com.google.gwt.query.rebind;\r
+\r
+import com.google.gwt.core.ext.TreeLogger;\r
+import com.google.gwt.core.ext.UnableToCompleteException;\r
+import com.google.gwt.core.ext.typeinfo.JMethod;\r
+import com.google.gwt.query.client.Selector;\r
+import com.google.gwt.query.client.impl.SelectorEngineNativeIE8;\r
+import com.google.gwt.user.rebind.SourceWriter;\r
+\r
+/**\r
+ * Compile time selector generator which delegates to native browser methods.\r
+ */\r
+public class SelectorGeneratorNativeIE8 extends SelectorGeneratorJS {\r
+\r
+ @Override\r
+ protected void generateMethodBody(SourceWriter sw, JMethod method,\r
+ TreeLogger treeLogger, boolean hasContext)\r
+ throws UnableToCompleteException {\r
+ String selector = method.getAnnotation(Selector.class).value();\r
+ if (selector.matches(SelectorEngineNativeIE8.NATIVE_EXCEPTIONS_REGEXP)) {\r
+ super.generateMethodBody(sw, method, treeLogger, hasContext);\r
+ } else {\r
+ sw.println("return "\r
+ + wrap(method, "querySelectorAll(\"" + selector + "\", root)") + ";");\r
+ }\r
+ }\r
+\r
+ @Override\r
+ protected String getImplSuffix() {\r
+ return "IE8" + super.getImplSuffix();\r
+ }\r
+\r
+ @Override\r
+ protected boolean hasGetElementsByClassName() {\r
+ return false;\r
+ }\r
+}
\ No newline at end of file
final GQuery g = $("#idtest").css("position", "absolute");
final Offset o = g.offset();
- final int duration = 800;
+ final int duration = 1000;
g.as(Effects.Effects).
animate($$("left: '+=100'"), duration, Easing.LINEAR).
animate($$("top: '+=100'"), duration, Easing.LINEAR).