aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/unit/draggable/draggable_events.js54
-rw-r--r--tests/unit/draggable/draggable_options.js25
-rw-r--r--ui/jquery.ui.draggable.js34
3 files changed, 103 insertions, 10 deletions
diff --git a/tests/unit/draggable/draggable_events.js b/tests/unit/draggable/draggable_events.js
index 79b406e8c..d92d8ee12 100644
--- a/tests/unit/draggable/draggable_events.js
+++ b/tests/unit/draggable/draggable_events.js
@@ -24,4 +24,58 @@ test("callbacks occurance count", function() {
});
+test("stopping the start callback", function() {
+
+ expect(3);
+
+ var start = 0, stop = 0, dragc = 0;
+ el = $("#draggable2").draggable({
+ start: function() { start++; return false; },
+ drag: function() { dragc++; },
+ stop: function() { stop++; }
+ });
+
+ drag(el, 10, 10);
+
+ equals(start, 1, "start callback should happen exactly once");
+ equals(dragc, 0, "drag callback should not happen at all");
+ equals(stop, 0, "stop callback should not happen if there wasnt even a start");
+
+});
+
+test("stopping the drag callback", function() {
+
+ expect(3);
+
+ var start = 0, stop = 0, dragc = 0;
+ el = $("#draggable2").draggable({
+ start: function() { start++;},
+ drag: function() { dragc++; return false; },
+ stop: function() { stop++; }
+ });
+
+ drag(el, 10, 10);
+
+ equals(start, 1, "start callback should happen exactly once");
+ equals(dragc, 1, "drag callback should happen exactly once");
+ equals(stop, 1, "stop callback should happen, as we need to actively stop the drag");
+
+});
+
+test("stopping the stop callback", function() {
+
+ expect(1);
+
+ el = $("#draggable2").draggable({
+ helper: 'clone',
+ stop: function() { return false; }
+ });
+
+ drag(el, 10, 10);
+
+ ok($("#draggable2").data('draggable').helper, "the clone should not be deleted if the stop callback is stopped");
+
+
+});
+
})(jQuery);
diff --git a/tests/unit/draggable/draggable_options.js b/tests/unit/draggable/draggable_options.js
index 72fa28639..78f6c563e 100644
--- a/tests/unit/draggable/draggable_options.js
+++ b/tests/unit/draggable/draggable_options.js
@@ -42,15 +42,34 @@ test("{ addClasses: false }", function() {
test("{ appendTo: 'parent' }, default", function() {
equals(draggable_defaults.appendTo, "parent");
- ok(false, 'missing test - untested code is broken code');
+ el = $("#draggable2").draggable({ appendTo: 'parent' });
+ drag(el, 50, 50);
+ moved(50, 50);
+
+ el = $("#draggable1").draggable({ appendTo: 'parent' });
+ drag(el, 50, 50);
+ moved(50, 50);
+
});
test("{ appendTo: Element }", function() {
- ok(false, 'missing test - untested code is broken code');
+ el = $("#draggable2").draggable({ appendTo: $("#draggable2").parent()[0] });
+ drag(el, 50, 50);
+ moved(50, 50);
+
+ el = $("#draggable1").draggable({ appendTo: $("#draggable2").parent()[0] });
+ drag(el, 50, 50);
+ moved(50, 50);
});
test("{ appendTo: Selector }", function() {
- ok(false, 'missing test - untested code is broken code');
+ el = $("#draggable2").draggable({ appendTo: "#main" });
+ drag(el, 50, 50);
+ moved(50, 50);
+
+ el = $("#draggable1").draggable({ appendTo: "#main" });
+ drag(el, 50, 50);
+ moved(50, 50);
});
test("{ axis: false }, default", function() {
diff --git a/ui/jquery.ui.draggable.js b/ui/jquery.ui.draggable.js
index 0cc564b78..1753aa02b 100644
--- a/ui/jquery.ui.draggable.js
+++ b/ui/jquery.ui.draggable.js
@@ -137,8 +137,11 @@ $.widget("ui.draggable", $.ui.mouse, {
if(o.containment)
this._setContainment();
- //Call plugins and callbacks
- this._trigger("start", event);
+ //Trigger event + callbacks
+ if(this._trigger("start", event) === false) {
+ this._clear();
+ return false;
+ }
//Recache the helper size
this._cacheHelperProportions();
@@ -161,7 +164,10 @@ $.widget("ui.draggable", $.ui.mouse, {
//Call plugins and callbacks and use the resulting position if something is returned
if (!noPropagation) {
var ui = this._uiHash();
- this._trigger('drag', event, ui);
+ if(this._trigger('drag', event, ui) === false) {
+ this._mouseUp({});
+ return false;
+ }
this.position = ui.position;
}
@@ -192,16 +198,30 @@ $.widget("ui.draggable", $.ui.mouse, {
if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) {
var self = this;
$(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
- self._trigger("stop", event);
- self._clear();
+ if(self._trigger("stop", event) !== false) {
+ self._clear();
+ }
});
} else {
- this._trigger("stop", event);
- this._clear();
+ if(this._trigger("stop", event) !== false) {
+ this._clear();
+ }
}
return false;
},
+
+ cancel: function() {
+
+ if(this.helper.is(".ui-draggable-dragging")) {
+ this._mouseUp({});
+ } else {
+ this._clear();
+ }
+
+ return this;
+
+ },
_getHandle: function(event) {