Skip to content

Commit

Permalink
Prevent a clickout from happening if a drag just ended. Issue #249
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrins committed Apr 27, 2015
1 parent df00a12 commit df7a8af
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
callbacks = opts.callbacks,
resize = throttle(reflow, 10),
visible = false,
isDragging = false,
dragWidth = 0,
dragHeight = 0,
dragHelperHeight = 0,
Expand Down Expand Up @@ -562,12 +563,14 @@
if (dragHeight <= 0 || dragWidth <= 0 || slideHeight <= 0) {
reflow();
}
isDragging = true;
container.addClass(draggingClass);
shiftMovementDirection = null;
boundElement.trigger('dragstart.spectrum', [ get() ]);
}

function dragStop() {
isDragging = false;
container.removeClass(draggingClass);
boundElement.trigger('dragstop.spectrum', [ get() ]);
}
Expand Down Expand Up @@ -645,6 +648,10 @@
// Return on right click.
if (e.button == 2) { return; }

// If a drag event was happening during the mouseup, don't hide
// on click.
if (isDragging) { return; }

if (clickoutFiresChange) {
updateOriginalInput(true);
}
Expand Down Expand Up @@ -1094,7 +1101,12 @@
if (dragging) {
$(doc).unbind(duringDragEvents);
$(doc.body).removeClass("sp-dragging");
onstop.apply(element, arguments);

// Wait a tick before notifying observers to allow the click event
// to fire in Chrome.
setTimeout(function() {
onstop.apply(element, arguments);
}, 0);
}
dragging = false;
}
Expand Down

0 comments on commit df7a8af

Please sign in to comment.