public
Description: Prototype JavaScript framework
Homepage: http://prototypejs.org/
Clone URL: git://github.com/sstephenson/prototype.git
Fix issue where Opera gets confused by complex selectors in $$. [#157 
state:resolved]
Tue Jun 24 11:29:37 -0700 2008
commit  6cdef71df792ae67ea1ecb4e69c64db5a3d03a0c
tree    168ebc912ee993ee1aa4d0605b9aa0654a6ae647
parent  69a4e3f5c1f0b1d1656e6ba6ce8f3c4f0dc29e66
...
 
 
1
2
3
...
1
2
3
4
5
0
@@ -1,3 +1,5 @@
0
+* Fix issue where Opera gets confused by complex selectors in $$. [Paulo Pereira, Andrea Baron, jddalton] 
0
+
0
 * Fix for IE7 to access local files via Ajax.Request. Closes #8259. [hagen.seifert, jddalton]
0
 
0
 * Ensure CSS files have loaded before firing the dom:loaded event. [Diego Perini, jddalton]
...
22
23
24
 
 
 
 
25
26
27
...
32
33
34
35
 
36
37
38
...
461
462
463
464
465
466
 
 
 
 
 
 
 
 
 
 
 
 
467
468
469
...
22
23
24
25
26
27
28
29
30
31
...
36
37
38
 
39
40
41
42
...
465
466
467
 
 
 
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
0
@@ -22,6 +22,10 @@ var Selector = Class.create({
0
     if (!Prototype.BrowserFeatures.XPath) return false;
0
     
0
     var e = this.expression;
0
+    
0
+    // Opera's XPath engine breaks down when selectors are too complex
0
+    if (Prototype.Browser.Opera)
0
+      return false;    
0
 
0
     // Safari 3 chokes on :*-of-type and :empty
0
     if (Prototype.Browser.WebKit && 
0
@@ -32,7 +36,7 @@ var Selector = Class.create({
0
     // the "checked" property from DOM nodes
0
     if ((/(\[[\w-]*?:|:checked)/).test(e))
0
       return false;
0
-
0
+      
0
     return true;
0
   },
0
   
0
@@ -461,9 +465,18 @@ Object.extend(Selector, {
0
     id: function(nodes, root, id, combinator) {
0
       var targetNode = $(id), h = Selector.handlers;
0
       if (!targetNode) {
0
-        // IE doesn't find elements by ID if they're not attached to the
0
-        // document.
0
-        if (Prototype.Browser.IE && (root.sourceIndex < 1 || root === document)) {
0
+        var needsToSearch = false;
0
+        // IE and Opera don't find elements by ID if they're not attached
0
+        // to the document.
0
+        if (Prototype.Browser.IE && (root.sourceIndex < 1 ||
0
+         root === document)) {
0
+          needsToSearch = true;        
0
+        } else if (Prototype.Browser.Opera &&
0
+         (root.compareDocumentPosition(document) & 1) === 1) {
0
+          needsToSearch = true;   
0
+        }
0
+        
0
+        if (needsToSearch) {
0
           var nodes = root.getElementsByTagName('*');
0
           for (var i = 0, node; node = nodes[i]; i++) {
0
             if (node.id === id) {
...
379
380
381
382
383
384
 
 
 
385
386
387
...
379
380
381
 
 
 
382
383
384
385
386
387
0
@@ -379,8 +379,8 @@ new Test.Unit.Runner({
0
     var wrapper = new Element("div");
0
     wrapper.update("<table><tr><td id='myTD'></td></tr></table>");
0
     new Selector('[id=myTD]').findElements(wrapper);
0
-    this.assertNotNullOrUndefined(wrapper.select('[id=myTD]')[0]);
0
-    this.assertNotNullOrUndefined(wrapper.select('td')[0]);
0
-    this.assertNotNullOrUndefined(wrapper.select('#myTD')[0]);
0
+    this.assertNotNullOrUndefined(wrapper.select('[id=myTD]')[0], "[id=myTD]");
0
+    this.assertNotNullOrUndefined(wrapper.select('td')[0], "td");
0
+    this.assertNotNullOrUndefined(wrapper.select('#myTD')[0], "#myTD");
0
   }
0
 });
0
\ No newline at end of file

Comments