eriklieben / aurelia-interactjs

Plugin to use interact.js with Aurelia http://interactjs.io/ Inspired by a blog post from Matthew James Davis http://davismj.me/blog/aurelia-drag-and-drop/
MIT License
13 stars 7 forks source link

Adding interact-draggable etc attributes to dom element via the templatingEngine doesn't work as attached() isn't called #4

Closed jfstephe closed 7 years ago

jfstephe commented 7 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: Adding the interact attributes to an existing dom element and calling templatingEngine.enhance() means that attached() isn't called and so the necessary interactjs code in the plugin isn't run.

Background: I'm trying to implement row drag+drop behaviour in my app for the grid in the https://github.com/ceolter/ag-grid-aurelia project. It doesn't support it by default so I have to add a cell renderer in my gridWrapper component which looks like:

this.columnDefinitions = [
  {
    headerName: 'dragger', width: 200, field: undefined, children: undefined, cellRenderer: function() {
      var span = document.createElement('span');
      span.setAttribute('interact-dropzone', '');
      span.setAttribute('interact-draggable', '');
      span.setAttribute('interact-dragend.delegate', 'dragEnd($event)');
      span.setAttribute('style', 'border:solid 2px red; margin:5px; padding:5px');
      templatingEngine.enhance({element: span, bindingContext: vm});
      return span;
    }
.......
];

I have limited control over the grid itself, but after debugging this, and after a lot of trial and error, I can get it working if I move the code that is in interact-draggable.js from attached() to bind().

Expected/desired behavior: As described above

jfstephe commented 7 years ago

Friendly poke :-). I've raised a related PR (#5) for you to look at please.