From 2cce20f255daebeeb2ccad58edcbbe40a09c961f Mon Sep 17 00:00:00 2001 From: Dusty Kline Date: Thu, 29 Jan 2015 15:07:11 -0600 Subject: [PATCH] Fix bug where sortupdate was not fired when using 'connectWith' option and the index() of the dragged element is the same, but the parent() is not (drag from idx#0 of ul#1 to idx#0 of ul#2). --- jquery.sortable.js | 5 +++-- jquery.sortable.min.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/jquery.sortable.js b/jquery.sortable.js index 2ebca6f..af0f853 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -21,7 +21,7 @@ $.fn.sortable = function(options) { } return; } - var isHandle, index, items = $(this).children(options.items); + var isHandle, index, parent, items = $(this).children(options.items); var placeholder = $('<' + (/^(ul|ol)$/i.test(this.tagName) ? 'li' : 'div') + ' class="sortable-placeholder">'); items.find(options.handle).mousedown(function() { isHandle = true; @@ -42,13 +42,14 @@ $.fn.sortable = function(options) { dt.effectAllowed = 'move'; dt.setData('Text', 'dummy'); index = (dragging = $(this)).addClass('sortable-dragging').index(); + parent = dragging.parent(); }).on('dragend.h5s', function() { if (!dragging) { return; } dragging.removeClass('sortable-dragging').show(); placeholders.detach(); - if (index != dragging.index()) { + if (index != dragging.index() || !parent.is(dragging.parent())) { dragging.parent().trigger('sortupdate', {item: dragging}); } dragging = null; diff --git a/jquery.sortable.min.js b/jquery.sortable.min.js index 7e90810..89b3a13 100644 --- a/jquery.sortable.min.js +++ b/jquery.sortable.min.js @@ -5,4 +5,4 @@ * Copyright 2012, Ali Farhadi * Released under the MIT license. */ -(function(e){var t,n=e();e.fn.sortable=function(r){var i=String(r);r=e.extend({connectWith:false},r);return this.each(function(){if(/^enable|disable|destroy$/.test(i)){var s=e(this).children(e(this).data("items")).attr("draggable",i=="enable");if(i=="destroy"){s.add(this).removeData("connectWith items").off("dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s")}return}var o,u,s=e(this).children(r.items);var a=e("<"+(/^ul|ol$/i.test(this.tagName)?"li":"div")+' class="sortable-placeholder">');s.find(r.handle).mousedown(function(){o=true}).mouseup(function(){o=false});e(this).data("items",r.items);n=n.add(a);if(r.connectWith){e(r.connectWith).add(this).data("connectWith",r.connectWith)}s.attr("draggable","true").on("dragstart.h5s",function(n){if(r.handle&&!o){return false}o=false;var i=n.originalEvent.dataTransfer;i.effectAllowed="move";i.setData("Text","dummy");u=(t=e(this)).addClass("sortable-dragging").index()}).on("dragend.h5s",function(){if(!t){return}t.removeClass("sortable-dragging").show();n.detach();if(u!=t.index()){t.parent().trigger("sortupdate",{item:t})}t=null}).not("a[href], img").on("selectstart.h5s",function(){this.dragDrop&&this.dragDrop();return false}).end().add([this,a]).on("dragover.h5s dragenter.h5s drop.h5s",function(i){if(!s.is(t)&&r.connectWith!==e(t).parent().data("connectWith")){return true}if(i.type=="drop"){i.stopPropagation();n.filter(":visible").after(t);t.trigger("dragend.h5s");return false}i.preventDefault();i.originalEvent.dataTransfer.dropEffect="move";if(s.is(this)){if(r.forcePlaceholderSize){a.height(t.outerHeight())}t.hide();e(this)[a.index()');s.find(r.handle).mousedown(function(){o=true}).mouseup(function(){o=false});e(this).data("items",r.items);n=n.add(f);if(r.connectWith){e(r.connectWith).add(this).data("connectWith",r.connectWith)}s.attr("draggable","true").on("dragstart.h5s",function(n){if(r.handle&&!o){return false}o=false;var i=n.originalEvent.dataTransfer;i.effectAllowed="move";i.setData("Text","dummy");u=(t=e(this)).addClass("sortable-dragging").index();a=t.parent()}).on("dragend.h5s",function(){if(!t){return}t.removeClass("sortable-dragging").show();n.detach();if(u!=t.index()||!a.is(t.parent())){t.parent().trigger("sortupdate",{item:t})}t=null}).not("a[href], img").on("selectstart.h5s",function(){this.dragDrop&&this.dragDrop();return false}).end().add([this,f]).on("dragover.h5s dragenter.h5s drop.h5s",function(i){if(!s.is(t)&&r.connectWith!==e(t).parent().data("connectWith")){return true}if(i.type=="drop"){i.stopPropagation();n.filter(":visible").after(t);t.trigger("dragend.h5s");return false}i.preventDefault();i.originalEvent.dataTransfer.dropEffect="move";if(s.is(this)){if(r.forcePlaceholderSize){f.height(t.outerHeight())}t.hide();e(this)[f.index()