kornelski / slip

Slip.js — UI library for manipulating lists via swipe and drag gestures
BSD 2-Clause "Simplified" License
2.44k stars 213 forks source link

Problem with an Ember js object and Slip.js #67

Open zequeira opened 8 years ago

zequeira commented 8 years ago

Hi, very nice plugin btw. I'm using it on an Ember JS application for Drag & Drop dynamic div elements that reflects an Ember js object. I face the problem that when taking the first element on the list for putting it as the last element, then the element was duplicated. I found out that your function for "reorder":

list.addEventListener('slip:reorder', function(e) {
    // e.target list item reordered.
    if (reorderedOK) {
        e.target.parentNode.insertBefore(e.target, e.detail.insertBefore);
    } else {
        // element will fly back to original position
        e.preventDefault();
    }
});

when taking any element of the list to move it as last element, e.detail.insertBefore = null and it seems that insertBefore do not handle that situation properly, so I need it to implemented this way:

if (e.detail.insertBefore != null) {
     e.target.parentNode.insertBefore(e.target, e.detail.insertBefore);
} else {
     e.target.parentNode.insertBefore(e.target, e.target.nextSibling);
}

don't know if it's the best approach but I think you should take a look at what is happening when e.detail.insertBefore = null. Best ;)

kornelski commented 8 years ago

If I remember correctly I was assuming that insertBefore(…, null) is the same as appendChild(…)