Make getNode() non-recursive and add comments for what it does. Issue #1447.

This commit is contained in:
Davide P. Cervone 2016-05-17 12:31:47 -04:00
parent 7116cde328
commit e1d430d1b3

View File

@ -337,20 +337,29 @@
setScript: HTML.setScript, setScript: HTML.setScript,
// //
// Look through the children of a node for one with the given type // Look through the direct children of a node for one with the given
// but don't step into child nodes that are from MathML elements // type (but if the node has intervening containers for its children,
// themselves (they will have IDs). // step into them; note that elements corresponding to MathML nodes
// will have id's so we don't step into them).
//
// This is used by munderover and msubsup to locate their child elements
// when they are part of an embellished operator that is being stretched.
// We don't use querySelector because we want to find only the direct child
// nodes, not nodes that might be nested deeper in the tree (see issue #1447).
// //
getNode: function (node,type) { getNode: function (node,type) {
var name = RegExp("\\b"+type+"\\b"); while (node && node.childNodes.length === 1 && node.firstChild.id == null)
for (var i = 0, m = node.childNodes.length; i < m; i++) { node = node.firstChild;
var child = node.childNodes[i]; if (node) {
if (name.test(child.className)) return child; var name = RegExp("\\b"+type+"\\b");
if (child.id == null) return this.getNode(child,type); for (var i = 0, m = node.childNodes.length; i < m; i++) {
var child = node.childNodes[i];
if (name.test(child.className)) return child;
}
} }
return null;
}, },
/********************************************/ /********************************************/
preTranslate: function (state) { preTranslate: function (state) {