Skip to content

Commit 7069e8f

Browse files
committed
additional option: onMousedown
closes johnny#17
1 parent 10e8bd2 commit 7069e8f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

source/js/jquery-sortable.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
onCancel: function ($item, container, _super) {
6767
},
6868
// Executed at the beginning of a mouse move event.
69-
// The Placeholder has not been moved yet
69+
// The Placeholder has not been moved yet.
7070
onDrag: function ($item, position, _super) {
7171
$item.css(position)
7272
},
@@ -88,6 +88,10 @@
8888
$item.removeClass("dragged").removeAttr("style")
8989
$("body").removeClass("dragging")
9090
},
91+
// Called on mousedown.
92+
onMousedown: function($item, event, _super) {
93+
event.preventDefault()
94+
},
9195
// Template for the placeholder. Can be any valid jQuery input
9296
// e.g. a string, a DOM element
9397
placeholder: '<li class="placeholder"/>',
@@ -241,6 +245,8 @@
241245
this.itemContainer = itemContainer
242246

243247
this.setPointer(e)
248+
249+
this.options.onMousedown(this.item, e, groupDefaults.onMousedown)
244250
},
245251
drag: function (e) {
246252
if(!this.dragging){
@@ -431,15 +437,12 @@
431437
Container.prototype = {
432438
dragInit: function (e) {
433439
var rootGroup = this.rootGroup
434-
if(rootGroup.item ||
435-
e.which !== 1 ||
436-
!this.options.drag ||
437-
$(e.target).is(this.options.exclude))
438-
return;
439-
440-
e.preventDefault()
441440

442-
rootGroup.dragInit(e, this)
441+
if( !rootGroup.item &&
442+
e.which === 1 &&
443+
this.options.drag &&
444+
!$(e.target).is(this.options.exclude))
445+
rootGroup.dragInit(e, this)
443446
},
444447
searchValidTarget: function (pointer, lastPointer) {
445448
var distances = sortByDistanceDesc(this.getItemDimensions(),

0 commit comments

Comments
 (0)