Skip to content

Improve getNode() so that is finds the correct node. #1447 #1459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions unpacked/jax/output/CommonHTML/jax.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,34 +336,29 @@
ucMatch: HTML.ucMatch,
setScript: HTML.setScript,

getNodesByClass: (document.getElementsByClassName ?
function (node,type) {return node.getElementsByClassName(type)} :
function (node,type) {
var NODES = [];
var nodes = node.getElementsByTagName("span");
//
// Look through the direct children of a node for one with the given
// type (but if the node has intervening containers for its children,
// 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) {
while (node && node.childNodes.length === 1 && node.firstChild.id == null)
node = node.firstChild;
if (node) {
var name = RegExp("\\b"+type+"\\b");
for (var i = 0, m = nodes.length; i < m; i++) {
if (name.test(nodes[i].className)) NODES.push = nodes[i];
for (var i = 0, m = node.childNodes.length; i < m; i++) {
var child = node.childNodes[i];
if (name.test(child.className)) return child;
}
return NODES;
}
),
getNode: function (node,type) {
var nodes = this.getNodesByClass(node,type);
if (nodes.length === 1) return nodes[0];
var closest = nodes[0], N = this.getNodeDepth(node,closest);
for (var i = 1, m = nodes.length; i < m; i++) {
var n = this.getNodeDepth(node,nodes[i]);
if (n < N) {closest = nodes[i]; N = n}
}
return closest;
return null;
},
getNodeDepth: function (parent,node) {
var n = 0;
while (node && node !== parent) {node = node.parentNode; n++}
return n;
},


/********************************************/

Expand Down