Skip to content

how to: drag and drop #533

Answered by adam12
hpvd asked this question in Q&A
Discussion options

You must be logged in to vote

In 2017-2018, I paired Unpoly with Dragula. There wasn't a lot of complexity around it, and it was self-contained inside an Unpoly compiler. Here's the code snippet from that project.

var drak;

up.compiler('[pinnable]', function() {
  if (typeof drak !== "undefined" && typeof drak.destroy === "function") drak.destroy()

  var containers = $('[pinnable]').toArray();

  drak = dragula(containers, {
    copy: false,
    accepts: function(el, target) {
      return target.hasAttribute('pinnable-target');
    }
  });

  drak.on('drop', function(el) {
    var form = el.querySelector('form[name=pin]');

    $(form).trigger('submit');
  });

  return function() {
    drak.destroy();
  };
});

For…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by hpvd
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants