diff --git a/4chan_x.user.js b/4chan_x.user.js index 49c1b7275..5e8b9ceb0 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -1511,14 +1511,20 @@ }; _Class.prototype.drop = function() { - var el, index, reply; + var el, index, newIndex, oldIndex, reply; el = $('.drag', this.parentNode); - index = function() { + index = function(el) { return Array.prototype.slice.call(el.parentNode.children).indexOf(el); }; - reply = qr.replies.splice(index(), 1)[0]; - $.before(this, el); - return qr.replies.splice(index(), 0, reply); + oldIndex = index(el); + newIndex = index(this); + if (oldIndex < newIndex) { + $.after(this, el); + } else { + $.before(this, el); + } + reply = qr.replies.splice(oldIndex, 1)[0]; + return qr.replies.splice(newIndex, 0, reply); }; _Class.prototype.dragEnd = function() { diff --git a/script.coffee b/script.coffee index fad2dd852..a81c6b325 100644 --- a/script.coffee +++ b/script.coffee @@ -1132,10 +1132,15 @@ qr = e.dataTransfer.dropEffect = 'move' drop: -> el = $ '.drag', @parentNode - index = -> Array::slice.call(el.parentNode.children).indexOf el - reply = qr.replies.splice(index(), 1)[0] - $.before @, el - qr.replies.splice index(), 0, reply + index = (el) -> Array::slice.call(el.parentNode.children).indexOf el + oldIndex = index el + newIndex = index @ + if oldIndex < newIndex + $.after @, el + else + $.before @, el + reply = qr.replies.splice(oldIndex, 1)[0] + qr.replies.splice newIndex, 0, reply dragEnd: -> $.removeClass @, 'drag' $.removeClass $('.over', @parentNode), 'over'