reppners / ngx-drag-drop

Angular directives using the native HTML Drag And Drop API
https://reppners.github.io/ngx-drag-drop/
BSD 3-Clause "New" or "Revised" License
300 stars 119 forks source link

remove(); not supported by IE #6

Closed brayunm closed 6 years ago

brayunm commented 6 years ago

Hi,

I've noticed that the remove() method is not supported by IE in version 1.0.0. This is used to hide the placeholder when there's no dragging going on.

https://stackoverflow.com/questions/20428877/javascript-remove-doesnt-work-in-ie As stated in the above stackoverflow I was able to fix this in IE11 by declaring the remove method myself. I'm not sure about older versions though.

Is there any chance this fix (or another one) can be included in a new version?

reppners commented 6 years ago

Thanks for reporting! Didn't know about missing support of remove() in IE.

I'm leaning to point people towards applying a polyfill when IE support is needed: https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove

// from:https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/remove()/remove().md
(function (arr) {
  arr.forEach(function (item) {
    if (item.hasOwnProperty('remove')) {
      return;
    }
    Object.defineProperty(item, 'remove', {
      configurable: true,
      enumerable: true,
      writable: true,
      value: function remove() {
        if (this.parentNode !== null)
          this.parentNode.removeChild(this);
      }
    });
  });
})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);

The reason being I want to keep the code clean and not include workarounds needed for a single browser that in the future will become obsolete because it's not evergreen.

On the other hand using remove() is a code smell because its directly operating on the DOM. I'm thinking about refactoring the placeholder to <ng-template> if possible.

brayunm commented 6 years ago

Thanks for the quick response.

I've implemented the polyfill you've suggested and its working as expected.

reppners commented 6 years ago

Will close this one because workaround/polyfill is available and there are issues that prevent using ng-template when nesting drop zones.