Bug 1596685 - fix gatherTextUnder() by reverting part of
bug 1570954. r+a=jorgk
Revert this: https://hg.mozilla.org/comm-central/rev/a128f9557e9d#l63.10
--- a/mail/base/content/utilityOverlay.js
+++ b/mail/base/content/utilityOverlay.js
@@ -65,49 +65,52 @@ function goCopyImage() {
}
// update Find As You Type menu items, they rely on focus
function goUpdateFindTypeMenuItems() {
goUpdateCommand("cmd_findTypeText");
goUpdateCommand("cmd_findTypeLinks");
}
-// Gather all descendent text under given document node.
+/**
+ * Gather all descendent text under given node.
+ * @param {Node} root - The root node to gather text from.
+ * @returns {string} The text data under the node.
+ */
function gatherTextUnder(root) {
var text = "";
- var node = root.firstElementChild;
+ var node = root.firstChild;
var depth = 1;
while (node && depth > 0) {
// See if this node is text.
if (node.nodeType == Node.TEXT_NODE) {
// Add this text to our collection.
text += " " + node.data;
} else if (node instanceof HTMLImageElement) {
// If it has an alt= attribute, add that.
var altText = node.getAttribute("alt");
if (altText && altText != "") {
text += " " + altText;
}
}
// Find next node to test.
- // First, see if this node has children.
- if (node.hasChildNodes()) {
- // Go to first child.
- node = node.firstElementChild;
+ if (node.firstChild) {
+ // If it has children, go to first child.
+ node = node.firstChild;
depth++;
- } else if (node.nextElementSibling) {
+ } else if (node.nextSibling) {
// No children, try next sibling.
- node = node.nextElementSibling;
+ node = node.nextSibling;
} else {
// Last resort is a sibling of an ancestor.
while (node && depth > 0) {
node = node.parentNode;
depth--;
- if (node.nextElementSibling) {
- node = node.nextElementSibling;
+ if (node.nextSibling) {
+ node = node.nextSibling;
break;
}
}
}
}
// Strip leading and trailing whitespace.
text = text.trim();
// Compress remaining whitespace.