Changeset 5665
- Timestamp:
- 05/22/08 12:08:52 (3 months ago)
- Files:
-
- 1 modified
-
branches/ui-experimental/mouse/ui.draggable.js (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ui-experimental/mouse/ui.draggable.js
r5652 r5665 21 21 //Initialize needed constants 22 22 var o = this.options; 23 23 24 24 this.mouseInit(); 25 25 26 26 //Position the node 27 27 if(o.helper == 'original' && !(/(relative|absolute|fixed)/).test(this.element.css('position'))) … … 30 30 }, 31 31 mouseStart: function(e) { 32 32 33 33 var o = this.options; 34 34 if($.ui.ddmanager) $.ui.ddmanager.current = this; … … 38 38 if(!this.helper.parents('body').length) this.helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo)); 39 39 if(this.helper[0] != this.element[0] && !(/(fixed|absolute)/).test(this.helper.css("position"))) this.helper.css("position", "absolute"); 40 40 41 41 /* 42 42 * - Position generation - … … 48 48 top: (parseInt(this.element.css("marginTop"),10) || 0) 49 49 }; 50 50 51 51 this.cssPosition = this.helper.css("position"); //Store the helper's css position 52 52 this.offset = this.element.offset(); //The element's absolute position on the page … … 55 55 left: this.offset.left - this.margins.left 56 56 }; 57 57 58 58 this.offset.click = { //Where the click happened, relative to the element 59 59 left: e.pageX - this.offset.left, 60 60 top: e.pageY - this.offset.top 61 61 }; 62 62 63 63 this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset(); //Get the offsetParent and cache its position 64 64 this.offset.parent = { //Store its position plus border … … 66 66 left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0) 67 67 }; 68 68 69 69 var p = this.element.position(); //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helpers 70 70 this.offset.relative = this.cssPosition == "relative" ? { … … 72 72 left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.offsetParent[0].scrollLeft 73 73 } : { top: 0, left: 0 }; 74 74 75 75 this.originalPosition = this.generatePosition(e); //Generate the original position 76 76 this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Cache the helper size 77 77 78 78 if(o.cursorAt) { 79 79 if(o.cursorAt.left != undefined) this.offset.click.left = o.cursorAt.left; … … 82 82 if(o.cursorAt.bottom != undefined) this.offset.click.top = this.helperProportions.height - o.cursorAt.bottom; 83 83 } 84 85 84 85 86 86 /* 87 87 * - Position constraining - … … 95 95 var ce = $(o.containment)[0]; 96 96 var co = $(o.containment).offset(); 97 97 98 98 this.containment = [ 99 99 co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left, … … 104 104 } 105 105 } 106 107 106 108 107 //Call plugins and callbacks 109 108 this.propagate("start", e); 110 109 111 110 this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size 112 111 if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e); 113 112 114 113 return !o.disabled; 115 116 114 }, 117 115 convertPositionTo: function(d, pos) { … … 154 152 ) 155 153 }; 156 154 157 155 if(!this.originalPosition) return position; //If we are not dragging yet, we won't check for options 158 159 156 160 157 /* … … 172 169 var top = this.originalPosition.top + Math.round((position.top - this.originalPosition.top) / o.grid[1]) * o.grid[1]; 173 170 position.top = this.containment ? (!(top < this.containment[1] || top > this.containment[3]) ? top : (!(top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; 174 171 175 172 var left = this.originalPosition.left + Math.round((position.left - this.originalPosition.left) / o.grid[0]) * o.grid[0]; 176 173 position.left = this.containment ? (!(left < this.containment[0] || left > this.containment[2]) ? left : (!(left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; … … 180 177 }, 181 178 mouseDrag: function(e) { 182 179 183 180 //Compute the helpers position 184 181 this.position = this.generatePosition(e); 185 182 this.positionAbs = this.convertPositionTo("absolute"); 186 183 187 184 //Call plugins and callbacks and use the resulting position if something is returned 188 185 this.position = this.propagate("drag", e) || this.position; … … 191 188 if(!this.options.axis || this.options.axis == "y") this.helper[0].style.top = this.position.top+'px'; 192 189 if($.ui.ddmanager) $.ui.ddmanager.drag(this, e); 190 193 191 return false; 194 195 192 }, 196 193 mouseStop: function(e) { … … 210 207 this.clear(); 211 208 } 212 209 213 210 return false; 214 215 211 }, 216 212 clear: function() { … … 261 257 } 262 258 }); 263 259 264 260 $.ui.plugin.add("draggable", "zIndex", { 265 261 start: function(e, ui) { … … 272 268 } 273 269 }); 274 270 275 271 $.ui.plugin.add("draggable", "opacity", { 276 272 start: function(e, ui) { … … 307 303 o.scrollSensitivity = o.scrollSensitivity || 20; 308 304 o.scrollSpeed = o.scrollSpeed || 20; 309 305 310 306 i.overflowY = function(el) { 311 307 do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode); … … 325 321 var o = ui.options; 326 322 var i = $(this).data("draggable"); 327 323 328 324 if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') { 329 325 if((i.overflowYOffset.top + i.overflowY[0].offsetHeight) - e.pageY < o.scrollSensitivity) … … 350 346 $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); 351 347 } 352 348 353 349 } 354 350 }); … … 370 366 }, 371 367 drag: function(e, ui) { 372 368 373 369 var inst = $(this).data("draggable"); 374 370 var d = ui.options.snapTolerance || 20; 375 371 var x1 = ui.absolutePosition.left, x2 = x1 + inst.helperProportions.width, 376 372 y1 = ui.absolutePosition.top, y2 = y1 + inst.helperProportions.height; 377 373 378 374 for (var i = inst.snapElements.length - 1; i >= 0; i--){ 379 375 380 376 var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width, 381 377 t = inst.snapElements[i].top, b = t + inst.snapElements[i].height; 382 378 383 379 //Yes, I know, this is insane ;) 384 380 if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) continue; 385 381 386 382 if(ui.options.snapMode != 'inner') { 387 383 var ts = Math.abs(t - y2) <= 20; … … 405 401 if(rs) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left; 406 402 } 407 403 408 404 }; 409 405 } … … 451 447 var height = inst.options.placeholderElement ? $(inst.options.placeholderElement, $(inst.options.items, inst.element)).innerHeight() : $(inst.options.items, inst.element).innerHeight(); 452 448 var width = inst.options.placeholderElement ? $(inst.options.placeholderElement, $(inst.options.items, inst.element)).innerWidth() : $(inst.options.items, inst.element).innerWidth(); 453 449 454 450 //Now we fake the start of dragging for the sortable instance, 455 451 //by cloning the list group item, appending it to the sortable and using it as inst.currentItem … … 471 467 472 468 } 473 469 474 470 //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable 475 471 if(inst.currentItem) inst.drag(e);
