mauricius / vue-draggable-resizable

Vue3 Component for draggable and resizable elements.
https://mauricius.github.io/vue-draggable-resizable/
MIT License
3.33k stars 559 forks source link

WTF is this? #280

Open CarterLi opened 3 years ago

CarterLi commented 3 years ago
addEvent(document.documentElement, 'touchend touchcancel', this.deselect)
removeEvent(document.documentElement, 'touchend touchcancel', this.deselect)

https://github.com/mauricius/vue-draggable-resizable/blob/cb43b89da98f733dc2637668e9f9cdbf5dc2bc82/src/components/vue-draggable-resizable.vue#L302

mauricius commented 3 years ago

magic

CarterLi commented 3 years ago

Why was it closed?

addEvent is implemented as

export function addEvent (el, event, handler) {
  if (!el) {
    return
  }
  if (el.attachEvent) {
    el.attachEvent('on' + event, handler)
  } else if (el.addEventListener) {
    el.addEventListener(event, handler, true)
  } else {
    el['on' + event] = handler
  }
}

https://github.com/mauricius/vue-draggable-resizable/blob/cb43b89da98f733dc2637668e9f9cdbf5dc2bc82/src/utils/dom.js#L34

for addEvent(document.documentElement, 'touchend touchcancel', this.deselect), you got

document.documentElement.attachEvent('ontouchend touchcancel', this.deselect)
document.documentElement.addEventListener('touchend touchcancel', this.deselect, true)
document.documentElement['ontouchend touchcancel'] = this.deselect

This was rediculous. addEventListener does NEVER support such a usage. If you do that, you end up adding a event listener named touchend touchcancel which is NOT touchend nor touchcancel and none of touchend and touchcancel will be fired

Open your F12, input document.documentElement.addEventListener('mousemove mousedown', console.log) and try it yourself

image

Note: jQuery.on does support space-separated event types. But addEventListener is not JQuery

CarterLi commented 3 years ago

In addition, you seem try to support IE8

el.attachEvent('on' + event, handler)

But Vue ( including Vue 2 ) does NOT support IE8. Therefore the code is useless.

mauricius commented 3 years ago

Well, it wasn't so hard to explain what you meant with that first comment, wasn't it? Why didn't you do that in the first place?

CarterLi commented 3 years ago

MAGIC