Yapapaya / jquery-cloneya

A jquery plugin to clone DOM elements
MIT License
76 stars 28 forks source link

Handle jQuery event namespaces correctly #62

Closed paulschwarz closed 7 years ago

paulschwarz commented 7 years ago

CloneYa handles an event called clone.cloneya on the triggering element. jQuery fails to correctly handle the bubbling of namespaced events (see unresolved bug report https://bugs.jquery.com/ticket/6913 and see a simple illustration here http://jsfiddle.net/kZCBw/3/).

CloneYa subscribes to its own custom namespaced event here and due to the jQuery issue, if a third party triggers a clone event on the element, CloneYa will pick it up. You could trigger clone, clone.foo or anything else. CloneYa goes on to run _cloneAndAppend(toClone) which obviously, it shouldn't.

The workaround is to check that event.namespace === name, where name is a "cloneya" as defined on line 12.