]> source.dussan.org Git - jquery-ui.git/commitdiff
Mouse: tie the preventClickEvent property to the event target, not the container...
authorawgy <josh.varner@gmail.com>
Wed, 3 Nov 2010 07:45:47 +0000 (02:45 -0500)
committerScott González <scott.gonzalez@gmail.com>
Tue, 9 Nov 2010 14:52:24 +0000 (09:52 -0500)
tests/jquery.simulate.js
tests/unit/sortable/sortable_tickets.js
ui/jquery.ui.mouse.js

index 3e7ca1090d503f57bddb5f1e9cfac598115c966f..81d7f62bf83d4d3a6dd16b07b69e758bfe2d51fe 100644 (file)
@@ -120,6 +120,7 @@ $.extend($.simulate.prototype, {
                this.simulateEvent(document, "mousemove", coord);
                this.simulateEvent(document, "mousemove", coord);
                this.simulateEvent(target, "mouseup", coord);
+               this.simulateEvent(target, "click", coord);
        },
        findCenter: function(el) {
                var el = $(this.target), o = el.offset();
index e265c2f3a64061b02a963dc8e8f01a28900b0c49..3edc8c04cfba18568fc114ef384104fc18375b10 100644 (file)
@@ -36,4 +36,48 @@ test("#3019: Stop fires too early", function() {
 
 });
 
+test('#4752: link event firing on sortable with connect list', function () {
+    var fired = {},
+        hasFired = function (type) { return (type in fired) && (true === fired[type]); };
+
+    $('#sortable').clone().attr('id', 'sortable2').insertAfter('#sortable');
+
+    $('#main ul').sortable({
+        connectWith: '#main ul',
+        change: function (e, ui) {
+            fired.change = true;
+        },
+        receive: function (e, ui) {
+            fired.receive = true;
+        },
+        remove: function (e, ui) {
+            fired.remove = true;
+        }
+    });
+
+    $('#main ul li').live('click.ui-sortable-test', function () {
+        fired.click = true;
+    });
+
+    $('#sortable li:eq(0)').simulate('click');
+    ok(!hasFired('change'), 'Click only, change event should not have fired');
+    ok(hasFired('click'), 'Click event should have fired');
+
+    // Drag an item within the first list
+    fired = {};
+    $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 40 });
+    ok(hasFired('change'), '40px drag, change event should have fired');
+    ok(!hasFired('receive'), 'Receive event should not have fired');
+    ok(!hasFired('remove'), 'Remove event should not have fired');
+    ok(!hasFired('click'), 'Click event should not have fired');
+
+    // Drag an item from the first list to the second, connected list
+    fired = {};
+    $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 150 });
+    ok(hasFired('change'), '150px drag, change event should have fired');
+    ok(hasFired('receive'), 'Receive event should have fired');
+    ok(hasFired('remove'), 'Remove event should have fired');
+    ok(!hasFired('click'), 'Click event should not have fired');
+});
+
 })(jQuery);
index d0c82f83f2d67dc7b5acfd29cbe9151debd393fa..bfe8640a2a36fdd9f1ef77eec9da735144c70d05 100644 (file)
@@ -26,8 +26,8 @@ $.widget("ui.mouse", {
                                return self._mouseDown(event);
                        })
                        .bind('click.'+this.widgetName, function(event) {
-                               if(self._preventClickEvent) {
-                                       self._preventClickEvent = false;
+                               if (true === $.data(event.target, self.widgetName + '.preventClickEvent')) {
+                                   $.removeData(event.target, self.widgetName + '.preventClickEvent');
                                        event.stopImmediatePropagation();
                                        return false;
                                }
@@ -118,7 +118,11 @@ $.widget("ui.mouse", {
 
                if (this._mouseStarted) {
                        this._mouseStarted = false;
-                       this._preventClickEvent = (event.target == this._mouseDownEvent.target);
+
+                       if (event.target == this._mouseDownEvent.target) {
+                           $.data(event.target, this.widgetName + '.preventClickEvent', true);
+                       }
+
                        this._mouseStop(event);
                }