Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
patch for ticket 304
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
simon.cusack@gmail.com  
View profile  
 More options May 4 2008, 10:14 pm
From: "simon.cus...@gmail.com" <simon.cus...@gmail.com>
Date: Sun, 4 May 2008 19:14:49 -0700 (PDT)
Local: Sun, May 4 2008 10:14 pm
Subject: patch for ticket 304
Hi,

tried to add this patch to the trac ticket that I raised but couldn't,
so it is here instead.  Sorry if I didn't follow the correct protocol;

8<----

Refactored isChildNode to use MochiKit.Base predicates.

Changed logic in tests to guard against cases when the child or parent
node is not part of the DOM.

Added extra tests to test suite, verified working on FF2, IE7.

diff -r 8d983df7eccc MochiKit/DOM.js
--- a/MochiKit/DOM.js   Wed Apr 30 17:16:32 2008 +1000
+++ b/MochiKit/DOM.js   Mon May 05 11:48:42 2008 +1000
@@ -352,20 +352,25 @@
     /** @id MochiKit.DOM.isChildNode */
     isChildNode: function (node, maybeparent) {
         var self = MochiKit.DOM;
-        if (typeof(node) == "string") {
-            node = self.getElement(node);
-        }
-        if (typeof(maybeparent) == "string") {
-            maybeparent = self.getElement(maybeparent);
-        }
-        if (typeof(node) == 'undefined' || node === null) {
-            return false;
-        }
-        while (node !== self._document) {
+        // ensure we are dealing with DOM elements not IDs
+        node        = self.getElement(node);
+        maybeparent = self.getElement(maybeparent);
+        var tagName = null;
+
+        if (node && maybeparent && (node !== self._document)) {
+          while (node) {
             if (node === maybeparent) {
-                return true;
+              return true;
             }
+
+            // not all nodes have tagNames, eg text nodes.
+            tagName = node.tagName && node.tagName.toUpperCase();
+            if ((tagName === "BODY") || (tagName === "HTML")) {
+              break;
+            }
+
             node = node.parentNode;
+          }
         }
         return false;
     },
diff -r 8d983df7eccc tests/test_MochiKit-DOM.html
--- a/tests/test_MochiKit-DOM.html      Wed Apr 30 17:16:32 2008 +1000
+++ b/tests/test_MochiKit-DOM.html      Mon May 05 11:48:42 2008 +1000
@@ -4,8 +4,8 @@
     <script type="text/javascript" src="../MochiKit/Base.js"></
script>
     <script type="text/javascript" src="../MochiKit/Iter.js"></
script>
     <script type="text/javascript" src="../MochiKit/DOM.js"></script>
-    <script type="text/javascript" src="../MochiKit/Style.js"></
script>
-    <script type="text/javascript" src="SimpleTest/SimpleTest.js"></
script>
+    <script type="text/javascript" src="../MochiKit/Style.js"></
script>
+    <script type="text/javascript" src="SimpleTest/SimpleTest.js"></
script>
     <link rel="stylesheet" type="text/css" href="SimpleTest/
test.css">
 </head>
 <body>
@@ -69,8 +69,8 @@
     is( lst.join(" "), "original new", "callStack in correct order
(abort)" );
     o.blah();
     is( lst.join(" "), "original new original new", "callStack in
correct order (again)" );
-
-
+
+
     is( escapeHTML("<>\"&bar"), "&lt;&gt;&quot;&amp;bar",
"escapeHTML" ); // for emacs highlighting: "

     var isDOM = function (value, expected, message) {
@@ -93,7 +93,7 @@
     isDOM( d, '<span>word up<span/>Think Different</span>',
'insertSiblingNodesBefore' );

     insertSiblingNodesAfter(d.childNodes[0], 'purple monkey',
document.createElement('span'));
-    isDOM( d, '<span>word uppurple monkey<span/><span/>Think
Different</span>', 'insertSiblingNodesAfter' );
+    isDOM( d, '<span>word uppurple monkey<span/><span/>Think
Different</span>', 'insertSiblingNodesAfter' );

     d = createDOM("span");
     isDOM( d, "<span/>", "createDOM empty" );
@@ -107,7 +107,7 @@
     is( getNodeAttribute(d, 'baz'), "wibble", "createDOM
attribute" );
     removeNodeAttribute(d, "spam");
     is( scrapeText(d), "onetwothree", "createDOM contents" );
-
+
     isDOM( d, '<span baz="wibble" foo="bar">onetwothree</span>',
"createDOM contents" );

     d = createDOM("span", null, function (f) {
@@ -136,7 +136,7 @@
     domConverters.unregister("taco");

     isDOM( d, "<span>Goddamn, I like pork tacos</span>", "createDOM
with custom converter" );
-
+
     is(
         escapeHTML(toHTML(SPAN(null))),
         escapeHTML(toHTML(createDOM("span", null))),
@@ -148,8 +148,8 @@

     var st = DIV(null, STRONG(null, "d"), "oor ", STRONG(null, "f",
SPAN(null, "r"), "a"), "me");
     is( scrapeText(st), "door frame", "scrape in-order" );
-
-
+
+
     ok( !isUndefinedOrNull(getElement("test")), "getElement might
work" );
     ok( !isUndefinedOrNull($("test")), "$alias$$ CASH MONEY alias
might work" );

@@ -171,10 +171,10 @@
     toggleElementClass("bar", d);
     ok( d.className == "baz", "toggleElementClass: " + d.className);
     toggleElementClass("bar", d);
-    ok( hasElementClass(d, "baz", "bar"),
+    ok( hasElementClass(d, "baz", "bar"),
         "toggleElementClass 2: " + d.className);
     addElementClass(d, "bar");
-    ok( hasElementClass(d, "baz", "bar"),
+    ok( hasElementClass(d, "baz", "bar"),
         "toggleElementClass 3: " + d.className);
     ok( addElementClass(d, "blah"), "addElementClass return");
     ok( hasElementClass(d, "baz", "bar", "blah"), "addElementClass
action");
@@ -221,7 +221,7 @@
         "tr0 tr1",
         "getElementsByTagAndClassName found all tr tags"
     );
-
+
     var oldDoc = document;
     var doc = MochiKit.MockDOM.createDocument();
     is( currentDocument(), document, "currentDocument() correct" );
@@ -282,7 +282,7 @@
     is( kv[0].join(","), "selempty,selempty2", "formContents names
empty option values" );
     is( kv[1].join(","), ",foo", "formContents empty option
values" );
     is( queryString("form_test2"), "selempty=&selempty2=foo",
"queryString empty option values" );
-
+
     var d = DIV(null, SPAN(), " \n\t", SPAN(), "foo", SPAN(), " ");
     is( d.childNodes.length, 6, "removeEmptyNodes test conditions
correct" );
     removeEmptyTextNodes(d);
@@ -302,11 +302,14 @@
     ok( isChildNode('child', document.body), "isChildNode of body");
     ok( isChildNode($('child').firstChild, 'parentTwo'), "isChildNode
text node");

+    ok( !isChildNode( SPAN(), document.body), "isChildNode child not
in DOM");
+    ok( !isChildNode( SPAN(), 'child'),       "isChildNode child not
in DOM");
+
+    ok( !isChildNode( 'child', SPAN()),       "isChildNode parent not
in DOM");
+
     ok( true, "test suite finished!");
-
-
 } catch (err) {
-
+
     var s = "test suite failure!\n";
     var o = {};
     var k = null;


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Per Cederberg  
View profile  
 More options May 6 2008, 4:25 am
From: "Per Cederberg" <cederb...@gmail.com>
Date: Tue, 6 May 2008 10:25:20 +0200
Local: Tues, May 6 2008 4:25 am
Subject: Re: [mochikit] patch for ticket 304
Thanks for the patch! The relevant changes have been made, so things
should work properly in svn again.

/Per

On Mon, May 5, 2008 at 4:14 AM, simon.cus...@gmail.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google