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

Ticket #10413: descendantOf.patch

File descendantOf.patch, 0.9 kB (added by kamil.szot, 1 year ago)

patch for correct determining if element is descendantOf another element even if element is generated dynamically, or ancestor following tested ancestor is generated dynamically so they don't have sourceIndex set

  • src/dom.js

    old new  
    364364    if (element.compareDocumentPosition) 
    365365      return (element.compareDocumentPosition(ancestor) & 8) === 8; 
    366366       
    367     if (element.sourceIndex && !Prototype.Browser.Opera) { 
     367    if (element.sourceIndex && ancestor.sourceIndex && !Prototype.Browser.Opera) { 
    368368      var e = element.sourceIndex, a = ancestor.sourceIndex, 
    369369       nextAncestor = ancestor.nextSibling; 
    370370      if (!nextAncestor) { 
    371371        do { ancestor = ancestor.parentNode; } 
    372372        while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode); 
    373373      } 
    374       if (nextAncestor) return (e > a && e < nextAncestor.sourceIndex);       
     374      if (nextAncestor && nextAncestor.sourceIndex) return (e > a && e < nextAncestor.sourceIndex);       
    375375    } 
    376376     
    377377    while (element = element.parentNode)