Changeset 1302

Show
Ignore:
Timestamp:
07/18/07 13:31:16 (1 year ago)
Author:
therve@gmail.com
Message:

Apply Julien's patch, add a few tests.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mochikit/trunk/MochiKit/DOM.js

    r1263 r1302  
    371371            maybeparent = self.getElement(maybeparent); 
    372372        } 
    373         if (node === maybeparent) { 
    374             return true; 
    375         } 
    376         while (node && node.tagName.toUpperCase() != "BODY") { 
    377             node = node.parentNode; 
     373        if (typeof(node) == 'undefined' || node === null || node === self._document) { 
     374            return false; 
     375        } 
     376        do { 
    378377            if (node === maybeparent) { 
    379378                return true; 
    380379            } 
    381         } 
     380            var tagName = node.tagName; 
     381            node = node.parentNode; 
     382            if (!tagName) { 
     383                break; 
     384            } 
     385            tagName = tagName.toUpperCase(); 
     386        } while (tagName != "BODY" && tagName != "HTML"); 
    382387        return false; 
    383388    }, 
  • mochikit/trunk/tests/test_MochiKit-DOM.html

    r1247 r1302  
    293293    is( getFirstParentByTagAndClassName('child', '*', 'two'), getElement("parentTwo"), "getFirstParentByTagAndClassName found parent (any tag)" ); 
    294294 
     295    ok( isChildNode('child', 'parentZero'), "isChildNode direct child"); 
     296    ok( isChildNode('child', 'parentTwo'), "isChildNode sub child"); 
     297    ok( !isChildNode('child', 'form_test'), "isChildNode wrong child"); 
     298    ok( !isChildNode('child', 'donotexist'), "isChildNode no parent"); 
     299    ok( !isChildNode('donotexist', 'child'), "isChildNode no parent"); 
     300    ok( isChildNode('child', document.body), "isChildNode of body"); 
     301 
    295302    ok( true, "test suite finished!"); 
    296303