From 1aa0121c3197c3d8e7853927c1595ab0216913c6 Mon Sep 17 00:00:00 2001 From: Lebedev Konstantin Date: Wed, 15 Feb 2017 22:24:39 +0300 Subject: [PATCH] #1029: + preventOnFilter --- README.md | 1 + Sortable.js | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 785db09..5db0b99 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ var sortable = new Sortable(el, { animation: 150, // ms, animation speed moving items when sorting, `0` — without animation handle: ".my-handle", // Drag handle selector within list items filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) + preventOnFilter: true, // Call `event.preventDefault()` when triggered `filter` draggable: ".item", // Specifies which items inside the element should be draggable ghostClass: "sortable-ghost", // Class name for the drop placeholder chosenClass: "sortable-chosen", // Class name for the chosen item diff --git a/Sortable.js b/Sortable.js index 087582a..648e8d2 100644 --- a/Sortable.js +++ b/Sortable.js @@ -249,6 +249,7 @@ dragClass: 'sortable-drag', ignore: 'a, img', filter: null, + preventOnFilter: true, animation: 0, setData: function (dataTransfer, dragEl) { dataTransfer.setData('Text', dragEl.textContent); @@ -306,6 +307,7 @@ var _this = this, el = this.el, options = this.options, + preventOnFilter = preventOnFilter.options, type = evt.type, touch = evt.touches && evt.touches[0], target = (touch || evt).target, @@ -339,7 +341,7 @@ if (typeof filter === 'function') { if (filter.call(this, evt, target, this)) { _dispatchEvent(_this, originalTarget, 'filter', target, el, startIndex); - evt.preventDefault(); + preventOnFilter && evt.preventDefault(); return; // cancel dnd } } @@ -354,7 +356,7 @@ }); if (filter) { - evt.preventDefault(); + preventOnFilter && evt.preventDefault(); return; // cancel dnd } }