Adjust behavior when dropping left to right or right to left.

This commit is contained in:
Nicolas Stepien 2012-02-11 21:13:47 +01:00
parent 272fb0e66e
commit 18cbff6b3d
2 changed files with 20 additions and 9 deletions

View File

@ -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() {

View File

@ -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'