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() { _Class.prototype.drop = function() {
var el, index, reply; var el, index, newIndex, oldIndex, reply;
el = $('.drag', this.parentNode); el = $('.drag', this.parentNode);
index = function() { index = function(el) {
return Array.prototype.slice.call(el.parentNode.children).indexOf(el); return Array.prototype.slice.call(el.parentNode.children).indexOf(el);
}; };
reply = qr.replies.splice(index(), 1)[0]; oldIndex = index(el);
$.before(this, el); newIndex = index(this);
return qr.replies.splice(index(), 0, reply); 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() { _Class.prototype.dragEnd = function() {

View File

@ -1132,10 +1132,15 @@ qr =
e.dataTransfer.dropEffect = 'move' e.dataTransfer.dropEffect = 'move'
drop: -> drop: ->
el = $ '.drag', @parentNode el = $ '.drag', @parentNode
index = -> Array::slice.call(el.parentNode.children).indexOf el index = (el) -> Array::slice.call(el.parentNode.children).indexOf el
reply = qr.replies.splice(index(), 1)[0] oldIndex = index el
$.before @, el newIndex = index @
qr.replies.splice index(), 0, reply if oldIndex < newIndex
$.after @, el
else
$.before @, el
reply = qr.replies.splice(oldIndex, 1)[0]
qr.replies.splice newIndex, 0, reply
dragEnd: -> dragEnd: ->
$.removeClass @, 'drag' $.removeClass @, 'drag'
$.removeClass $('.over', @parentNode), 'over' $.removeClass $('.over', @parentNode), 'over'