Skip to content

Commit b7996fa

Browse files
committed
Modify behaviour of onMousedown option
Falsy return value prevents dragging
1 parent ccd7d58 commit b7996fa

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

source/js/jquery-sortable.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@
9292
$item.removeClass("dragged").removeAttr("style")
9393
$("body").removeClass("dragging")
9494
},
95-
// Called on mousedown.
95+
// Called on mousedown. If falsy value is returned, the dragging will not start.
9696
onMousedown: function($item, _super, event) {
9797
event.preventDefault()
98+
return true
9899
},
99100
// Template for the placeholder. Can be any valid jQuery input
100101
// e.g. a string, a DOM element.
@@ -226,15 +227,15 @@
226227
this.$document = $(itemContainer.el[0].ownerDocument)
227228

228229
if(itemContainer.enabled()){
229-
this.toggleListeners('on')
230-
231230
// get item to drag
232231
this.item = $(e.target).closest(this.options.itemSelector)
233232
this.itemContainer = itemContainer
234233

235-
this.setPointer(e)
234+
if(!this.options.onMousedown(this.item, groupDefaults.onMousedown, e))
235+
return
236236

237-
this.options.onMousedown(this.item, groupDefaults.onMousedown, e)
237+
this.setPointer(e)
238+
this.toggleListeners('on')
238239
} else {
239240
this.toggleListeners('on', ['drop'])
240241
}

0 commit comments

Comments
 (0)