From 02c94fb4a772843e33bf05e04348a86723b1de37 Mon Sep 17 00:00:00 2001 From: Goran Radulovic Date: Thu, 17 Apr 2014 12:47:17 +0200 Subject: [PATCH 1/6] sort update now also passes the indexes from and to from which the elements have changed the position --- .gitignore | 1 + jquery.sortable.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/jquery.sortable.js b/jquery.sortable.js index 350d172..3851a65 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -49,7 +49,11 @@ $.fn.sortable = function(options) { dragging.removeClass('sortable-dragging').show(); placeholders.detach(); if (index != dragging.index()) { - dragging.parent().trigger('sortupdate', {item: dragging}); + dragging.parent().trigger('sortupdate', { + item : dragging, + from : index, + to : dragging.index() + }); } dragging = null; }).not('a[href], img').on('selectstart.h5s', function() { From 91b7e4cb9be224d489417594ff2365a119e96fc5 Mon Sep 17 00:00:00 2001 From: Goran Radulovic Date: Thu, 17 Apr 2014 12:52:39 +0200 Subject: [PATCH 2/6] updated documentation --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a3d888f..973da57 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ HTML5 Sortable jQuery Plugin ============================ +Changes From the Original Version +-------- +* `sortupdate` event now provides `from` and `to` indexes of dragged item + **[Demos & Documentation](http://farhadi.ir/projects/html5sortable)** Features From 127facf2ddaee92820c055b49ca8badeab786537 Mon Sep 17 00:00:00 2001 From: Goran Radulovic Date: Thu, 17 Apr 2014 12:54:33 +0200 Subject: [PATCH 3/6] updated documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 973da57..fe8d0bc 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ HTML5 Sortable jQuery Plugin ============================ +**[Demos & Documentation](http://farhadi.ir/projects/html5sortable)** + Changes From the Original Version -------- * `sortupdate` event now provides `from` and `to` indexes of dragged item -**[Demos & Documentation](http://farhadi.ir/projects/html5sortable)** - Features -------- * Less than 1KB (minified and gzipped). From 1a5bc96cb5e2cb3d0e117e6f15600fe475be9a55 Mon Sep 17 00:00:00 2001 From: Goran Radulovic Date: Fri, 18 Apr 2014 01:10:15 +0200 Subject: [PATCH 4/6] when forcing placeholder size, do it only once, not every time dragging events are triggered --- jquery.sortable.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/jquery.sortable.js b/jquery.sortable.js index 3851a65..fe0e224 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -64,6 +64,9 @@ $.fn.sortable = function(options) { return true; } if (e.type == 'drop') { + if (options.forcePlaceholderSize) { + placeholder.removeClass('forcedPlaceholderSize'); + } // if e.stopPropagation(); placeholders.filter(':visible').after(dragging); dragging.trigger('dragend.h5s'); @@ -72,9 +75,10 @@ $.fn.sortable = function(options) { e.preventDefault(); e.originalEvent.dataTransfer.dropEffect = 'move'; if (items.is(this)) { - if (options.forcePlaceholderSize) { - placeholder.height(dragging.outerHeight()); - } + if (options.forcePlaceholderSize && !placeholder.is('.forcedPlaceholderSize')) { + placeholder.addClass('forcedPlaceholderSize'); + placeholder.height(dragging.outerHeight()); + } dragging.hide(); $(this)[placeholder.index() < $(this).index() ? 'after' : 'before'](placeholder); placeholders.not(placeholder).detach(); From b2421b43ebbb837c5dc3166abb2f8125ef671a9a Mon Sep 17 00:00:00 2001 From: Goran Radulovic Date: Sat, 19 Apr 2014 11:32:44 +0200 Subject: [PATCH 5/6] sort update event should trigger even if we're dragging item to new list --- jquery.sortable.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/jquery.sortable.js b/jquery.sortable.js index fe0e224..4a95094 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,18 +42,15 @@ $.fn.sortable = function(options) { dt.effectAllowed = 'move'; dt.setData('Text', 'dummy'); index = (dragging = $(this)).addClass('sortable-dragging').index(); - }).on('dragend.h5s', function() { + parent = dragging.parent()[0]; + }).on('dragend.h5s', function() { if (!dragging) { return; } dragging.removeClass('sortable-dragging').show(); placeholders.detach(); - if (index != dragging.index()) { - dragging.parent().trigger('sortupdate', { - item : dragging, - from : index, - to : dragging.index() - }); + if (index != dragging.index() || dragging.parent()[0] != parent) { + dragging.parent().trigger('sortupdate', { item : dragging, from : index, to : dragging.index() }); } dragging = null; }).not('a[href], img').on('selectstart.h5s', function() { From 76fb628f493a0e4d3825f8b80a780c20ec65fe0b Mon Sep 17 00:00:00 2001 From: Goran Radulovic Date: Thu, 25 Dec 2014 22:58:17 +0100 Subject: [PATCH 6/6] don't prevent selecting text in input --- jquery.sortable.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/jquery.sortable.js b/jquery.sortable.js index 4a95094..138e57b 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -53,9 +53,15 @@ $.fn.sortable = function(options) { dragging.parent().trigger('sortupdate', { item : dragging, from : index, to : dragging.index() }); } dragging = null; - }).not('a[href], img').on('selectstart.h5s', function() { - this.dragDrop && this.dragDrop(); - return false; + }).not('a[href], img').on('selectstart.h5s', function(event) { + // if event originates from input field, let it be + if ($(event.target).is('input, textarea, select')) { + return true; + } else { + this.dragDrop && this.dragDrop(); + return false; + } + }).end().add([this, placeholder]).on('dragover.h5s dragenter.h5s drop.h5s', function(e) { if (!items.is(dragging) && options.connectWith !== $(dragging).parent().data('connectWith')) { return true;