guardian / scribe

DEPRECATED: A rich text editor framework for the web platform
http://guardian.github.io/scribe/
Apache License 2.0
3.5k stars 245 forks source link

node.children is undefined? #462

Open mindplay-dk opened 8 years ago

mindplay-dk commented 8 years ago

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

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

mindplay-dk commented 8 years ago

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;
    }
rrees commented 8 years ago

I agree with trying to implement the right check

katebee commented 7 years ago

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