Changeset 28780 for trunk/themes/default/js/ui/jquery.ui.draggable.js
- Timestamp:
- Jun 24, 2014, 10:16:59 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/themes/default/js/ui/jquery.ui.draggable.js
r20824 r28780 1 1 /*! 2 * jQuery UI Draggable 1.10. 12 * jQuery UI Draggable 1.10.4 3 3 * http://jqueryui.com 4 4 * 5 * Copyright 201 3jQuery Foundation and other contributors5 * Copyright 2014 jQuery Foundation and other contributors 6 6 * Released under the MIT license. 7 7 * http://jquery.org/license … … 17 17 18 18 $.widget("ui.draggable", $.ui.mouse, { 19 version: "1.10. 1",19 version: "1.10.4", 20 20 widgetEventPrefix: "drag", 21 21 options: { … … 126 126 127 127 //Store the helper's css position 128 this.cssPosition = this.helper.css( "position");128 this.cssPosition = this.helper.css( "position" ); 129 129 this.scrollParent = this.helper.scrollParent(); 130 this.offsetParent = this.helper.offsetParent(); 131 this.offsetParentCssPosition = this.offsetParent.css( "position" ); 130 132 131 133 //The element's absolute position on the page minus margins … … 135 137 left: this.offset.left - this.margins.left 136 138 }; 139 140 //Reset scroll cache 141 this.offset.scroll = false; 137 142 138 143 $.extend(this.offset, { … … 154 159 155 160 //Set a containment if given in the options 156 if(o.containment) { 157 this._setContainment(); 158 } 161 this._setContainment(); 159 162 160 163 //Trigger event + callbacks … … 184 187 185 188 _mouseDrag: function(event, noPropagation) { 189 // reset any necessary cached properties (see #5009) 190 if ( this.offsetParentCssPosition === "fixed" ) { 191 this.offset.parent = this._getParentOffset(); 192 } 186 193 187 194 //Compute the helpers position … … 215 222 216 223 //If we are using droppables, inform the manager about the drop 217 var element, 218 that = this, 219 elementInDom = false, 224 var that = this, 220 225 dropped = false; 221 226 if ($.ui.ddmanager && !this.options.dropBehaviour) { … … 230 235 231 236 //if the original element is no longer in the DOM don't bother to continue (see #8269) 232 element = this.element[0]; 233 while ( element && (element = element.parentNode) ) { 234 if (element === document ) { 235 elementInDom = true; 236 } 237 } 238 if ( !elementInDom && this.options.helper === "original" ) { 237 if ( this.options.helper === "original" && !$.contains( this.element[ 0 ].ownerDocument, this.element[ 0 ] ) ) { 239 238 return false; 240 239 } … … 282 281 283 282 _getHandle: function(event) { 284 285 var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false; 286 $(this.options.handle, this.element) 287 .find("*") 288 .addBack() 289 .each(function() { 290 if(this === event.target) { 291 handle = true; 292 } 293 }); 294 295 return handle; 296 283 return this.options.handle ? 284 !!$( event.target ).closest( this.element.find( this.options.handle ) ).length : 285 true; 297 286 }, 298 287 … … 338 327 339 328 //Get the offsetParent and cache its position 340 this.offsetParent = this.helper.offsetParent();341 329 var po = this.offsetParent.offset(); 342 330 … … 399 387 o = this.options; 400 388 401 if(o.containment === "parent") { 402 o.containment = this.helper[0].parentNode; 403 } 404 if(o.containment === "document" || o.containment === "window") { 389 if ( !o.containment ) { 390 this.containment = null; 391 return; 392 } 393 394 if ( o.containment === "window" ) { 405 395 this.containment = [ 406 o.containment === "document" ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left,407 o.containment === "document" ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top,408 (o.containment === "document" ? 0 : $(window).scrollLeft()) + $(o.containment === "document" ? document : window).width() - this.helperProportions.width - this.margins.left,409 (o.containment === "document" ? 0 : $(window).scrollTop()) + ($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top396 $( window ).scrollLeft() - this.offset.relative.left - this.offset.parent.left, 397 $( window ).scrollTop() - this.offset.relative.top - this.offset.parent.top, 398 $( window ).scrollLeft() + $( window ).width() - this.helperProportions.width - this.margins.left, 399 $( window ).scrollTop() + ( $( window ).height() || document.body.parentNode.scrollHeight ) - this.helperProportions.height - this.margins.top 410 400 ]; 411 } 412 413 if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor !== Array) { 414 c = $(o.containment); 415 ce = c[0]; 416 417 if(!ce) { 418 return; 419 } 420 421 over = ($(ce).css("overflow") !== "hidden"); 422 401 return; 402 } 403 404 if ( o.containment === "document") { 423 405 this.containment = [ 424 (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0),425 (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0),426 (over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right,427 ( over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom406 0, 407 0, 408 $( document ).width() - this.helperProportions.width - this.margins.left, 409 ( $( document ).height() || document.body.parentNode.scrollHeight ) - this.helperProportions.height - this.margins.top 428 410 ]; 429 this.relative_container = c; 430 431 } else if(o.containment.constructor === Array) { 411 return; 412 } 413 414 if ( o.containment.constructor === Array ) { 432 415 this.containment = o.containment; 433 } 434 416 return; 417 } 418 419 if ( o.containment === "parent" ) { 420 o.containment = this.helper[ 0 ].parentNode; 421 } 422 423 c = $( o.containment ); 424 ce = c[ 0 ]; 425 426 if( !ce ) { 427 return; 428 } 429 430 over = c.css( "overflow" ) !== "hidden"; 431 432 this.containment = [ 433 ( parseInt( c.css( "borderLeftWidth" ), 10 ) || 0 ) + ( parseInt( c.css( "paddingLeft" ), 10 ) || 0 ), 434 ( parseInt( c.css( "borderTopWidth" ), 10 ) || 0 ) + ( parseInt( c.css( "paddingTop" ), 10 ) || 0 ) , 435 ( over ? Math.max( ce.scrollWidth, ce.offsetWidth ) : ce.offsetWidth ) - ( parseInt( c.css( "borderRightWidth" ), 10 ) || 0 ) - ( parseInt( c.css( "paddingRight" ), 10 ) || 0 ) - this.helperProportions.width - this.margins.left - this.margins.right, 436 ( over ? Math.max( ce.scrollHeight, ce.offsetHeight ) : ce.offsetHeight ) - ( parseInt( c.css( "borderBottomWidth" ), 10 ) || 0 ) - ( parseInt( c.css( "paddingBottom" ), 10 ) || 0 ) - this.helperProportions.height - this.margins.top - this.margins.bottom 437 ]; 438 this.relative_container = c; 435 439 }, 436 440 … … 442 446 443 447 var mod = d === "absolute" ? 1 : -1, 444 scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); 448 scroll = this.cssPosition === "absolute" && !( this.scrollParent[ 0 ] !== document && $.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) ? this.offsetParent : this.scrollParent; 449 450 //Cache the scroll 451 if (!this.offset.scroll) { 452 this.offset.scroll = {top : scroll.scrollTop(), left : scroll.scrollLeft()}; 453 } 445 454 446 455 return { … … 449 458 this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent 450 459 this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border) 451 ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)460 ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : this.offset.scroll.top ) * mod ) 452 461 ), 453 462 left: ( … … 455 464 this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent 456 465 this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border) 457 ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)466 ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : this.offset.scroll.left ) * mod ) 458 467 ) 459 468 }; … … 465 474 var containment, co, top, left, 466 475 o = this.options, 467 scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, 468 scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName), 476 scroll = this.cssPosition === "absolute" && !( this.scrollParent[ 0 ] !== document && $.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) ? this.offsetParent : this.scrollParent, 469 477 pageX = event.pageX, 470 478 pageY = event.pageY; 479 480 //Cache the scroll 481 if (!this.offset.scroll) { 482 this.offset.scroll = {top : scroll.scrollTop(), left : scroll.scrollLeft()}; 483 } 471 484 472 485 /* … … 475 488 */ 476 489 477 if(this.originalPosition) { //If we are not dragging yet, we won't check for options 478 if(this.containment) { 479 if (this.relative_container){ 480 co = this.relative_container.offset(); 481 containment = [ this.containment[0] + co.left, 482 this.containment[1] + co.top, 483 this.containment[2] + co.left, 484 this.containment[3] + co.top ]; 485 } 486 else { 487 containment = this.containment; 488 } 490 // If we are not dragging yet, we won't check for options 491 if ( this.originalPosition ) { 492 if ( this.containment ) { 493 if ( this.relative_container ){ 494 co = this.relative_container.offset(); 495 containment = [ 496 this.containment[ 0 ] + co.left, 497 this.containment[ 1 ] + co.top, 498 this.containment[ 2 ] + co.left, 499 this.containment[ 3 ] + co.top 500 ]; 501 } 502 else { 503 containment = this.containment; 504 } 489 505 490 506 if(event.pageX - this.offset.click.left < containment[0]) { … … 519 535 this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent 520 536 this.offset.parent.top + // The offsetParent's offset without borders (offset + border) 521 ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))537 ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : this.offset.scroll.top ) 522 538 ), 523 539 left: ( … … 526 542 this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent 527 543 this.offset.parent.left + // The offsetParent's offset without borders (offset + border) 528 ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))544 ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : this.offset.scroll.left ) 529 545 ) 530 546 }; … … 601 617 //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: "valid/invalid" 602 618 if(this.shouldRevert) { 603 this.instance.options.revert = t rue;619 this.instance.options.revert = this.shouldRevert; 604 620 } 605 621 … … 848 864 b = t + inst.snapElements[i].height; 849 865 850 //Yes, I know, this is insane ;) 851 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))) { 866 if ( x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d || !$.contains( inst.snapElements[ i ].item.ownerDocument, inst.snapElements[ i ].item ) ) { 852 867 if(inst.snapElements[i].snapping) { 853 868 (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
Note: See TracChangeset
for help on using the changeset viewer.