|
93 | 93 | event.preventDefault() |
94 | 94 | }, |
95 | 95 | // Template for the placeholder. Can be any valid jQuery input |
96 | | - // e.g. a string, a DOM element |
| 96 | + // e.g. a string, a DOM element. |
| 97 | + // The placeholder must have the class "placeholder" |
97 | 98 | placeholder: '<li class="placeholder"/>', |
98 | 99 | // If true, the position of the placeholder is calculated on every mousemove. |
99 | 100 | // If false, it is only calculated when the mouse is above a container. |
|
115 | 116 |
|
116 | 117 | return result |
117 | 118 | }, |
118 | | - // Set tolerance while dragging. Positive values will decrease sensitivity. |
| 119 | + // Set tolerance while dragging. Positive values decrease sensitivity, |
| 120 | + // negative values increase it. |
119 | 121 | tolerance: 0 |
120 | 122 | }, // end group defaults |
121 | 123 | containerGroups = {}, |
122 | 124 | groupCounter = 0, |
| 125 | + emptyBox = { |
| 126 | + left: 0, |
| 127 | + top: 0, |
| 128 | + bottom: 0, |
| 129 | + right:0 |
| 130 | + } |
123 | 131 | eventNames = { |
124 | 132 | start: "touchstart.sortable mousedown.sortable", |
125 | 133 | end: "touchend.sortable touchcancel.sortable mouseup.sortable", |
|
142 | 150 | return array.push.apply(array, rest); |
143 | 151 | } |
144 | 152 |
|
145 | | - function setDimensions(array, dimensions, useOffset) { |
| 153 | + function setDimensions(array, dimensions, tolerance, useOffset) { |
146 | 154 | var i = array.length, |
147 | 155 | offsetMethod = useOffset ? "offset" : "position" |
| 156 | + tolerance = tolerance || 0 |
| 157 | + |
148 | 158 | while(i--){ |
149 | 159 | var el = array[i].el ? array[i].el : $(array[i]), |
150 | 160 | // use fitting method |
151 | 161 | pos = el[offsetMethod]() |
152 | 162 | pos.left += parseInt(el.css('margin-left'), 10) |
153 | | - pos.right += parseInt(el.css('margin-right'),10) |
| 163 | + pos.top += parseInt(el.css('margin-top'),10) |
154 | 164 | dimensions[i] = [ |
155 | | - pos.left, |
156 | | - pos.left + el.outerWidth(), |
157 | | - pos.top, |
158 | | - pos.top + el.outerHeight() |
| 165 | + pos.left - tolerance, |
| 166 | + pos.left + el.outerWidth() + tolerance, |
| 167 | + pos.top - tolerance, |
| 168 | + pos.top + el.outerHeight() + tolerance |
159 | 169 | ] |
160 | 170 | } |
161 | 171 | } |
|
330 | 340 | }, |
331 | 341 | getContainerDimensions: function () { |
332 | 342 | if(!this.containerDimensions) |
333 | | - setDimensions(this.containers, this.containerDimensions = [], !this.$getOffsetParent()) |
| 343 | + setDimensions(this.containers, this.containerDimensions = [], this.options.tolerance, !this.$getOffsetParent()) |
334 | 344 | return this.containerDimensions |
335 | 345 | }, |
336 | 346 | getContainer: function (element) { |
|
453 | 463 | while(i--){ |
454 | 464 | var index = distances[i][0], |
455 | 465 | distance = distances[i][1] |
456 | | - if(!distance && this.options.nested && this.getContainerGroup(index)){ |
| 466 | + if(!distance && this.hasChildGroup(index)){ |
457 | 467 | var found = this.getContainerGroup(index).searchValidTarget(pointer, lastPointer) |
458 | 468 | if(found) |
459 | 469 | return true |
|
494 | 504 | } else |
495 | 505 | sameResultBox.left += width / 2 |
496 | 506 | } |
| 507 | + if(this.hasChildGroup(index)) |
| 508 | + sameResultBox = emptyBox |
497 | 509 | this.rootGroup.movePlaceholder(this, item, method, sameResultBox) |
498 | 510 | }, |
499 | 511 | getItemDimensions: function () { |
500 | 512 | if(!this.itemDimensions){ |
501 | | - this.items = this.$getChildren(this.el, "item").filter(":not(.dragged)").get() |
502 | | - setDimensions(this.items, this.itemDimensions = []) |
| 513 | + this.items = this.$getChildren(this.el, "item").filter(":not(.placeholder)").get() |
| 514 | + setDimensions(this.items, this.itemDimensions = [], this.options.tolerance) |
503 | 515 | } |
504 | 516 | return this.itemDimensions |
505 | 517 | }, |
|
514 | 526 | offsetParent = el.offsetParent() |
515 | 527 | return offsetParent |
516 | 528 | }, |
| 529 | + hasChildGroup: function (index) { |
| 530 | + return this.options.nested && this.getContainerGroup(index) |
| 531 | + }, |
517 | 532 | getContainerGroup: function (index) { |
518 | 533 | var childGroup = $.data(this.items[index], "subContainer") |
519 | 534 | if( childGroup === undefined){ |
|
0 commit comments