Changeset 5386
- Timestamp:
- 05/02/08 20:25:00 (8 months ago)
- Location:
- trunk/ui
- Files:
-
- 2 modified
-
ui.draggable.js (modified) (6 diffs)
-
ui.droppable.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ui/ui.draggable.js
r5384 r5386 56 56 * - Position generation - 57 57 * This block generates everything position related - it's the core of draggables. 58 */ 59 58 */ 59 60 this.margins = { //Cache the margins 61 left: (parseInt(this.element.css("marginLeft"),10) || 0), 62 top: (parseInt(this.element.css("marginTop"),10) || 0) 63 }; 64 60 65 this.cssPosition = this.helper.css("position"); //Store the helper's css position 61 66 this.offset = this.element.offset(); //The element's absolute position on the page 62 67 this.offset = { //Substract the margins from the element's absolute offset 63 top: this.offset.top - parseInt(this.element.css("marginTop") || 0,10),64 left: this.offset.left - parseInt(this.element.css("marginLeft") || 0,10)65 }; 66 68 top: this.offset.top - this.margins.top, 69 left: this.offset.left - this.margins.left 70 }; 71 67 72 this.offset.click = { //Where the click happened, relative to the element 68 73 left: e.pageX - this.offset.left, 69 74 top: e.pageY - this.offset.top 70 75 }; 71 76 72 77 this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset(); //Get the offsetParent and cache its position 73 78 this.offset.parent = { //Store its position plus border 74 top: po.top + parseInt(this.offsetParent.css("borderTopWidth") || 0,10),75 left: po.left + parseInt(this.offsetParent.css("borderLeftWidth") || 0,10)76 }; 77 79 top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0), 80 left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0) 81 }; 82 78 83 var p = this.element.position(); //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helpers 79 84 this.offset.relative = this.cssPosition == "relative" ? { 80 top: p.top - parseInt(this.helper.css("top") || 0,10) + this.offsetParent[0].scrollTop,81 left: p.left - parseInt(this.helper.css("left") || 0,10) + this.offsetParent[0].scrollLeft85 top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.offsetParent[0].scrollTop, 86 left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.offsetParent[0].scrollLeft 82 87 } : { top: 0, left: 0 }; 83 88 84 89 this.originalPosition = this.generatePosition(e); //Generate the original position 85 90 this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Cache the helper size … … 106 111 107 112 this.containment = [ 108 co.left + parseInt($(ce).css("borderLeftWidth"),10) - this.offset.relative.left - this.offset.parent.left,109 co.top + parseInt($(ce).css("borderTopWidth"),10) - this.offset.relative.top - this.offset.parent.top,110 co.left+Math.max(ce.scrollWidth,ce.offsetWidth) - parseInt($(ce).css("borderLeftWidth"),10) - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - parseInt(this.element.css("marginLeft") || 0,10) - parseInt(this.element.css("marginRight") || 0,10),111 co.top+Math.max(ce.scrollHeight,ce.offsetHeight) - parseInt($(ce).css("borderTopWidth"),10) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - parseInt(this.element.css("marginTop") || 0,10) - parseInt(this.element.css("marginTop") || 0,10)113 co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left, 114 co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top, 115 co.left+Math.max(ce.scrollWidth,ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0), 116 co.top+Math.max(ce.scrollHeight,ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0) 112 117 ]; 113 118 } … … 123 128 return false; 124 129 130 }, 131 generateAbsolutePosition: function(pos) { 132 return { 133 top: ( 134 pos.top // the calculated relative position 135 + this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent 136 + this.offset.parent.top // The offsetParent's offset without borders (offset + border) 137 - (this.cssPosition == "fixed" ? 0 : this.offsetParent[0].scrollTop) // The offsetParent's scroll position, not if the element is fixed 138 + this.margins.top //Add the margin (you don't want the margin counting in intersection methods) 139 ), 140 left: ( 141 pos.left // the calculated relative position 142 + this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent 143 + this.offset.parent.left // The offsetParent's offset without borders (offset + border) 144 - (this.cssPosition == "fixed" ? 0 : this.offsetParent[0].scrollLeft) // The offsetParent's scroll position, not if the element is fixed 145 + this.margins.left //Add the margin (you don't want the margin counting in intersection methods) 146 ) 147 }; 125 148 }, 126 149 generatePosition: function(e) { … … 143 166 ) 144 167 }; 145 168 146 169 if(!this.originalPosition) return position; //If we are not dragging yet, we won't check for options 147 170 … … 172 195 //Compute the helpers position 173 196 this.position = this.generatePosition(e); 197 this.positionAbs = this.generateAbsolutePosition(this.position); 174 198 175 199 //Call plugins and callbacks and use the resulting position if something is returned … … 183 207 }, 184 208 stop: function(e) { 185 209 186 210 //If we are using droppables, inform the manager about the drop 187 211 if ($.ui.ddmanager && !this.options.dropBehaviour) -
trunk/ui/ui.droppable.js
r5300 r5386 194 194 break; 195 195 case 'pointer': 196 return ( l < ((draggable.positionAbs || draggable.position.absolute).left + draggable.clickOffset.left) && ((draggable.positionAbs || draggable.position.absolute).left + draggable.clickOffset.left) < r197 && t < ((draggable.positionAbs || draggable.position.absolute).top + draggable.clickOffset.top) && ((draggable.positionAbs || draggable.position.absolute).top + draggable.clickOffset.top) < b);196 return ( l < ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left) && ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left) < r 197 && t < ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top) && ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top) < b); 198 198 break; 199 199 case 'touch':
