guardian / scribe

DEPRECATED: A rich text editor framework for the web platform

Home Page:http://guardian.github.io/scribe/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node.children is undefined?

mindplay-dk opened this issue · comments

In this function, did you really mean node or element?

Because Node objects do not have the children property - only Element objects have that.

We probably ought to have an extra function to check if a given node is an HTMLElement, and then use that to make an extra assertion before relying on children - something like:

    function isHTMLElement(node) {
        return node instanceof HTMLElement;
    }

    function isEmptyInlineElement(node) {
        if (isHTMLElement(node)) {
            if (node.children.length > 1) {
                return false;
            }
            if (node.children.length === 1 && node.textContent.trim() !== '') {
                return false;
            }
            if (node.children.length === 0) {
                return node.textContent.trim() === '';
            }
            return isEmptyInlineElement(node.children[0]);
        }
        return false;
    }

I agree with trying to implement the right check

@rrees adding labels appears to have unassigned you 😢 (that was not intentional)