Greatly simplify IE's implementation of Element#descendantOf.

This commit is contained in:
Andrew Dupont 2008-03-30 20:07:47 -05:00
parent b03d4d40a0
commit a3f7b712c3
2 changed files with 6 additions and 12 deletions

View File

@ -1,3 +1,5 @@
* Greatly simplify IE's implementation of Element#descendantOf.
* Prevent exception when using Selector to search for an attribute that is not present. [gryn, Andrew Dupont]
* Fix issues where Firefox improperly returns the wrong node from a call to Event.element. Also fixes possible exception in Event.element in IE. [jdalton, Andrew Dupont]

View File

@ -363,24 +363,16 @@ Element.Methods = {
descendantOf: function(element, ancestor) {
element = $(element), ancestor = $(ancestor);
var originalAncestor = ancestor;
if (element.compareDocumentPosition)
return (element.compareDocumentPosition(ancestor) & 8) === 8;
if (element.sourceIndex && !Prototype.Browser.Opera) {
var e = element.sourceIndex, a = ancestor.sourceIndex,
nextAncestor = ancestor.nextSibling;
if (!nextAncestor) {
do { ancestor = ancestor.parentNode; }
while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode);
}
if (nextAncestor && nextAncestor.sourceIndex)
return (e > a && e < nextAncestor.sourceIndex);
}
if (ancestor.contains)
return ancestor.contains(element);
while (element = element.parentNode)
if (element == originalAncestor) return true;
if (element == ancestor) return true;
return false;
},