LeaVerou / bliss

Blissful JavaScript
http://blissfuljs.com
MIT License
2.39k stars 101 forks source link

TypeError: evt.target.closest is not a function #234

Open UweOhse opened 4 years ago

UweOhse commented 4 years ago

Bliss.delegate(document.body, "dragstart", "[draggable=true]", function(e) { /* nothing */ }); leads to the exception in the title if one drags a text, because a dragstart event runs, and is handled here:

delegate: overload(function (type, selector, callback) {
        $.bind(this, type, function(evt) {
            if (evt.target.closest(selector)) {
                callback.call(this, evt);
            }
        });
    }, 0, 2),

evt.target unfortunately is a text in this case, and has no closest() method.

A fix is simple: if (evt.target.closest && evt.target.closest(selector)) { (tested, works)

btw: bliss is great. thank you very much.

LeaVerou commented 4 years ago

Thanks for reporting! I've added it to my radar.

Actually, a better fix would be to use evt.parentNode.closest() in this case which is essentially what you need.