]> source.dussan.org Git - jquery-ui.git/commitdiff
draggable: another connectToSortable improvement: the activate/deactivate callbacks...
authorPaul Bakaus <paul.bakaus@googlemail.com>
Fri, 30 May 2008 11:30:58 +0000 (11:30 +0000)
committerPaul Bakaus <paul.bakaus@googlemail.com>
Fri, 30 May 2008 11:30:58 +0000 (11:30 +0000)
ui/source/ui.draggable.js
ui/source/ui.sortable.js

index 64e2062450bec8eccb9865d4c64d5c7158b013f4..87fe090571c20c4587ef97118f9982a9486c1f50 100644 (file)
        \r
        $.ui.plugin.add("draggable", "connectToSortable", {\r
                start: function(e,ui) {\r
-                       \r
+               \r
                        var inst = $(this).data("draggable");\r
                        inst.sortables = [];\r
                        $(ui.options.connectToSortable).each(function() {\r
-                               if($.data(this, 'sortable')) inst.sortables.push({\r
-                                       instance: $.data(this, 'sortable'),\r
-                                       offset: $.data(this, 'sortable').element.offset(),\r
-                                       width: $.data(this, 'sortable').element.width(),\r
-                                       height: $.data(this, 'sortable').element.height(),\r
-                                       shouldRevert: $.data(this, 'sortable').options.revert\r
-                               });\r
+                               if($.data(this, 'sortable')) {\r
+                                       var sortable = $.data(this, 'sortable');\r
+                                       inst.sortables.push({\r
+                                               instance: sortable,\r
+                                               offset: sortable.element.offset(),\r
+                                               width: sortable.element.width(),\r
+                                               height: sortable.element.height(),\r
+                                               shouldRevert: sortable.options.revert\r
+                                       });\r
+                                       \r
+                                       sortable.propagate("activate", e, inst);\r
+                               }\r
                        });\r
 \r
                },\r
                                        this.instance.element.triggerHandler("sortreceive", [e, $.extend(this.instance.ui(), { sender: inst.element })], this.instance.options["receive"]);\r
 \r
                                        this.instance.options.helper = this.instance.options._helper;\r
+                               } else {\r
+                                       this.instance.propagate("deactivate", e, inst);\r
                                }\r
+\r
                        });\r
                        \r
                },\r
                                        \r
                                var l = o.left, r = l + o.width,\r
                                        t = o.top, b = t + o.height;\r
-                                       \r
+               \r
                                return (l < (this.positionAbs.left + this.offset.click.left) && (this.positionAbs.left + this.offset.click.left) < r\r
                                                && t < (this.positionAbs.top + this.offset.click.top) && (this.positionAbs.top + this.offset.click.top) < b);                           \r
                        };\r
                        \r
-                       $.each(inst.sortables, function() {\r
+                       $.each(inst.sortables, function(i) {\r
+\r
 \r
                                if(checkPos.call(inst, {\r
                                        left: this.offset.left, top: this.offset.top,\r
                                        width: this.width, height: this.height\r
                                })) {\r
+\r
                                        //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once\r
                                        if(!this.instance.isOver) {\r
                                                this.instance.isOver = 1;\r
                                                this.instance.options.helper = function() { return ui.helper[0]; };\r
                                        \r
                                                e.target = this.instance.currentItem[0];\r
-                                               this.instance.mouseStart(e, true);\r
+                                               this.instance.mouseStart(e, true, true);\r
 \r
                                                //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes\r
                                                this.instance.offset.click.top = inst.offset.click.top;\r
index 7ab406a59b5df59246388a51afc4f584703d2892..17287bb867d2ca33ec9d16e0a5e2fc3f309fef4b 100644 (file)
                                \r
                        };                      \r
                },\r
-               mouseStart: function(e, overrideHandle) {\r
+               mouseStart: function(e, overrideHandle, noActivation) {\r
                \r
                        var o = this.options;\r
                        this.currentContainer = this;\r
                        this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size\r
 \r
                        if(this.options.placeholder != 'clone') this.currentItem.css('visibility', 'hidden'); //Set the original element visibility to hidden to still fill out the white space\r
-                       for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i].propagate("activate", e, this); } //Post 'activate' events to possible containers\r
+                       \r
+                       if(!noActivation) {\r
+                                for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i].propagate("activate", e, this); } //Post 'activate' events to possible containers\r
+                       }\r
                        \r
                        //Prepare possible droppables\r
                        if($.ui.ddmanager) $.ui.ddmanager.current = this;\r
                        \r
                        if(this.domPosition != this.currentItem.prev()[0]) this.propagate("update", e, null, noPropagation); //Trigger update callback if the DOM position has changed\r
                        if(!contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element\r
-                               this.propagate("remove", e);\r
+                               this.propagate("remove", e, null, noPropagation);\r
                                for (var i = this.containers.length - 1; i >= 0; i--){\r
                                        if(contains(this.containers[i].element[0], this.currentItem[0])) {\r
-                                               this.containers[i].propagate("update", e, this);\r
-                                               this.containers[i].propagate("receive", e, this);\r
+                                               this.containers[i].propagate("update", e, this, noPropagation);\r
+                                               this.containers[i].propagate("receive", e, this, noPropagation);\r
                                        }\r
                                };\r
                        };\r
                        \r
                        //Post events to containers\r
                        for (var i = this.containers.length - 1; i >= 0; i--){\r
-                               this.containers[i].propagate("deactivate", e, this);\r
+                               this.containers[i].propagate("deactivate", e, this, noPropagation);\r
                                if(this.containers[i].containerCache.over) {\r
                                        this.containers[i].propagate("out", e, this);\r
                                        this.containers[i].containerCache.over = 0;\r