Minor tweaks for ConversationPageState.isDescendantOf

Use uppercase since that is what the DOM for HTML defaults to, use
nodeName rather than tagName for cases when there the check is false and
ancestor is the document element, add unit tests.
This commit is contained in:
Michael Gratton 2019-01-21 20:55:03 +11:00 committed by Michael James Gratton
parent 44d871f6f1
commit c83f07a9f1
2 changed files with 48 additions and 5 deletions

View file

@ -82,7 +82,7 @@ ConversationPageState.prototype = {
// Only insert into a quote container if the element is a
// top level blockquote
if (!ConversationPageState.isDescendantOf(blockquote, "blockquote")) {
if (!ConversationPageState.isDescendantOf(blockquote, "BLOCKQUOTE")) {
let quoteHeight = blockquote.offsetHeight;
// Only make the quote it controllable if it is tall enough
@ -171,7 +171,7 @@ ConversationPageState.prototype = {
let div = possibleSigs.item(i);
let innerHTML = div.innerHTML;
if ((sigRegex.test(innerHTML) || alternateSigRegex.test(innerHTML)) &&
!ConversationPageState.isDescendantOf(div, "blockquote")) {
!ConversationPageState.isDescendantOf(div, "BLOCKQUOTE")) {
break;
}
}
@ -206,7 +206,7 @@ ConversationPageState.prototype = {
// so that new lines are preserved.
let dummy = document.createElement("DIV");
let includeDummy = false;
if (ConversationPageState.isDescendantOf(ancestor, "div", "plaintext")) {
if (ConversationPageState.isDescendantOf(ancestor, "DIV", "plaintext")) {
dummy.classList.add("plaintext");
dummy.setAttribute("style", "white-space: pre-wrap;");
includeDummy = true;
@ -324,14 +324,14 @@ ConversationPageState.isDeceptiveText = function(text, href) {
/**
* See if this element has an ancestor with the given tag and class.
*
* ancestorTag must be all lowercase.
* ancestorTag must be all uppercase.
*
* If ancestorClass is null, no class checking is done.
*/
ConversationPageState.isDescendantOf = function(node, ancestorTag, ancestorClass = null) {
let ancestor = node.parentNode;
while (ancestor != null) {
if (ancestor.tagName.toLowerCase() == ancestorTag) {
if (ancestor.nodeName.toUpperCase() == ancestorTag) {
if (!ancestorClass || ancestor.classList.contains(ancestorClass)) {
return true;
}