Fix issue where a Selector query rooted on a node that had not been attached to the document failed in IE. [#464 state:resolved] (jddalton, kangax, Douglas Fraser, Andrew Dupont)

This commit is contained in:
Andrew Dupont 2009-02-22 15:59:01 -06:00
parent 8fe518719e
commit 432a9422d6
3 changed files with 34 additions and 2 deletions

View File

@ -1,3 +1,5 @@
* Fix issue where a Selector query rooted on a node that had not been attached to the document failed in IE. [#464 state:resolved] (jddalton, kangax, Douglas Fraser, Andrew Dupont)
* Fix Selector to match elements with attributes containing hyphens. [#285 state:resolved] (leiyou, jddalton, kangax)
* Make sure Form.reset always returns a reference to the receiver element. [#309 state:resolved] (Phil, kangax)

View File

@ -485,8 +485,23 @@ Object.extend(Selector, {
id: function(nodes, root, id, combinator) {
var targetNode = $(id), h = Selector.handlers;
if (!targetNode) return [];
if (!nodes && root == document) return [targetNode];
if (root == document) {
// We don't have to deal with orphan nodes. Easy.
if (!targetNode) return [];
if (!nodes) return [targetNode];
} else {
// In IE, we can check sourceIndex to see if root is attached
// to the document. If not (or if sourceIndex is not present),
// we do it the hard way.
if (!root.sourceIndex || root.sourceIndex < 1) {
var nodes = root.getElementsByTagName('*');
for (var j = 0, node; node = nodes[j]; j++) {
if (node.id === id) return [node];
}
}
}
if (nodes) {
if (combinator) {
if (combinator == 'child') {

View File

@ -371,6 +371,21 @@ new Test.Unit.Runner({
'div.is_counted'
);
},
testSelectorNotInsertedNodes: function() {
window.debug = true;
var wrapper = new Element("div");
wrapper.update("<table><tr><td id='myTD'></td></tr></table>");
this.assertNotNullOrUndefined(wrapper.select('[id=myTD]')[0],
'selecting: [id=myTD]');
this.assertNotNullOrUndefined(wrapper.select('#myTD')[0],
'selecting: #myTD');
this.assertNotNullOrUndefined(wrapper.select('td')[0],
'selecting: td');
this.assert($$('#myTD').length == 0,
'should not turn up in document-rooted search');
window.debug = false;
},
testElementDown: function() {
var a = $('dupL4');