Skip to content

Commit f5387c1

Browse files
committed
Ability to specify certain delay before drag start to be captured johnny#64
1 parent 354e9e3 commit f5387c1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

source/js/jquery-sortable.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
containerSelector: "ol, ul",
5757
// Distance the mouse has to travel to start dragging
5858
distance: 0,
59+
// Time in milliseconds after mousedown until dragging should start.
60+
// This option can be used to prevent unwanted drags when clicking on an element.
61+
delay: 0,
5962
// The css selector of the drag handle
6063
handle: "",
6164
// The exact css path between the item and its subcontainers
@@ -247,12 +250,26 @@
247250
}
248251

249252
this.dragInitDone = true
253+
254+
// init delay timer if needed
255+
var that = this
256+
this.isDelayMet = !this.options.delay
257+
if (!this.isDelayMet) {
258+
clearTimeout(this._mouseDelayTimer);
259+
this._mouseDelayTimer = setTimeout(function() {
260+
that.isDelayMet = true
261+
}, this.options.delay)
262+
}
263+
250264
},
251265
drag: function (e) {
252266
if(!this.dragging){
253267
if(!this.distanceMet(e))
254268
return
255269

270+
if (!this.delayMet())
271+
return
272+
256273
this.options.onDragStart(this.item, this.itemContainer, groupDefaults.onDragStart, e)
257274
this.item.before(this.placeholder)
258275
this.dragging = true
@@ -387,6 +404,9 @@
387404
Math.abs(this.pointer.top - e.pageY)
388405
) >= this.options.distance)
389406
},
407+
delayMet: function () {
408+
return this.isDelayMet;
409+
},
390410
scroll: function (e) {
391411
this.clearDimensions()
392412
this.clearOffsetParent()

0 commit comments

Comments
 (0)