wp/wp-includes/js/jquery/ui/draggable.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     1 /*!
     1 /*!
     2  * jQuery UI Draggable 1.13.1
     2  * jQuery UI Draggable 1.13.3
     3  * http://jqueryui.com
     3  * https://jqueryui.com
     4  *
     4  *
     5  * Copyright jQuery Foundation and other contributors
     5  * Copyright OpenJS Foundation and other contributors
     6  * Released under the MIT license.
     6  * Released under the MIT license.
     7  * http://jquery.org/license
     7  * https://jquery.org/license
     8  */
     8  */
     9 
     9 
    10 //>>label: Draggable
    10 //>>label: Draggable
    11 //>>group: Interactions
    11 //>>group: Interactions
    12 //>>description: Enables dragging functionality for any element.
    12 //>>description: Enables dragging functionality for any element.
    13 //>>docs: http://api.jqueryui.com/draggable/
    13 //>>docs: https://api.jqueryui.com/draggable/
    14 //>>demos: http://jqueryui.com/draggable/
    14 //>>demos: https://jqueryui.com/draggable/
    15 //>>css.structure: ../../themes/base/draggable.css
    15 //>>css.structure: ../../themes/base/draggable.css
    16 
    16 
    17 ( function( factory ) {
    17 ( function( factory ) {
    18 	"use strict";
    18 	"use strict";
    19 
    19 
    21 
    21 
    22 		// AMD. Register as an anonymous module.
    22 		// AMD. Register as an anonymous module.
    23 		define( [
    23 		define( [
    24 			"jquery",
    24 			"jquery",
    25 			"./mouse",
    25 			"./mouse",
    26 			"./core"
    26 			"../data",
       
    27 			"../plugin",
       
    28 			"../safe-active-element",
       
    29 			"../safe-blur",
       
    30 			"../scroll-parent",
       
    31 			"../version",
       
    32 			"../widget"
    27 		], factory );
    33 		], factory );
    28 	} else {
    34 	} else {
    29 
    35 
    30 		// Browser globals
    36 		// Browser globals
    31 		factory( jQuery );
    37 		factory( jQuery );
    32 	}
    38 	}
    33 } )( function( $ ) {
    39 } )( function( $ ) {
    34 "use strict";
    40 "use strict";
    35 
    41 
    36 $.widget( "ui.draggable", $.ui.mouse, {
    42 $.widget( "ui.draggable", $.ui.mouse, {
    37 	version: "1.13.1",
    43 	version: "1.13.3",
    38 	widgetEventPrefix: "drag",
    44 	widgetEventPrefix: "drag",
    39 	options: {
    45 	options: {
    40 		addClasses: true,
    46 		addClasses: true,
    41 		appendTo: "parent",
    47 		appendTo: "parent",
    42 		axis: false,
    48 		axis: false,
   100 	_mouseCapture: function( event ) {
   106 	_mouseCapture: function( event ) {
   101 		var o = this.options;
   107 		var o = this.options;
   102 
   108 
   103 		// Among others, prevent a drag on a resizable-handle
   109 		// Among others, prevent a drag on a resizable-handle
   104 		if ( this.helper || o.disabled ||
   110 		if ( this.helper || o.disabled ||
   105 			$( event.target ).closest( ".ui-resizable-handle" ).length > 0 ) {
   111 				$( event.target ).closest( ".ui-resizable-handle" ).length > 0 ) {
   106 			return false;
   112 			return false;
   107 		}
   113 		}
   108 
   114 
   109 		//Quit if we're not on a valid handle
   115 		//Quit if we're not on a valid handle
   110 		this.handle = this._getHandle( event );
   116 		this.handle = this._getHandle( event );
   183 		//Store the helper's css position
   189 		//Store the helper's css position
   184 		this.cssPosition = this.helper.css( "position" );
   190 		this.cssPosition = this.helper.css( "position" );
   185 		this.scrollParent = this.helper.scrollParent( true );
   191 		this.scrollParent = this.helper.scrollParent( true );
   186 		this.offsetParent = this.helper.offsetParent();
   192 		this.offsetParent = this.helper.offsetParent();
   187 		this.hasFixedAncestor = this.helper.parents().filter( function() {
   193 		this.hasFixedAncestor = this.helper.parents().filter( function() {
   188 			return $( this ).css( "position" ) === "fixed";
   194 				return $( this ).css( "position" ) === "fixed";
   189 		} ).length > 0;
   195 			} ).length > 0;
   190 
   196 
   191 		//The element's absolute position on the page minus margins
   197 		//The element's absolute position on the page minus margins
   192 		this.positionAbs = this.element.offset();
   198 		this.positionAbs = this.element.offset();
   193 		this._refreshOffsets( event );
   199 		this._refreshOffsets( event );
   194 
   200 
   292 			dropped = this.dropped;
   298 			dropped = this.dropped;
   293 			this.dropped = false;
   299 			this.dropped = false;
   294 		}
   300 		}
   295 
   301 
   296 		if ( ( this.options.revert === "invalid" && !dropped ) ||
   302 		if ( ( this.options.revert === "invalid" && !dropped ) ||
   297 			( this.options.revert === "valid" && dropped ) ||
   303 				( this.options.revert === "valid" && dropped ) ||
   298 			this.options.revert === true || ( typeof this.options.revert === "function" &&
   304 				this.options.revert === true || ( typeof this.options.revert === "function" &&
   299 				this.options.revert.call( this.element, dropped ) )
   305 				this.options.revert.call( this.element, dropped ) )
   300 		) {
   306 		) {
   301 			$( this.helper ).animate(
   307 			$( this.helper ).animate(
   302 				this.originalPosition,
   308 				this.originalPosition,
   303 				parseInt( this.options.revertDuration, 10 ),
   309 				parseInt( this.options.revertDuration, 10 ),
   378 			helper.appendTo( ( o.appendTo === "parent" ?
   384 			helper.appendTo( ( o.appendTo === "parent" ?
   379 				this.element[ 0 ].parentNode :
   385 				this.element[ 0 ].parentNode :
   380 				o.appendTo ) );
   386 				o.appendTo ) );
   381 		}
   387 		}
   382 
   388 
   383 		// Http://bugs.jqueryui.com/ticket/9446
   389 		// https://bugs.jqueryui.com/ticket/9446
   384 		// a helper function can return the original element
   390 		// a helper function can return the original element
   385 		// which wouldn't have been set to relative in _create
   391 		// which wouldn't have been set to relative in _create
   386 		if ( helperIsFunction && helper[ 0 ] === this.element[ 0 ] ) {
   392 		if ( helperIsFunction && helper[ 0 ] === this.element[ 0 ] ) {
   387 			this._setPositionRelative();
   393 			this._setPositionRelative();
   388 		}
   394 		}
   389 
   395 
   390 		if ( helper[ 0 ] !== this.element[ 0 ] &&
   396 		if ( helper[ 0 ] !== this.element[ 0 ] &&
   391 			!( /(fixed|absolute)/ ).test( helper.css( "position" ) ) ) {
   397 				!( /(fixed|absolute)/ ).test( helper.css( "position" ) ) ) {
   392 			helper.css( "position", "absolute" );
   398 			helper.css( "position", "absolute" );
   393 		}
   399 		}
   394 
   400 
   395 		return helper;
   401 		return helper;
   396 
   402 
   439 		// next positioned parent
   445 		// next positioned parent
   440 		// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't
   446 		// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't
   441 		// the document, which means that the scroll is included in the initial calculation of the
   447 		// the document, which means that the scroll is included in the initial calculation of the
   442 		// offset of the parent, and never recalculated upon drag
   448 		// offset of the parent, and never recalculated upon drag
   443 		if ( this.cssPosition === "absolute" && this.scrollParent[ 0 ] !== document &&
   449 		if ( this.cssPosition === "absolute" && this.scrollParent[ 0 ] !== document &&
   444 			$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) {
   450 				$.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) {
   445 			po.left += this.scrollParent.scrollLeft();
   451 			po.left += this.scrollParent.scrollLeft();
   446 			po.top += this.scrollParent.scrollTop();
   452 			po.top += this.scrollParent.scrollTop();
   447 		}
   453 		}
   448 
   454 
   449 		if ( this._isRootNode( this.offsetParent[ 0 ] ) ) {
   455 		if ( this._isRootNode( this.offsetParent[ 0 ] ) ) {
   506 		if ( o.containment === "window" ) {
   512 		if ( o.containment === "window" ) {
   507 			this.containment = [
   513 			this.containment = [
   508 				$( window ).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
   514 				$( window ).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
   509 				$( window ).scrollTop() - this.offset.relative.top - this.offset.parent.top,
   515 				$( window ).scrollTop() - this.offset.relative.top - this.offset.parent.top,
   510 				$( window ).scrollLeft() + $( window ).width() -
   516 				$( window ).scrollLeft() + $( window ).width() -
   511 				this.helperProportions.width - this.margins.left,
   517 					this.helperProportions.width - this.margins.left,
   512 				$( window ).scrollTop() +
   518 				$( window ).scrollTop() +
   513 				( $( window ).height() || document.body.parentNode.scrollHeight ) -
   519 					( $( window ).height() || document.body.parentNode.scrollHeight ) -
   514 				this.helperProportions.height - this.margins.top
   520 					this.helperProportions.height - this.margins.top
   515 			];
   521 			];
   516 			return;
   522 			return;
   517 		}
   523 		}
   518 
   524 
   519 		if ( o.containment === "document" ) {
   525 		if ( o.containment === "document" ) {
   520 			this.containment = [
   526 			this.containment = [
   521 				0,
   527 				0,
   522 				0,
   528 				0,
   523 				$( document ).width() - this.helperProportions.width - this.margins.left,
   529 				$( document ).width() - this.helperProportions.width - this.margins.left,
   524 				( $( document ).height() || document.body.parentNode.scrollHeight ) -
   530 				( $( document ).height() || document.body.parentNode.scrollHeight ) -
   525 				this.helperProportions.height - this.margins.top
   531 					this.helperProportions.height - this.margins.top
   526 			];
   532 			];
   527 			return;
   533 			return;
   528 		}
   534 		}
   529 
   535 
   530 		if ( o.containment.constructor === Array ) {
   536 		if ( o.containment.constructor === Array ) {
   545 
   551 
   546 		isUserScrollable = /(scroll|auto)/.test( c.css( "overflow" ) );
   552 		isUserScrollable = /(scroll|auto)/.test( c.css( "overflow" ) );
   547 
   553 
   548 		this.containment = [
   554 		this.containment = [
   549 			( parseInt( c.css( "borderLeftWidth" ), 10 ) || 0 ) +
   555 			( parseInt( c.css( "borderLeftWidth" ), 10 ) || 0 ) +
   550 			( parseInt( c.css( "paddingLeft" ), 10 ) || 0 ),
   556 				( parseInt( c.css( "paddingLeft" ), 10 ) || 0 ),
   551 			( parseInt( c.css( "borderTopWidth" ), 10 ) || 0 ) +
   557 			( parseInt( c.css( "borderTopWidth" ), 10 ) || 0 ) +
   552 			( parseInt( c.css( "paddingTop" ), 10 ) || 0 ),
   558 				( parseInt( c.css( "paddingTop" ), 10 ) || 0 ),
   553 			( isUserScrollable ? Math.max( ce.scrollWidth, ce.offsetWidth ) : ce.offsetWidth ) -
   559 			( isUserScrollable ? Math.max( ce.scrollWidth, ce.offsetWidth ) : ce.offsetWidth ) -
   554 			( parseInt( c.css( "borderRightWidth" ), 10 ) || 0 ) -
   560 				( parseInt( c.css( "borderRightWidth" ), 10 ) || 0 ) -
   555 			( parseInt( c.css( "paddingRight" ), 10 ) || 0 ) -
   561 				( parseInt( c.css( "paddingRight" ), 10 ) || 0 ) -
   556 			this.helperProportions.width -
   562 				this.helperProportions.width -
   557 			this.margins.left -
   563 				this.margins.left -
   558 			this.margins.right,
   564 				this.margins.right,
   559 			( isUserScrollable ? Math.max( ce.scrollHeight, ce.offsetHeight ) : ce.offsetHeight ) -
   565 			( isUserScrollable ? Math.max( ce.scrollHeight, ce.offsetHeight ) : ce.offsetHeight ) -
   560 			( parseInt( c.css( "borderBottomWidth" ), 10 ) || 0 ) -
   566 				( parseInt( c.css( "borderBottomWidth" ), 10 ) || 0 ) -
   561 			( parseInt( c.css( "paddingBottom" ), 10 ) || 0 ) -
   567 				( parseInt( c.css( "paddingBottom" ), 10 ) || 0 ) -
   562 			this.helperProportions.height -
   568 				this.helperProportions.height -
   563 			this.margins.top -
   569 				this.margins.top -
   564 			this.margins.bottom
   570 				this.margins.bottom
   565 		];
   571 		];
   566 		this.relativeContainer = c;
   572 		this.relativeContainer = c;
   567 	},
   573 	},
   568 
   574 
   569 	_convertPositionTo: function( d, pos ) {
   575 	_convertPositionTo: function( d, pos ) {
   664 				// argument errors in IE (see ticket #6950)
   670 				// argument errors in IE (see ticket #6950)
   665 				top = o.grid[ 1 ] ? this.originalPageY + Math.round( ( pageY -
   671 				top = o.grid[ 1 ] ? this.originalPageY + Math.round( ( pageY -
   666 					this.originalPageY ) / o.grid[ 1 ] ) * o.grid[ 1 ] : this.originalPageY;
   672 					this.originalPageY ) / o.grid[ 1 ] ) * o.grid[ 1 ] : this.originalPageY;
   667 				pageY = containment ? ( ( top - this.offset.click.top >= containment[ 1 ] ||
   673 				pageY = containment ? ( ( top - this.offset.click.top >= containment[ 1 ] ||
   668 					top - this.offset.click.top > containment[ 3 ] ) ?
   674 					top - this.offset.click.top > containment[ 3 ] ) ?
   669 					top :
   675 						top :
   670 					( ( top - this.offset.click.top >= containment[ 1 ] ) ?
   676 						( ( top - this.offset.click.top >= containment[ 1 ] ) ?
   671 						top - o.grid[ 1 ] : top + o.grid[ 1 ] ) ) : top;
   677 							top - o.grid[ 1 ] : top + o.grid[ 1 ] ) ) : top;
   672 
   678 
   673 				left = o.grid[ 0 ] ? this.originalPageX +
   679 				left = o.grid[ 0 ] ? this.originalPageX +
   674 					Math.round( ( pageX - this.originalPageX ) / o.grid[ 0 ] ) * o.grid[ 0 ] :
   680 					Math.round( ( pageX - this.originalPageX ) / o.grid[ 0 ] ) * o.grid[ 0 ] :
   675 					this.originalPageX;
   681 					this.originalPageX;
   676 				pageX = containment ? ( ( left - this.offset.click.left >= containment[ 0 ] ||
   682 				pageX = containment ? ( ( left - this.offset.click.left >= containment[ 0 ] ||
   677 					left - this.offset.click.left > containment[ 2 ] ) ?
   683 					left - this.offset.click.left > containment[ 2 ] ) ?
   678 					left :
   684 						left :
   679 					( ( left - this.offset.click.left >= containment[ 0 ] ) ?
   685 						( ( left - this.offset.click.left >= containment[ 0 ] ) ?
   680 						left - o.grid[ 0 ] : left + o.grid[ 0 ] ) ) : left;
   686 							left - o.grid[ 0 ] : left + o.grid[ 0 ] ) ) : left;
   681 			}
   687 			}
   682 
   688 
   683 			if ( o.axis === "y" ) {
   689 			if ( o.axis === "y" ) {
   684 				pageX = this.originalPageX;
   690 				pageX = this.originalPageX;
   685 			}
   691 			}
   849 					this.positionAbs = draggable.positionAbs;
   855 					this.positionAbs = draggable.positionAbs;
   850 					this.helperProportions = draggable.helperProportions;
   856 					this.helperProportions = draggable.helperProportions;
   851 					this.offset.click = draggable.offset.click;
   857 					this.offset.click = draggable.offset.click;
   852 
   858 
   853 					if ( this !== sortable &&
   859 					if ( this !== sortable &&
   854 						this._intersectsWith( this.containerCache ) &&
   860 							this._intersectsWith( this.containerCache ) &&
   855 						$.contains( sortable.element[ 0 ], this.element[ 0 ] ) ) {
   861 							$.contains( sortable.element[ 0 ], this.element[ 0 ] ) ) {
   856 						innermostIntersecting = false;
   862 						innermostIntersecting = false;
   857 					}
   863 					}
   858 
   864 
   859 					return innermostIntersecting;
   865 					return innermostIntersecting;
   860 				} );
   866 				} );
  1010 		if ( !i.scrollParentNotHidden ) {
  1016 		if ( !i.scrollParentNotHidden ) {
  1011 			i.scrollParentNotHidden = i.helper.scrollParent( false );
  1017 			i.scrollParentNotHidden = i.helper.scrollParent( false );
  1012 		}
  1018 		}
  1013 
  1019 
  1014 		if ( i.scrollParentNotHidden[ 0 ] !== i.document[ 0 ] &&
  1020 		if ( i.scrollParentNotHidden[ 0 ] !== i.document[ 0 ] &&
  1015 			i.scrollParentNotHidden[ 0 ].tagName !== "HTML" ) {
  1021 				i.scrollParentNotHidden[ 0 ].tagName !== "HTML" ) {
  1016 			i.overflowOffset = i.scrollParentNotHidden.offset();
  1022 			i.overflowOffset = i.scrollParentNotHidden.offset();
  1017 		}
  1023 		}
  1018 	},
  1024 	},
  1019 	drag: function( event, ui, i  ) {
  1025 	drag: function( event, ui, i  ) {
  1020 
  1026 
  1024 			document = i.document[ 0 ];
  1030 			document = i.document[ 0 ];
  1025 
  1031 
  1026 		if ( scrollParent !== document && scrollParent.tagName !== "HTML" ) {
  1032 		if ( scrollParent !== document && scrollParent.tagName !== "HTML" ) {
  1027 			if ( !o.axis || o.axis !== "x" ) {
  1033 			if ( !o.axis || o.axis !== "x" ) {
  1028 				if ( ( i.overflowOffset.top + scrollParent.offsetHeight ) - event.pageY <
  1034 				if ( ( i.overflowOffset.top + scrollParent.offsetHeight ) - event.pageY <
  1029 					o.scrollSensitivity ) {
  1035 						o.scrollSensitivity ) {
  1030 					scrollParent.scrollTop = scrolled = scrollParent.scrollTop + o.scrollSpeed;
  1036 					scrollParent.scrollTop = scrolled = scrollParent.scrollTop + o.scrollSpeed;
  1031 				} else if ( event.pageY - i.overflowOffset.top < o.scrollSensitivity ) {
  1037 				} else if ( event.pageY - i.overflowOffset.top < o.scrollSensitivity ) {
  1032 					scrollParent.scrollTop = scrolled = scrollParent.scrollTop - o.scrollSpeed;
  1038 					scrollParent.scrollTop = scrolled = scrollParent.scrollTop - o.scrollSpeed;
  1033 				}
  1039 				}
  1034 			}
  1040 			}
  1035 
  1041 
  1036 			if ( !o.axis || o.axis !== "y" ) {
  1042 			if ( !o.axis || o.axis !== "y" ) {
  1037 				if ( ( i.overflowOffset.left + scrollParent.offsetWidth ) - event.pageX <
  1043 				if ( ( i.overflowOffset.left + scrollParent.offsetWidth ) - event.pageX <
  1038 					o.scrollSensitivity ) {
  1044 						o.scrollSensitivity ) {
  1039 					scrollParent.scrollLeft = scrolled = scrollParent.scrollLeft + o.scrollSpeed;
  1045 					scrollParent.scrollLeft = scrolled = scrollParent.scrollLeft + o.scrollSpeed;
  1040 				} else if ( event.pageX - i.overflowOffset.left < o.scrollSensitivity ) {
  1046 				} else if ( event.pageX - i.overflowOffset.left < o.scrollSensitivity ) {
  1041 					scrollParent.scrollLeft = scrolled = scrollParent.scrollLeft - o.scrollSpeed;
  1047 					scrollParent.scrollLeft = scrolled = scrollParent.scrollLeft - o.scrollSpeed;
  1042 				}
  1048 				}
  1043 			}
  1049 			}
  1046 
  1052 
  1047 			if ( !o.axis || o.axis !== "x" ) {
  1053 			if ( !o.axis || o.axis !== "x" ) {
  1048 				if ( event.pageY - $( document ).scrollTop() < o.scrollSensitivity ) {
  1054 				if ( event.pageY - $( document ).scrollTop() < o.scrollSensitivity ) {
  1049 					scrolled = $( document ).scrollTop( $( document ).scrollTop() - o.scrollSpeed );
  1055 					scrolled = $( document ).scrollTop( $( document ).scrollTop() - o.scrollSpeed );
  1050 				} else if ( $( window ).height() - ( event.pageY - $( document ).scrollTop() ) <
  1056 				} else if ( $( window ).height() - ( event.pageY - $( document ).scrollTop() ) <
  1051 					o.scrollSensitivity ) {
  1057 						o.scrollSensitivity ) {
  1052 					scrolled = $( document ).scrollTop( $( document ).scrollTop() + o.scrollSpeed );
  1058 					scrolled = $( document ).scrollTop( $( document ).scrollTop() + o.scrollSpeed );
  1053 				}
  1059 				}
  1054 			}
  1060 			}
  1055 
  1061 
  1056 			if ( !o.axis || o.axis !== "y" ) {
  1062 			if ( !o.axis || o.axis !== "y" ) {
  1057 				if ( event.pageX - $( document ).scrollLeft() < o.scrollSensitivity ) {
  1063 				if ( event.pageX - $( document ).scrollLeft() < o.scrollSensitivity ) {
  1058 					scrolled = $( document ).scrollLeft(
  1064 					scrolled = $( document ).scrollLeft(
  1059 						$( document ).scrollLeft() - o.scrollSpeed
  1065 						$( document ).scrollLeft() - o.scrollSpeed
  1060 					);
  1066 					);
  1061 				} else if ( $( window ).width() - ( event.pageX - $( document ).scrollLeft() ) <
  1067 				} else if ( $( window ).width() - ( event.pageX - $( document ).scrollLeft() ) <
  1062 					o.scrollSensitivity ) {
  1068 						o.scrollSensitivity ) {
  1063 					scrolled = $( document ).scrollLeft(
  1069 					scrolled = $( document ).scrollLeft(
  1064 						$( document ).scrollLeft() + o.scrollSpeed
  1070 						$( document ).scrollLeft() + o.scrollSpeed
  1065 					);
  1071 					);
  1066 				}
  1072 				}
  1067 			}
  1073 			}
  1110 			r = l + inst.snapElements[ i ].width;
  1116 			r = l + inst.snapElements[ i ].width;
  1111 			t = inst.snapElements[ i ].top - inst.margins.top;
  1117 			t = inst.snapElements[ i ].top - inst.margins.top;
  1112 			b = t + inst.snapElements[ i ].height;
  1118 			b = t + inst.snapElements[ i ].height;
  1113 
  1119 
  1114 			if ( x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d ||
  1120 			if ( x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d ||
  1115 				!$.contains( inst.snapElements[ i ].item.ownerDocument,
  1121 					!$.contains( inst.snapElements[ i ].item.ownerDocument,
  1116 					inst.snapElements[ i ].item ) ) {
  1122 					inst.snapElements[ i ].item ) ) {
  1117 				if ( inst.snapElements[ i ].snapping ) {
  1123 				if ( inst.snapElements[ i ].snapping ) {
  1118 					if ( inst.options.snap.release ) {
  1124 					if ( inst.options.snap.release ) {
  1119 						inst.options.snap.release.call(
  1125 						inst.options.snap.release.call(
  1120 							inst.element,
  1126 							inst.element,