From e2b95ea8c9d1e3509fa7c91da72ed5c3eb55a5a0 Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Thu, 23 Apr 2015 17:06:34 +0200 Subject: [PATCH 01/13] test --- jquery.sortable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.sortable.js b/jquery.sortable.js index 2ebca6f..5633200 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -7,7 +7,7 @@ */ (function($) { var dragging, placeholders = $(); -$.fn.sortable = function(options) { +$.fn.html5sortable = function(options) { var method = String(options); options = $.extend({ connectWith: false @@ -61,7 +61,7 @@ $.fn.sortable = function(options) { } if (e.type == 'drop') { e.stopPropagation(); - placeholders.filter(':visible').after(dragging); + placeholders.filter(':visible').after(dragging.clone()); dragging.trigger('dragend.h5s'); return false; } From a372343164d36f6ee21be1a26ac6b33053dd9fea Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Thu, 23 Apr 2015 17:06:49 +0200 Subject: [PATCH 02/13] test --- jquery.sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.sortable.js b/jquery.sortable.js index 5633200..0ba9040 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -61,7 +61,7 @@ $.fn.html5sortable = function(options) { } if (e.type == 'drop') { e.stopPropagation(); - placeholders.filter(':visible').after(dragging.clone()); + placeholders.filter(':visible').after(dragging.clone(true)); dragging.trigger('dragend.h5s'); return false; } From ff28e8214435bec16378cc5ecc9499e4c82932ca Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Thu, 23 Apr 2015 17:31:38 +0200 Subject: [PATCH 03/13] test --- jquery.sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.sortable.js b/jquery.sortable.js index 0ba9040..5a26ad6 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -61,7 +61,7 @@ $.fn.html5sortable = function(options) { } if (e.type == 'drop') { e.stopPropagation(); - placeholders.filter(':visible').after(dragging.clone(true)); + dragging.clone(true).insertAfter(placeholders.filter(':visible')); dragging.trigger('dragend.h5s'); return false; } From 96ec9beed33d6076ca978d38b973520f2b87eac8 Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Thu, 23 Apr 2015 17:36:45 +0200 Subject: [PATCH 04/13] version --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 39fc86c..cc09b39 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "html5sortable", - "version": "0.0.1", + "version": "0.0.2", "homepage": "http://farhadi.ir/projects/html5sortable/", "authors": [ "Ali Farhadi " From 572f752b12505fb57e68e8aff8613bb19863b4f9 Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Thu, 23 Apr 2015 17:40:58 +0200 Subject: [PATCH 05/13] test --- bower.json | 2 +- jquery.sortable.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index cc09b39..f013d52 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "html5sortable", - "version": "0.0.2", + "version": "0.0.3", "homepage": "http://farhadi.ir/projects/html5sortable/", "authors": [ "Ali Farhadi " diff --git a/jquery.sortable.js b/jquery.sortable.js index 5a26ad6..fab60ce 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -61,7 +61,8 @@ $.fn.html5sortable = function(options) { } if (e.type == 'drop') { e.stopPropagation(); - dragging.clone(true).insertAfter(placeholders.filter(':visible')); + dragging = dragging.clone(true) + dragging.insertAfter(placeholders.filter(':visible')); dragging.trigger('dragend.h5s'); return false; } From a36b7124170c26b9385fb1e1060b586243a15d91 Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Thu, 23 Apr 2015 19:12:27 +0200 Subject: [PATCH 06/13] test --- jquery.sortable.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/jquery.sortable.js b/jquery.sortable.js index fab60ce..1e4d270 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -12,6 +12,7 @@ $.fn.html5sortable = function(options) { options = $.extend({ connectWith: false }, options); + var self = this; return this.each(function() { if (/^(enable|disable|destroy)$/.test(method)) { var items = $(this).children($(this).data('items')).attr('draggable', method == 'enable'); @@ -39,7 +40,7 @@ $.fn.html5sortable = function(options) { } isHandle = false; var dt = e.originalEvent.dataTransfer; - dt.effectAllowed = 'move'; + dt.effectAllowed = 'copy'; dt.setData('Text', 'dummy'); index = (dragging = $(this)).addClass('sortable-dragging').index(); }).on('dragend.h5s', function() { @@ -48,9 +49,7 @@ $.fn.html5sortable = 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}); dragging = null; }).not('a[href], img').on('selectstart.h5s', function() { this.dragDrop && this.dragDrop(); @@ -59,20 +58,35 @@ $.fn.html5sortable = function(options) { if (!items.is(dragging) && options.connectWith !== $(dragging).parent().data('connectWith')) { return true; } + + var targets = dragging.attr('data-targets'); + if(targets && targets.split(',').indexOf(self.attr('data-key')) === -1) { + return true; + } + if (e.type == 'drop') { e.stopPropagation(); + + if(dragging.parent().is(placeholders.filter(':visible').parent())) { + dragging.detach(); + } else { + dragging.removeClass('sortable-dragging').show(); + } + dragging = dragging.clone(true) dragging.insertAfter(placeholders.filter(':visible')); dragging.trigger('dragend.h5s'); return false; } e.preventDefault(); - e.originalEvent.dataTransfer.dropEffect = 'move'; + e.originalEvent.dataTransfer.dropEffect = 'copy'; if (items.is(this)) { if (options.forcePlaceholderSize) { placeholder.height(dragging.outerHeight()); } - dragging.hide(); + if(!targets || targets.split(',').indexOf(dragging.parent().attr('data-key')) !== -1) { + dragging.hide(); + } $(this)[placeholder.index() < $(this).index() ? 'after' : 'before'](placeholder); placeholders.not(placeholder).detach(); } else if (!placeholders.is(this) && !$(this).children(options.items).length) { From c56247d790c8f108e13e9d9b4a46c2a3d082e8cf Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Thu, 23 Apr 2015 19:12:50 +0200 Subject: [PATCH 07/13] test --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index f013d52..c929085 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "html5sortable", - "version": "0.0.3", + "version": "0.0.4", "homepage": "http://farhadi.ir/projects/html5sortable/", "authors": [ "Ali Farhadi " From f01b984ae680dffc8b482eb0116cc9325ed73ae6 Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Fri, 24 Apr 2015 18:13:26 +0200 Subject: [PATCH 08/13] version --- bower.json | 2 +- jquery.sortable.js | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/bower.json b/bower.json index c929085..8a4bebf 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "html5sortable", - "version": "0.0.4", + "version": "0.0.5", "homepage": "http://farhadi.ir/projects/html5sortable/", "authors": [ "Ali Farhadi " diff --git a/jquery.sortable.js b/jquery.sortable.js index 1e4d270..546e1a8 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -15,8 +15,8 @@ $.fn.html5sortable = function(options) { var self = this; return this.each(function() { if (/^(enable|disable|destroy)$/.test(method)) { - var items = $(this).children($(this).data('items')).attr('draggable', method == 'enable'); - if (method == 'destroy') { + var items = $(this).children($(this).data('items')).attr('draggable', method === 'enable'); + if (method === 'destroy') { items.add(this).removeData('connectWith items') .off('dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s'); } @@ -29,7 +29,7 @@ $.fn.html5sortable = function(options) { }).mouseup(function() { isHandle = false; }); - $(this).data('items', options.items) + $(this).data('items', options.items); placeholders = placeholders.add(placeholder); if (options.connectWith) { $(options.connectWith).add(this).data('connectWith', options.connectWith); @@ -52,7 +52,9 @@ $.fn.html5sortable = function(options) { dragging.parent().trigger('sortupdate', {item: dragging}); dragging = null; }).not('a[href], img').on('selectstart.h5s', function() { - this.dragDrop && this.dragDrop(); + if(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')) { @@ -64,16 +66,23 @@ $.fn.html5sortable = function(options) { return true; } - if (e.type == 'drop') { + if (e.type === 'drop') { e.stopPropagation(); - if(dragging.parent().is(placeholders.filter(':visible').parent())) { + var parent = placeholders.filter(':visible').parent(); + + if(dragging.parent().is(parent)) { dragging.detach(); } else { dragging.removeClass('sortable-dragging').show(); } - dragging = dragging.clone(true) + dragging = dragging.clone(true); + + if(parent.attr('data-unique') === 'true') { + parent.find('[data-value="'+dragging.attr('data-value')+'"]').remove(); + } + dragging.insertAfter(placeholders.filter(':visible')); dragging.trigger('dragend.h5s'); return false; From e0219dbd41957b073157ba2b1e7ef9982e2172b8 Mon Sep 17 00:00:00 2001 From: FreshXOpenSource Date: Tue, 28 Apr 2015 10:53:14 +0200 Subject: [PATCH 09/13] Delete jquery.sortable.min.js --- jquery.sortable.min.js | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 jquery.sortable.min.js diff --git a/jquery.sortable.min.js b/jquery.sortable.min.js deleted file mode 100644 index 7e90810..0000000 --- a/jquery.sortable.min.js +++ /dev/null @@ -1,8 +0,0 @@ -/* - * HTML5 Sortable jQuery Plugin - * http://farhadi.ir/projects/html5sortable - * - * 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() Date: Tue, 28 Apr 2015 11:44:59 +0200 Subject: [PATCH 10/13] new versioN --- bower.json | 2 +- jquery.sortable.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 8a4bebf..7c9a9d1 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "html5sortable", - "version": "0.0.5", + "version": "0.0.6", "homepage": "http://farhadi.ir/projects/html5sortable/", "authors": [ "Ali Farhadi " diff --git a/jquery.sortable.js b/jquery.sortable.js index 546e1a8..df53eba 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -89,9 +89,10 @@ $.fn.html5sortable = function(options) { } e.preventDefault(); e.originalEvent.dataTransfer.dropEffect = 'copy'; + console.log(this); if (items.is(this)) { if (options.forcePlaceholderSize) { - placeholder.height(dragging.outerHeight()); + placeholder.height(dragging.outerHeight()+1); } if(!targets || targets.split(',').indexOf(dragging.parent().attr('data-key')) !== -1) { dragging.hide(); From 98c72b1c7df02af3961c125484c9b2ee19b05abd Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Thu, 14 May 2015 21:02:36 +0200 Subject: [PATCH 11/13] targets --- bower.json | 2 +- jquery.sortable.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 7c9a9d1..a439b87 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "html5sortable", - "version": "0.0.6", + "version": "0.0.7", "homepage": "http://farhadi.ir/projects/html5sortable/", "authors": [ "Ali Farhadi " diff --git a/jquery.sortable.js b/jquery.sortable.js index df53eba..82c5e6b 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -62,7 +62,7 @@ $.fn.html5sortable = function(options) { } var targets = dragging.attr('data-targets'); - if(targets && targets.split(',').indexOf(self.attr('data-key')) === -1) { + if(targets !== undefined && targets.split(',').indexOf(self.attr('data-key')) === -1) { return true; } From cb7a0e1df44fa3e1355ff0a2067f3c51f63830cb Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Thu, 14 May 2015 21:22:45 +0200 Subject: [PATCH 12/13] removed debug output --- bower.json | 2 +- jquery.sortable.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/bower.json b/bower.json index a439b87..3edeb19 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "html5sortable", - "version": "0.0.7", + "version": "0.0.8", "homepage": "http://farhadi.ir/projects/html5sortable/", "authors": [ "Ali Farhadi " diff --git a/jquery.sortable.js b/jquery.sortable.js index 82c5e6b..6d380b2 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -89,7 +89,6 @@ $.fn.html5sortable = function(options) { } e.preventDefault(); e.originalEvent.dataTransfer.dropEffect = 'copy'; - console.log(this); if (items.is(this)) { if (options.forcePlaceholderSize) { placeholder.height(dragging.outerHeight()+1); From 3349284f309605490713ad3144d84a1ea67d2bfa Mon Sep 17 00:00:00 2001 From: Dominik Roessler Date: Fri, 15 May 2015 12:32:53 +0200 Subject: [PATCH 13/13] highlight targets --- bower.json | 2 +- jquery.sortable.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 3edeb19..a05b2c3 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "html5sortable", - "version": "0.0.8", + "version": "0.1.0", "homepage": "http://farhadi.ir/projects/html5sortable/", "authors": [ "Ali Farhadi " diff --git a/jquery.sortable.js b/jquery.sortable.js index 6d380b2..e071546 100644 --- a/jquery.sortable.js +++ b/jquery.sortable.js @@ -43,10 +43,25 @@ $.fn.html5sortable = function(options) { dt.effectAllowed = 'copy'; dt.setData('Text', 'dummy'); index = (dragging = $(this)).addClass('sortable-dragging').index(); + + var targets = dragging.attr('data-targets'); + if(targets !== undefined) { + targets.split(',').forEach(function(target) { + $('[data-key="'+target+'"]').addClass('hot'); + }); + } }).on('dragend.h5s', function() { if (!dragging) { return; } + + var targets = dragging.attr('data-targets'); + if(targets !== undefined) { + targets.split(',').forEach(function(target) { + $('[data-key="'+target+'"]').removeClass('hot'); + }); + } + dragging.removeClass('sortable-dragging').show(); placeholders.detach(); dragging.parent().trigger('sortupdate', {item: dragging});