Permalink
Browse files

Ability to specify certain delay before drag start to be captured #64

  • Loading branch information...
1 parent 354e9e3 commit f5387c1fb91c46695beda3d8bb3da9981af30c79 @troggy troggy committed Feb 3, 2014
Showing with 20 additions and 0 deletions.
  1. +20 −0 source/js/jquery-sortable.js
View
20 source/js/jquery-sortable.js
@@ -56,6 +56,9 @@
containerSelector: "ol, ul",
// Distance the mouse has to travel to start dragging
distance: 0,
+ // Time in milliseconds after mousedown until dragging should start.
+ // This option can be used to prevent unwanted drags when clicking on an element.
+ delay: 0,
// The css selector of the drag handle
handle: "",
// The exact css path between the item and its subcontainers
@@ -247,12 +250,26 @@
}
this.dragInitDone = true
+
+ // init delay timer if needed
+ var that = this
+ this.isDelayMet = !this.options.delay
+ if (!this.isDelayMet) {
+ clearTimeout(this._mouseDelayTimer);
+ this._mouseDelayTimer = setTimeout(function() {
+ that.isDelayMet = true
+ }, this.options.delay)
+ }
+
},
drag: function (e) {
if(!this.dragging){
if(!this.distanceMet(e))
return
+ if (!this.delayMet())
+ return
+
this.options.onDragStart(this.item, this.itemContainer, groupDefaults.onDragStart, e)
this.item.before(this.placeholder)
this.dragging = true
@@ -387,6 +404,9 @@
Math.abs(this.pointer.top - e.pageY)
) >= this.options.distance)
},
+ delayMet: function () {
+ return this.isDelayMet;
+ },
scroll: function (e) {
this.clearDimensions()
this.clearOffsetParent()

0 comments on commit f5387c1

Please sign in to comment.