Skip to content

Commit

Permalink
Fix issue where Opera gets confused by complex selectors in $$. [#157
Browse files Browse the repository at this point in the history
…state:resolved]
  • Loading branch information
savetheclocktower committed Jun 24, 2008
1 parent 69a4e3f commit 6cdef71
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
* Fix issue where Opera gets confused by complex selectors in $$. [Paulo Pereira, Andrea Baron, jddalton]

* Fix for IE7 to access local files via Ajax.Request. Closes #8259. [hagen.seifert, jddalton]

* Ensure CSS files have loaded before firing the dom:loaded event. [Diego Perini, jddalton]
Expand Down
21 changes: 17 additions & 4 deletions src/selector.js
Expand Up @@ -22,6 +22,10 @@ var Selector = Class.create({
if (!Prototype.BrowserFeatures.XPath) return false;

var e = this.expression;

// Opera's XPath engine breaks down when selectors are too complex
if (Prototype.Browser.Opera)
return false;

// Safari 3 chokes on :*-of-type and :empty
if (Prototype.Browser.WebKit &&
Expand All @@ -32,7 +36,7 @@ var Selector = Class.create({
// the "checked" property from DOM nodes
if ((/(\[[\w-]*?:|:checked)/).test(e))
return false;

return true;
},

Expand Down Expand Up @@ -461,9 +465,18 @@ Object.extend(Selector, {
id: function(nodes, root, id, combinator) {
var targetNode = $(id), h = Selector.handlers;
if (!targetNode) {
// IE doesn't find elements by ID if they're not attached to the
// document.
if (Prototype.Browser.IE && (root.sourceIndex < 1 || root === document)) {
var needsToSearch = false;
// IE and Opera don't find elements by ID if they're not attached
// to the document.
if (Prototype.Browser.IE && (root.sourceIndex < 1 ||
root === document)) {
needsToSearch = true;
} else if (Prototype.Browser.Opera &&
(root.compareDocumentPosition(document) & 1) === 1) {
needsToSearch = true;
}

if (needsToSearch) {
var nodes = root.getElementsByTagName('*');
for (var i = 0, node; node = nodes[i]; i++) {
if (node.id === id) {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/selector_test.js
Expand Up @@ -379,8 +379,8 @@ new Test.Unit.Runner({
var wrapper = new Element("div");
wrapper.update("<table><tr><td id='myTD'></td></tr></table>");
new Selector('[id=myTD]').findElements(wrapper);
this.assertNotNullOrUndefined(wrapper.select('[id=myTD]')[0]);
this.assertNotNullOrUndefined(wrapper.select('td')[0]);
this.assertNotNullOrUndefined(wrapper.select('#myTD')[0]);
this.assertNotNullOrUndefined(wrapper.select('[id=myTD]')[0], "[id=myTD]");
this.assertNotNullOrUndefined(wrapper.select('td')[0], "td");
this.assertNotNullOrUndefined(wrapper.select('#myTD')[0], "#myTD");
}
});

0 comments on commit 6cdef71

Please sign in to comment.