Hi,
I think I spotted a bug (this time in
MochiKit.DOM.appendChildNodes.
The problem is that when an iterable is found in the node
stack, its
content is flattened at the end of the stack rather than
"in-place".
I see no reason why the current code would ever want to do
this.
Here are an example that exposes the bug and a patch for it.
Eric.
--------------------------------------------
--- DOM.js.orig Sat Feb 25 14:29:17 2006
+++ DOM.js Sat Feb 25 14:29:40 2006
 -439,7
+439,6 
elem
)
];
- var iextend = MochiKit.Iter.iextend;
while (nodeStack.length) {
var n = nodeStack.shift();
if (typeof(n) == 'undefined' || n == null) {
 -447,7
+446,7 
} else if (typeof(n.nodeType) == 'number') {
elem.appendChild(n);
} else {
- iextend(nodeStack, n);
+ nodeStack = MochiKit.Base.extend(list(n),
nodeStack);
}
}
return elem;
---------------------------------------------
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
a>">
<html xmlns="http://www.w3.org/1999/x
html">
<head>
<title>Test</title>
<script src="MochiKit.js"
type="text/javascript"></script>
</head>
<body>
<div id="foo"/>
</body>
<script type="text/javascript">
/* Uncomment to enable the fix.
MochiKit.DOM.appendChildNodes = function (node) {
var elem = node;
var self = MochiKit.DOM;
if (typeof(node) == 'string') {
elem = self.getElement(node);
}
var nodeStack = [
self.coerceToDOM(
MochiKit.Base.extend(null, arguments, 1),
elem
)
];
while (nodeStack.length) {
var n = nodeStack.shift();
if (typeof(n) == 'undefined' || n == null) {
// pass
} else if (typeof(n.nodeType) == 'number') {
elem.appendChild(n);
} else {
nodeStack = MochiKit.Base.extend(list(n), nodeStack);
}
}
return elem;
};
*/
makeLine = function(item) {
return TR(null, TD(null, "item ", item))
};
makeLines = function(items) {
return [ TR(null, TD(null, "items ",
repr(items))),
map(makeLine, items) ];
};
lines = [
[ 1, 2, 3 ],
[ 4, 5, 6 ],
[ 7, 8, 9 ] ];
swapDOM("foo", TABLE(null, TR(null, TH(null,
"Things")),
TBODY(null,
map(makeLines, lines))));
</script>
</html>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "MochiKit" group.
To post to this group, send email to mochikit googlegroups.com
To unsubscribe from this group, send email to
mochikit-unsubscribe googlegroups.com
For more options, visit this group at http://groups
.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---
|