Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11474: select_id_ie_patch_jd.diff

File select_id_ie_patch_jd.diff, 1.7 kB (added by jdalton, 8 months ago)

this one keeps the IE branch sep and only brute forces if the element is not attached.

  • src/selector.js

    old new  
    670670      for (var i = 0, node; node = nodes[i]; i++) 
    671671        node.removeAttribute('_countedByPrototype'); 
    672672      return nodes;   
    673     } 
    674   });   
     673    }, 
     674     
     675    // IE doesn't find elements by id if they are not attached to the document 
     676    id: Selector.handlers.id.wrap(function(proceed, nodes, root, id, combinator) { 
     677      var targetNode = $(id); 
     678      if (!targetNode && (root.sourceIndex < 1 || root == document)) { 
     679        var nodes = root.getElementsByTagName('*'), i = nodes.length; 
     680        while(i){ //faster than for-loop? 
     681          if(nodes[--i].id == id) { 
     682            targetNode = nodes[i]; break; 
     683          } 
     684        } 
     685      } 
     686      return proceed(nodes, root, targetNode, combinator); 
     687    }) 
     688  }); 
    675689} 
    676690 
    677691function $$() { 
  • test/unit/selector.html

    old new  
    459459        Selector.matchElements($('counted_container').descendants(), 'div'), 'div.is_counted',  
    460460        'div.is_counted' 
    461461      ); 
     462    }, 
     463     
     464    testSelectorNotInsertedNodes: function() { 
     465      var wrapper = new Element("div"); 
     466      wrapper.update("<table><tr><td id='myTD'></td></tr></table>"); 
     467      new Selector('[id=myTD]').findElements(wrapper); 
     468      this.assertNotNullOrUndefined(wrapper.select('[id=myTD]')[0]); 
     469      this.assertNotNullOrUndefined(wrapper.select('td')[0]); 
     470      this.assertNotNullOrUndefined(wrapper.select('#myTD')[0]); 
    462471    } 
    463472  }); 
    464473