2012-02-27 00:49:51 +00:00
/ * !
2008-09-04 22:03:30 +00:00
* jQuery UI Draggable @ VERSION
2012-07-04 13:08:08 +00:00
* http : //jqueryui.com
2008-06-04 02:34:33 +00:00
*
2014-01-29 03:25:02 +00:00
* Copyright 2014 jQuery Foundation and other contributors
2012-08-09 14:13:24 +00:00
* Released under the MIT license .
2010-07-09 13:01:04 +00:00
* http : //jquery.org/license
2008-11-10 05:18:20 +00:00
*
2012-09-26 23:06:20 +00:00
* http : //api.jqueryui.com/draggable/
2008-06-04 02:34:33 +00:00
* /
2013-07-12 16:40:48 +00:00
( function ( factory ) {
if ( typeof define === "function" && define . amd ) {
// AMD. Register as an anonymous module.
define ( [
"jquery" ,
2013-12-02 18:36:12 +00:00
"./core" ,
"./mouse" ,
"./widget"
2013-07-12 16:40:48 +00:00
] , factory ) ;
} else {
// Browser globals
factory ( jQuery ) ;
}
} ( function ( $ ) {
2008-06-04 02:34:33 +00:00
2010-01-07 03:19:50 +00:00
$ . widget ( "ui.draggable" , $ . ui . mouse , {
2011-05-28 19:39:55 +00:00
version : "@VERSION" ,
2010-02-05 03:03:50 +00:00
widgetEventPrefix : "drag" ,
2010-01-07 03:19:50 +00:00
options : {
addClasses : true ,
appendTo : "parent" ,
axis : false ,
connectToSortable : false ,
containment : false ,
cursor : "auto" ,
cursorAt : false ,
grid : false ,
handle : false ,
helper : "original" ,
iframeFix : false ,
opacity : false ,
refreshPositions : false ,
revert : false ,
revertDuration : 500 ,
scope : "default" ,
scroll : true ,
scrollSensitivity : 20 ,
scrollSpeed : 20 ,
snap : false ,
snapMode : "both" ,
snapTolerance : 20 ,
stack : false ,
2013-01-02 23:27:22 +00:00
zIndex : false ,
// callbacks
drag : null ,
start : null ,
stop : null
2010-01-07 03:19:50 +00:00
} ,
2010-01-15 18:58:20 +00:00
_create : function ( ) {
2008-11-10 05:18:20 +00:00
2012-12-25 17:01:09 +00:00
if ( this . options . helper === "original" && ! ( /^(?:r|a|f)/ ) . test ( this . element . css ( "position" ) ) ) {
this . element [ 0 ] . style . position = "relative" ;
2012-11-18 16:44:12 +00:00
}
if ( this . options . addClasses ) {
this . element . addClass ( "ui-draggable" ) ;
}
if ( this . options . disabled ) {
this . element . addClass ( "ui-draggable-disabled" ) ;
}
2013-12-13 03:10:06 +00:00
this . _setHandleClassName ( ) ;
2008-11-10 05:18:20 +00:00
2008-08-17 08:15:49 +00:00
this . _mouseInit ( ) ;
2013-12-13 03:10:06 +00:00
} ,
2008-11-10 05:18:20 +00:00
2013-12-13 03:10:06 +00:00
_setOption : function ( key , value ) {
this . _super ( key , value ) ;
if ( key === "handle" ) {
2014-07-15 19:16:26 +00:00
this . _removeHandleClassName ( ) ;
2013-12-13 03:10:06 +00:00
this . _setHandleClassName ( ) ;
}
2008-06-04 02:34:33 +00:00
} ,
2008-11-10 05:18:20 +00:00
2012-05-24 19:10:49 +00:00
_destroy : function ( ) {
2013-03-27 20:47:57 +00:00
if ( ( this . helper || this . element ) . is ( ".ui-draggable-dragging" ) ) {
this . destroyOnClear = true ;
return ;
}
2012-05-24 19:10:49 +00:00
this . element . removeClass ( "ui-draggable ui-draggable-dragging ui-draggable-disabled" ) ;
2013-12-13 03:10:06 +00:00
this . _removeHandleClassName ( ) ;
2008-11-21 04:01:33 +00:00
this . _mouseDestroy ( ) ;
} ,
2008-11-14 03:00:16 +00:00
_mouseCapture : function ( event ) {
2008-11-10 05:18:20 +00:00
2013-08-28 13:17:01 +00:00
var document = this . document [ 0 ] ,
o = this . options ;
2008-11-10 05:18:20 +00:00
2013-08-28 13:17:01 +00:00
// support: IE9
// IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
try {
// Support: IE9+
// If the <body> is blurred, IE will switch windows, see #9520
if ( document . activeElement && document . activeElement . nodeName . toLowerCase ( ) !== "body" ) {
// Blur any element that currently has focus, see #4261
$ ( document . activeElement ) . blur ( ) ;
}
} catch ( error ) { }
2013-05-01 22:01:32 +00:00
2009-08-06 18:10:10 +00:00
// among others, prevent a drag on a resizable-handle
2012-12-25 17:01:09 +00:00
if ( this . helper || o . disabled || $ ( event . target ) . closest ( ".ui-resizable-handle" ) . length > 0 ) {
2008-07-17 15:04:42 +00:00
return false ;
2012-11-18 16:44:12 +00:00
}
2008-11-10 05:18:20 +00:00
2008-09-15 20:26:42 +00:00
//Quit if we're not on a valid handle
2008-11-23 17:42:24 +00:00
this . handle = this . _getHandle ( event ) ;
2012-11-18 16:44:12 +00:00
if ( ! this . handle ) {
2008-09-15 20:26:42 +00:00
return false ;
2012-11-18 16:44:12 +00:00
}
2012-10-22 01:50:03 +00:00
2011-04-19 21:39:58 +00:00
$ ( o . iframeFix === true ? "iframe" : o . iframeFix ) . each ( function ( ) {
2012-12-25 17:01:09 +00:00
$ ( "<div class='ui-draggable-iframeFix' style='background: #fff;'></div>" )
2011-04-19 21:39:58 +00:00
. css ( {
2014-02-17 21:08:41 +00:00
width : this . offsetWidth + "px" , height : this . offsetHeight + "px" ,
2011-04-19 21:39:58 +00:00
position : "absolute" , opacity : "0.001" , zIndex : 1000
} )
. css ( $ ( this ) . offset ( ) )
. appendTo ( "body" ) ;
} ) ;
2008-11-10 05:18:20 +00:00
2008-09-16 13:02:21 +00:00
return true ;
2008-11-10 05:18:20 +00:00
2008-09-16 13:02:21 +00:00
} ,
2008-11-10 05:18:20 +00:00
2008-11-14 03:00:16 +00:00
_mouseStart : function ( event ) {
2008-11-10 05:18:20 +00:00
2008-09-16 13:02:21 +00:00
var o = this . options ;
2008-11-10 05:18:20 +00:00
2008-09-15 20:26:42 +00:00
//Create and append the visible helper
2008-11-23 17:42:24 +00:00
this . helper = this . _createHelper ( event ) ;
2008-11-28 15:43:32 +00:00
2012-05-24 18:30:55 +00:00
this . helper . addClass ( "ui-draggable-dragging" ) ;
2008-11-23 17:42:24 +00:00
//Cache the helper size
this . _cacheHelperProportions ( ) ;
2008-11-10 05:18:20 +00:00
2008-09-15 20:26:42 +00:00
//If ddmanager is used for droppables, set the global draggable
2014-02-17 21:08:41 +00:00
if ( $ . ui . ddmanager ) {
2008-07-17 15:04:42 +00:00
$ . ui . ddmanager . current = this ;
2012-11-18 16:44:12 +00:00
}
2008-11-10 05:18:20 +00:00
2008-06-04 02:34:33 +00:00
/ *
* - Position generation -
* This block generates everything position related - it ' s the core of draggables .
* /
2008-11-10 05:18:20 +00:00
2008-11-23 17:42:24 +00:00
//Cache the margins of the original element
this . _cacheMargins ( ) ;
2008-11-10 05:18:20 +00:00
2008-11-23 17:42:24 +00:00
//Store the helper's css position
2013-04-03 16:26:39 +00:00
this . cssPosition = this . helper . css ( "position" ) ;
2014-08-10 03:00:58 +00:00
this . scrollParent = this . helper . scrollParent ( true ) ;
2013-04-03 16:26:39 +00:00
this . offsetParent = this . helper . offsetParent ( ) ;
this . offsetParentCssPosition = this . offsetParent . css ( "position" ) ;
2008-11-28 15:43:32 +00:00
2008-11-23 17:42:24 +00:00
//The element's absolute position on the page minus margins
2009-08-22 08:10:19 +00:00
this . offset = this . positionAbs = this . element . offset ( ) ;
2008-11-23 17:42:24 +00:00
this . offset = {
2008-06-04 02:34:33 +00:00
top : this . offset . top - this . margins . top ,
left : this . offset . left - this . margins . left
} ;
2008-11-10 05:18:20 +00:00
2013-03-14 18:21:24 +00:00
//Reset scroll cache
this . offset . scroll = false ;
2008-11-23 17:42:24 +00:00
$ . extend ( this . offset , {
click : { //Where the click happened, relative to the element
left : event . pageX - this . offset . left ,
top : event . pageY - this . offset . top
} ,
parent : this . _getParentOffset ( ) ,
relative : this . _getRelativeOffset ( ) //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
} ) ;
2008-11-28 15:43:32 +00:00
2008-09-15 20:26:42 +00:00
//Generate the original position
2013-10-21 14:48:54 +00:00
this . originalPosition = this . position = this . _generatePosition ( event , false ) ;
2009-01-08 12:37:15 +00:00
this . originalPageX = event . pageX ;
this . originalPageY = event . pageY ;
2008-11-10 05:18:20 +00:00
2012-12-25 17:01:09 +00:00
//Adjust the mouse offset relative to the helper if "cursorAt" is supplied
2009-08-03 13:13:13 +00:00
( o . cursorAt && this . _adjustOffsetFromHelper ( o . cursorAt ) ) ;
2009-01-08 13:39:58 +00:00
2008-11-23 17:42:24 +00:00
//Set a containment if given in the options
2013-03-23 02:12:52 +00:00
this . _setContainment ( ) ;
2008-11-10 05:18:20 +00:00
2010-01-28 16:35:59 +00:00
//Trigger event + callbacks
2014-02-17 21:08:41 +00:00
if ( this . _trigger ( "start" , event ) === false ) {
2010-01-28 16:35:59 +00:00
this . _clear ( ) ;
return false ;
}
2008-11-10 05:18:20 +00:00
2008-09-15 20:26:42 +00:00
//Recache the helper size
2008-11-23 17:42:24 +00:00
this . _cacheHelperProportions ( ) ;
2008-11-10 05:18:20 +00:00
2008-09-15 20:26:42 +00:00
//Prepare the droppable offsets
2012-11-18 16:44:12 +00:00
if ( $ . ui . ddmanager && ! o . dropBehaviour ) {
2008-11-14 03:00:16 +00:00
$ . ui . ddmanager . prepareOffsets ( this , event ) ;
2012-11-18 16:44:12 +00:00
}
2008-11-10 05:18:20 +00:00
2008-11-23 17:42:24 +00:00
this . _mouseDrag ( event , true ) ; //Execute the drag once - this causes the helper not to be visible before getting its correct position
2012-10-22 01:50:03 +00:00
2011-05-27 17:01:42 +00:00
//If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
2012-11-18 16:44:12 +00:00
if ( $ . ui . ddmanager ) {
$ . ui . ddmanager . dragStart ( this , event ) ;
}
2012-10-22 01:50:03 +00:00
2008-06-04 02:34:33 +00:00
return true ;
} ,
2008-11-10 05:18:20 +00:00
2008-11-23 17:42:24 +00:00
_mouseDrag : function ( event , noPropagation ) {
2013-04-03 16:26:39 +00:00
// reset any necessary cached properties (see #5009)
if ( this . offsetParentCssPosition === "fixed" ) {
this . offset . parent = this . _getParentOffset ( ) ;
}
2008-11-21 04:01:33 +00:00
//Compute the helpers position
2013-10-21 14:48:54 +00:00
this . position = this . _generatePosition ( event , true ) ;
2008-11-21 04:01:33 +00:00
this . positionAbs = this . _convertPositionTo ( "absolute" ) ;
//Call plugins and callbacks and use the resulting position if something is returned
2009-01-15 19:40:11 +00:00
if ( ! noPropagation ) {
var ui = this . _uiHash ( ) ;
2014-02-17 21:08:41 +00:00
if ( this . _trigger ( "drag" , event , ui ) === false ) {
2010-01-28 16:35:59 +00:00
this . _mouseUp ( { } ) ;
return false ;
}
2009-01-15 19:40:11 +00:00
this . position = ui . position ;
}
2008-11-21 04:01:33 +00:00
2013-10-20 23:33:40 +00:00
this . helper [ 0 ] . style . left = this . position . left + "px" ;
this . helper [ 0 ] . style . top = this . position . top + "px" ;
2014-02-17 21:08:41 +00:00
if ( $ . ui . ddmanager ) {
2012-11-18 16:44:12 +00:00
$ . ui . ddmanager . drag ( this , event ) ;
}
2008-11-21 04:01:33 +00:00
return false ;
} ,
_mouseStop : function ( event ) {
//If we are using droppables, inform the manager about the drop
2013-03-16 18:36:06 +00:00
var that = this ,
2012-11-18 16:44:12 +00:00
dropped = false ;
if ( $ . ui . ddmanager && ! this . options . dropBehaviour ) {
2009-01-08 14:03:34 +00:00
dropped = $ . ui . ddmanager . drop ( this , event ) ;
2012-11-18 16:44:12 +00:00
}
2009-01-22 13:10:18 +00:00
2009-01-08 14:03:34 +00:00
//if a drop comes from outside (a sortable)
2014-02-17 21:08:41 +00:00
if ( this . dropped ) {
2009-01-08 14:03:34 +00:00
dropped = this . dropped ;
this . dropped = false ;
}
2012-10-22 01:50:03 +00:00
2014-02-17 21:08:41 +00:00
if ( ( this . options . revert === "invalid" && ! dropped ) || ( this . options . revert === "valid" && dropped ) || this . options . revert === true || ( $ . isFunction ( this . options . revert ) && this . options . revert . call ( this . element , dropped ) ) ) {
2008-11-21 04:01:33 +00:00
$ ( this . helper ) . animate ( this . originalPosition , parseInt ( this . options . revertDuration , 10 ) , function ( ) {
2014-02-17 21:08:41 +00:00
if ( that . _trigger ( "stop" , event ) !== false ) {
2012-02-12 14:30:05 +00:00
that . _clear ( ) ;
2010-01-28 16:35:59 +00:00
}
2008-11-21 04:01:33 +00:00
} ) ;
} else {
2014-02-17 21:08:41 +00:00
if ( this . _trigger ( "stop" , event ) !== false ) {
2010-01-28 16:35:59 +00:00
this . _clear ( ) ;
}
2008-11-21 04:01:33 +00:00
}
return false ;
} ,
2012-10-22 01:50:03 +00:00
2011-04-19 21:39:58 +00:00
_mouseUp : function ( event ) {
2012-09-06 16:30:11 +00:00
//Remove frame helpers
2012-10-22 01:50:03 +00:00
$ ( "div.ui-draggable-iframeFix" ) . each ( function ( ) {
this . parentNode . removeChild ( this ) ;
2012-09-06 16:30:11 +00:00
} ) ;
2012-10-22 01:50:03 +00:00
2011-05-27 17:01:42 +00:00
//If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
2014-02-17 21:08:41 +00:00
if ( $ . ui . ddmanager ) {
2012-11-18 16:44:12 +00:00
$ . ui . ddmanager . dragStop ( this , event ) ;
}
2012-10-22 01:50:03 +00:00
2013-05-02 19:07:34 +00:00
// The interaction is over; whether or not the click resulted in a drag, focus the element
this . element . focus ( ) ;
2011-04-19 21:39:58 +00:00
return $ . ui . mouse . prototype . _mouseUp . call ( this , event ) ;
} ,
2012-10-22 01:50:03 +00:00
2010-01-28 16:35:59 +00:00
cancel : function ( ) {
2012-10-22 01:50:03 +00:00
2014-02-17 21:08:41 +00:00
if ( this . helper . is ( ".ui-draggable-dragging" ) ) {
2010-01-28 16:35:59 +00:00
this . _mouseUp ( { } ) ;
} else {
this . _clear ( ) ;
}
2012-10-22 01:50:03 +00:00
2010-01-28 16:35:59 +00:00
return this ;
2012-10-22 01:50:03 +00:00
2010-01-28 16:35:59 +00:00
} ,
2008-11-21 04:01:33 +00:00
2008-11-23 17:42:24 +00:00
_getHandle : function ( event ) {
2013-03-08 15:08:46 +00:00
return this . options . handle ?
! ! $ ( event . target ) . closest ( this . element . find ( this . options . handle ) ) . length :
true ;
2008-11-21 04:01:33 +00:00
} ,
2013-12-13 03:10:06 +00:00
_setHandleClassName : function ( ) {
2014-07-15 19:16:26 +00:00
this . handleElement = this . options . handle ?
2014-07-15 17:38:00 +00:00
this . element . find ( this . options . handle ) : this . element ;
2014-07-15 19:16:26 +00:00
this . handleElement . addClass ( "ui-draggable-handle" ) ;
2013-12-13 03:10:06 +00:00
} ,
_removeHandleClassName : function ( ) {
2014-07-15 19:16:26 +00:00
this . handleElement . removeClass ( "ui-draggable-handle" ) ;
2013-12-13 03:10:06 +00:00
} ,
2008-11-23 17:42:24 +00:00
_createHelper : function ( event ) {
2008-11-21 04:01:33 +00:00
2012-11-18 16:44:12 +00:00
var o = this . options ,
2014-02-17 21:08:41 +00:00
helper = $ . isFunction ( o . helper ) ? $ ( o . helper . apply ( this . element [ 0 ] , [ event ] ) ) : ( o . helper === "clone" ? this . element . clone ( ) . removeAttr ( "id" ) : this . element ) ;
2008-11-21 04:01:33 +00:00
2014-02-17 21:08:41 +00:00
if ( ! helper . parents ( "body" ) . length ) {
2012-12-25 17:01:09 +00:00
helper . appendTo ( ( o . appendTo === "parent" ? this . element [ 0 ] . parentNode : o . appendTo ) ) ;
2012-11-18 16:44:12 +00:00
}
2008-11-21 04:01:33 +00:00
2014-02-17 21:08:41 +00:00
if ( helper [ 0 ] !== this . element [ 0 ] && ! ( /(fixed|absolute)/ ) . test ( helper . css ( "position" ) ) ) {
2008-11-21 04:01:33 +00:00
helper . css ( "position" , "absolute" ) ;
2012-11-18 16:44:12 +00:00
}
2008-11-21 04:01:33 +00:00
return helper ;
} ,
2008-11-23 17:42:24 +00:00
_adjustOffsetFromHelper : function ( obj ) {
2012-12-25 17:01:09 +00:00
if ( typeof obj === "string" ) {
obj = obj . split ( " " ) ;
2009-08-03 13:13:13 +00:00
}
if ( $ . isArray ( obj ) ) {
2014-02-17 21:08:41 +00:00
obj = { left : + obj [ 0 ] , top : + obj [ 1 ] || 0 } ;
2009-08-03 13:13:13 +00:00
}
2012-12-25 17:01:09 +00:00
if ( "left" in obj ) {
2009-08-03 13:13:13 +00:00
this . offset . click . left = obj . left + this . margins . left ;
}
2012-12-25 17:01:09 +00:00
if ( "right" in obj ) {
2009-08-03 13:13:13 +00:00
this . offset . click . left = this . helperProportions . width - obj . right + this . margins . left ;
}
2012-12-25 17:01:09 +00:00
if ( "top" in obj ) {
2009-08-03 13:13:13 +00:00
this . offset . click . top = obj . top + this . margins . top ;
}
2012-12-25 17:01:09 +00:00
if ( "bottom" in obj ) {
2009-08-03 13:13:13 +00:00
this . offset . click . top = this . helperProportions . height - obj . bottom + this . margins . top ;
}
2008-09-15 20:26:42 +00:00
} ,
2008-11-28 15:43:32 +00:00
2013-10-29 22:35:42 +00:00
_isRootNode : function ( element ) {
return ( /(html|body)/i ) . test ( element . tagName ) || element === this . document [ 0 ] ;
} ,
2008-11-23 17:42:24 +00:00
_getParentOffset : function ( ) {
2008-11-10 05:18:20 +00:00
2009-01-08 11:19:48 +00:00
//Get the offsetParent and cache its position
2010-06-14 15:20:03 +00:00
var po = this . offsetParent . offset ( ) ,
document = this . document [ 0 ] ;
2009-01-22 13:10:18 +00:00
2009-01-08 11:19:48 +00:00
// This is a special case where we need to modify a offset calculated on start, since the following happened:
// 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
// the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
2014-02-17 21:08:41 +00:00
if ( this . cssPosition === "absolute" && this . scrollParent [ 0 ] !== document && $ . contains ( this . scrollParent [ 0 ] , this . offsetParent [ 0 ] ) ) {
2009-01-08 11:19:48 +00:00
po . left += this . scrollParent . scrollLeft ( ) ;
po . top += this . scrollParent . scrollTop ( ) ;
}
2008-11-23 17:42:24 +00:00
2013-10-29 22:35:42 +00:00
if ( this . _isRootNode ( this . offsetParent [ 0 ] ) ) {
2008-11-28 15:43:32 +00:00
po = { top : 0 , left : 0 } ;
2012-11-18 16:44:12 +00:00
}
2008-11-23 17:42:24 +00:00
return {
2014-08-06 21:51:43 +00:00
top : po . top + ( parseInt ( this . offsetParent . css ( "borderTopWidth" ) , 10 ) || 0 ) ,
left : po . left + ( parseInt ( this . offsetParent . css ( "borderLeftWidth" ) , 10 ) || 0 )
2008-11-23 17:42:24 +00:00
} ;
} ,
2008-11-28 15:43:32 +00:00
2008-11-23 17:42:24 +00:00
_getRelativeOffset : function ( ) {
2013-10-29 22:35:42 +00:00
if ( this . cssPosition !== "relative" ) {
2008-11-23 17:42:24 +00:00
return { top : 0 , left : 0 } ;
}
2008-11-28 15:43:32 +00:00
2013-10-29 22:35:42 +00:00
var p = this . element . position ( ) ,
scrollIsRootNode = this . _isRootNode ( this . scrollParent [ 0 ] ) ;
return {
top : p . top - ( parseInt ( this . helper . css ( "top" ) , 10 ) || 0 ) + ( ! scrollIsRootNode ? this . scrollParent . scrollTop ( ) : 0 ) ,
left : p . left - ( parseInt ( this . helper . css ( "left" ) , 10 ) || 0 ) + ( ! scrollIsRootNode ? this . scrollParent . scrollLeft ( ) : 0 )
} ;
2008-11-23 17:42:24 +00:00
} ,
2008-11-28 15:43:32 +00:00
2008-11-23 17:42:24 +00:00
_cacheMargins : function ( ) {
this . margins = {
2014-08-06 21:51:43 +00:00
left : ( parseInt ( this . element . css ( "marginLeft" ) , 10 ) || 0 ) ,
top : ( parseInt ( this . element . css ( "marginTop" ) , 10 ) || 0 ) ,
right : ( parseInt ( this . element . css ( "marginRight" ) , 10 ) || 0 ) ,
bottom : ( parseInt ( this . element . css ( "marginBottom" ) , 10 ) || 0 )
2008-11-23 17:42:24 +00:00
} ;
} ,
_cacheHelperProportions : function ( ) {
2008-09-15 20:26:42 +00:00
this . helperProportions = {
width : this . helper . outerWidth ( ) ,
height : this . helper . outerHeight ( )
} ;
} ,
2008-11-10 05:18:20 +00:00
2008-11-23 17:42:24 +00:00
_setContainment : function ( ) {
2008-11-10 05:18:20 +00:00
2012-11-18 16:44:12 +00:00
var over , c , ce ,
2010-06-14 15:20:03 +00:00
o = this . options ,
document = this . document [ 0 ] ;
2012-11-18 16:44:12 +00:00
2014-08-06 21:51:43 +00:00
this . relativeContainer = null ;
2014-01-13 22:51:06 +00:00
2013-03-23 02:12:52 +00:00
if ( ! o . containment ) {
this . containment = null ;
return ;
2012-11-18 16:44:12 +00:00
}
2013-03-23 02:12:52 +00:00
if ( o . containment === "window" ) {
2012-11-18 16:44:12 +00:00
this . containment = [
2013-03-23 02:12:52 +00:00
$ ( window ) . scrollLeft ( ) - this . offset . relative . left - this . offset . parent . left ,
$ ( window ) . scrollTop ( ) - this . offset . relative . top - this . offset . parent . top ,
$ ( window ) . scrollLeft ( ) + $ ( window ) . width ( ) - this . helperProportions . width - this . margins . left ,
$ ( window ) . scrollTop ( ) + ( $ ( window ) . height ( ) || document . body . parentNode . scrollHeight ) - this . helperProportions . height - this . margins . top
2012-11-18 16:44:12 +00:00
] ;
2013-03-23 02:12:52 +00:00
return ;
2012-11-18 16:44:12 +00:00
}
2013-03-23 02:12:52 +00:00
if ( o . containment === "document" ) {
2008-09-15 20:26:42 +00:00
this . containment = [
2013-03-23 02:12:52 +00:00
0 ,
0 ,
$ ( document ) . width ( ) - this . helperProportions . width - this . margins . left ,
( $ ( document ) . height ( ) || document . body . parentNode . scrollHeight ) - this . helperProportions . height - this . margins . top
2008-09-15 20:26:42 +00:00
] ;
2013-03-23 02:12:52 +00:00
return ;
}
2011-04-28 14:43:02 +00:00
2013-03-23 02:12:52 +00:00
if ( o . containment . constructor === Array ) {
2009-01-20 10:01:49 +00:00
this . containment = o . containment ;
2013-03-23 02:12:52 +00:00
return ;
}
if ( o . containment === "parent" ) {
o . containment = this . helper [ 0 ] . parentNode ;
2008-09-15 20:26:42 +00:00
}
2008-11-10 05:18:20 +00:00
2013-03-23 02:12:52 +00:00
c = $ ( o . containment ) ;
ce = c [ 0 ] ;
2014-02-17 21:08:41 +00:00
if ( ! ce ) {
2013-03-23 02:12:52 +00:00
return ;
}
over = c . css ( "overflow" ) !== "hidden" ;
this . containment = [
( parseInt ( c . css ( "borderLeftWidth" ) , 10 ) || 0 ) + ( parseInt ( c . css ( "paddingLeft" ) , 10 ) || 0 ) ,
2014-02-17 21:08:41 +00:00
( parseInt ( c . css ( "borderTopWidth" ) , 10 ) || 0 ) + ( parseInt ( c . css ( "paddingTop" ) , 10 ) || 0 ) ,
2013-03-23 02:12:52 +00:00
( 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 ,
( 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
] ;
2014-08-06 21:51:43 +00:00
this . relativeContainer = c ;
2008-09-15 20:26:42 +00:00
} ,
2008-11-10 05:18:20 +00:00
2008-08-17 02:15:55 +00:00
_convertPositionTo : function ( d , pos ) {
2008-11-10 05:18:20 +00:00
2014-02-17 21:08:41 +00:00
if ( ! pos ) {
2012-11-18 16:44:12 +00:00
pos = this . position ;
}
var mod = d === "absolute" ? 1 : - 1 ,
2013-10-29 22:35:42 +00:00
scrollIsRootNode = this . _isRootNode ( this . scrollParent [ 0 ] ) ;
2013-03-14 18:21:24 +00:00
2008-06-04 02:34:33 +00:00
return {
top : (
2012-11-18 16:44:12 +00:00
pos . top + // The absolute mouse position
this . offset . relative . top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
this . offset . parent . top * mod - // The offsetParent's offset without borders (offset + border)
2013-10-29 22:35:42 +00:00
( ( this . cssPosition === "fixed" ? - this . offset . scroll . top : ( scrollIsRootNode ? 0 : this . offset . scroll . top ) ) * mod )
2008-06-04 02:34:33 +00:00
) ,
left : (
2012-11-18 16:44:12 +00:00
pos . left + // The absolute mouse position
this . offset . relative . left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
this . offset . parent . left * mod - // The offsetParent's offset without borders (offset + border)
2013-10-29 22:35:42 +00:00
( ( this . cssPosition === "fixed" ? - this . offset . scroll . left : ( scrollIsRootNode ? 0 : this . offset . scroll . left ) ) * mod )
2008-06-04 02:34:33 +00:00
)
} ;
2009-01-22 13:10:18 +00:00
2008-06-04 02:34:33 +00:00
} ,
2008-11-21 04:01:33 +00:00
2013-10-21 14:48:54 +00:00
_generatePosition : function ( event , constrainPosition ) {
2008-11-10 05:18:20 +00:00
2012-11-18 16:44:12 +00:00
var containment , co , top , left ,
o = this . options ,
2013-10-29 22:35:42 +00:00
scrollIsRootNode = this . _isRootNode ( this . scrollParent [ 0 ] ) ,
2012-11-18 16:44:12 +00:00
pageX = event . pageX ,
pageY = event . pageY ;
2009-01-08 12:37:15 +00:00
2013-10-29 22:35:42 +00:00
// Cache the scroll
if ( ! scrollIsRootNode || ! this . offset . scroll ) {
this . offset . scroll = {
top : this . scrollParent . scrollTop ( ) ,
left : this . scrollParent . scrollLeft ( )
} ;
2013-03-14 18:21:24 +00:00
}
2009-01-08 12:37:15 +00:00
/ *
* - Position constraining -
* Constrain the position to a mix of grid , containment .
* /
2009-01-22 13:10:18 +00:00
2013-03-23 02:12:52 +00:00
// If we are not dragging yet, we won't check for options
2013-10-21 14:48:54 +00:00
if ( constrainPosition ) {
2013-03-23 02:12:52 +00:00
if ( this . containment ) {
2014-08-06 21:51:43 +00:00
if ( this . relativeContainer ) {
co = this . relativeContainer . offset ( ) ;
2013-03-23 02:12:52 +00:00
containment = [
this . containment [ 0 ] + co . left ,
this . containment [ 1 ] + co . top ,
this . containment [ 2 ] + co . left ,
this . containment [ 3 ] + co . top
] ;
2014-02-17 21:08:41 +00:00
} else {
2013-03-23 02:12:52 +00:00
containment = this . containment ;
}
2011-04-28 14:43:02 +00:00
2014-02-17 21:08:41 +00:00
if ( event . pageX - this . offset . click . left < containment [ 0 ] ) {
2012-11-18 16:44:12 +00:00
pageX = containment [ 0 ] + this . offset . click . left ;
}
2014-02-17 21:08:41 +00:00
if ( event . pageY - this . offset . click . top < containment [ 1 ] ) {
2012-11-18 16:44:12 +00:00
pageY = containment [ 1 ] + this . offset . click . top ;
}
2014-02-17 21:08:41 +00:00
if ( event . pageX - this . offset . click . left > containment [ 2 ] ) {
2012-11-18 16:44:12 +00:00
pageX = containment [ 2 ] + this . offset . click . left ;
}
2014-02-17 21:08:41 +00:00
if ( event . pageY - this . offset . click . top > containment [ 3 ] ) {
2012-11-18 16:44:12 +00:00
pageY = containment [ 3 ] + this . offset . click . top ;
}
2009-01-08 12:37:15 +00:00
}
2009-01-22 13:10:18 +00:00
2014-02-17 21:08:41 +00:00
if ( o . grid ) {
2011-05-13 15:23:44 +00:00
//Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
2012-11-18 16:44:12 +00:00
top = o . grid [ 1 ] ? this . originalPageY + Math . round ( ( pageY - this . originalPageY ) / o . grid [ 1 ] ) * o . grid [ 1 ] : this . originalPageY ;
2012-10-30 23:12:17 +00:00
pageY = containment ? ( ( top - this . offset . click . top >= containment [ 1 ] || top - this . offset . click . top > containment [ 3 ] ) ? top : ( ( top - this . offset . click . top >= containment [ 1 ] ) ? top - o . grid [ 1 ] : top + o . grid [ 1 ] ) ) : top ;
2009-01-08 12:37:15 +00:00
2012-11-18 16:44:12 +00:00
left = o . grid [ 0 ] ? this . originalPageX + Math . round ( ( pageX - this . originalPageX ) / o . grid [ 0 ] ) * o . grid [ 0 ] : this . originalPageX ;
2012-10-30 23:12:17 +00:00
pageX = containment ? ( ( left - this . offset . click . left >= containment [ 0 ] || left - this . offset . click . left > containment [ 2 ] ) ? left : ( ( left - this . offset . click . left >= containment [ 0 ] ) ? left - o . grid [ 0 ] : left + o . grid [ 0 ] ) ) : left ;
2009-01-08 12:37:15 +00:00
}
2013-10-20 23:33:40 +00:00
if ( o . axis === "y" ) {
pageX = this . originalPageX ;
}
if ( o . axis === "x" ) {
pageY = this . originalPageY ;
}
2009-01-08 12:37:15 +00:00
}
2009-01-08 13:31:16 +00:00
return {
2008-06-04 02:34:33 +00:00
top : (
2012-11-18 16:44:12 +00:00
pageY - // The absolute mouse position
this . offset . click . top - // Click offset (relative to the element)
this . offset . relative . top - // Only for relative positioned nodes: Relative offset from element to offset parent
this . offset . parent . top + // The offsetParent's offset without borders (offset + border)
2013-10-29 22:35:42 +00:00
( this . cssPosition === "fixed" ? - this . offset . scroll . top : ( scrollIsRootNode ? 0 : this . offset . scroll . top ) )
2008-06-04 02:34:33 +00:00
) ,
left : (
2012-11-18 16:44:12 +00:00
pageX - // The absolute mouse position
this . offset . click . left - // Click offset (relative to the element)
this . offset . relative . left - // Only for relative positioned nodes: Relative offset from element to offset parent
this . offset . parent . left + // The offsetParent's offset without borders (offset + border)
2013-10-29 22:35:42 +00:00
( this . cssPosition === "fixed" ? - this . offset . scroll . left : ( scrollIsRootNode ? 0 : this . offset . scroll . left ) )
2008-06-04 02:34:33 +00:00
)
} ;
2008-11-10 05:18:20 +00:00
2008-06-04 02:34:33 +00:00
} ,
2008-11-10 05:18:20 +00:00
2008-08-17 02:15:55 +00:00
_clear : function ( ) {
2009-02-02 06:45:50 +00:00
this . helper . removeClass ( "ui-draggable-dragging" ) ;
2014-02-17 21:08:41 +00:00
if ( this . helper [ 0 ] !== this . element [ 0 ] && ! this . cancelHelperRemoval ) {
2012-11-18 16:44:12 +00:00
this . helper . remove ( ) ;
}
2008-06-04 02:34:33 +00:00
this . helper = null ;
this . cancelHelperRemoval = false ;
2013-03-27 20:47:57 +00:00
if ( this . destroyOnClear ) {
this . destroy ( ) ;
}
2008-06-04 02:34:33 +00:00
} ,
2008-11-10 05:18:20 +00:00
2008-06-04 02:34:33 +00:00
// From now on bulk stuff - mainly helpers
2008-11-21 04:01:33 +00:00
2009-01-15 19:40:11 +00:00
_trigger : function ( type , event , ui ) {
ui = ui || this . _uiHash ( ) ;
2013-03-27 20:47:57 +00:00
$ . ui . plugin . call ( this , type , [ event , ui , this ] , true ) ;
2012-11-18 16:44:12 +00:00
//The absolute position has to be recalculated after plugins
2014-02-17 21:08:41 +00:00
if ( type === "drag" ) {
2012-11-18 16:44:12 +00:00
this . positionAbs = this . _convertPositionTo ( "absolute" ) ;
}
2010-01-07 03:19:50 +00:00
return $ . Widget . prototype . _trigger . call ( this , type , event , ui ) ;
2008-11-21 04:01:33 +00:00
} ,
2008-06-04 02:34:33 +00:00
plugins : { } ,
2008-11-21 04:01:33 +00:00
2012-10-30 23:12:17 +00:00
_uiHash : function ( ) {
2008-06-04 02:34:33 +00:00
return {
helper : this . helper ,
position : this . position ,
2009-08-23 17:40:44 +00:00
originalPosition : this . originalPosition ,
2009-01-29 12:35:38 +00:00
offset : this . positionAbs
2008-06-04 02:34:33 +00:00
} ;
}
2008-11-21 04:01:33 +00:00
2010-01-07 03:19:50 +00:00
} ) ;
2008-06-04 02:34:33 +00:00
2009-01-16 02:09:45 +00:00
$ . ui . plugin . add ( "draggable" , "connectToSortable" , {
2013-03-27 20:47:57 +00:00
start : function ( event , ui , inst ) {
2008-11-21 04:01:33 +00:00
2013-03-27 20:47:57 +00:00
var o = inst . options ,
2009-02-05 04:21:21 +00:00
uiSortable = $ . extend ( { } , ui , { item : inst . element } ) ;
2008-11-21 04:01:33 +00:00
inst . sortables = [ ] ;
2009-01-23 13:04:08 +00:00
$ ( o . connectToSortable ) . each ( function ( ) {
2013-03-19 15:53:35 +00:00
var sortable = $ ( this ) . sortable ( "instance" ) ;
2009-02-05 03:44:08 +00:00
if ( sortable && ! sortable . options . disabled ) {
inst . sortables . push ( {
instance : sortable ,
shouldRevert : sortable . options . revert
} ) ;
2011-03-14 13:53:00 +00:00
sortable . refreshPositions ( ) ; // Call the sortable's refreshPositions at drag start to refresh the containerCache since the sortable container cache is used in drag and needs to be up to date (this will ensure it's initialised as well as being kept in step with any changes that might have happened on the page).
2009-02-05 04:21:21 +00:00
sortable . _trigger ( "activate" , event , uiSortable ) ;
2009-02-05 03:44:08 +00:00
}
2008-11-21 04:01:33 +00:00
} ) ;
2008-06-04 02:34:33 +00:00
} ,
2013-03-27 20:47:57 +00:00
stop : function ( event , ui , inst ) {
2008-06-04 02:34:33 +00:00
2008-11-21 04:01:33 +00:00
//If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
2013-03-27 20:47:57 +00:00
var uiSortable = $ . extend ( { } , ui , {
item : inst . element
} ) ;
2008-11-21 04:01:33 +00:00
$ . each ( inst . sortables , function ( ) {
2014-02-17 21:08:41 +00:00
if ( this . instance . isOver ) {
2009-01-22 13:10:18 +00:00
2008-11-21 04:01:33 +00:00
this . instance . isOver = 0 ;
2009-01-22 13:10:18 +00:00
2008-11-21 04:01:33 +00:00
inst . cancelHelperRemoval = true ; //Don't remove the helper in the draggable instance
this . instance . cancelHelperRemoval = false ; //Remove it in the sortable instance (so sortable plugins like revert still work)
2009-01-22 13:10:18 +00:00
2012-12-25 17:01:09 +00:00
//The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: "valid/invalid"
2014-02-17 21:08:41 +00:00
if ( this . shouldRevert ) {
2013-02-19 22:58:31 +00:00
this . instance . options . revert = this . shouldRevert ;
2012-11-18 16:44:12 +00:00
}
2009-01-22 13:10:18 +00:00
2009-01-08 14:03:34 +00:00
//Trigger the stop of the sortable
2008-11-21 04:01:33 +00:00
this . instance . _mouseStop ( event ) ;
2009-01-22 13:10:18 +00:00
2008-11-21 04:01:33 +00:00
this . instance . options . helper = this . instance . options . _helper ;
2008-12-31 08:22:11 +00:00
2009-01-08 14:03:34 +00:00
//If the helper has been the original item, restore properties in the sortable
2014-02-17 21:08:41 +00:00
if ( inst . options . helper === "original" ) {
2012-12-25 17:01:09 +00:00
this . instance . currentItem . css ( { top : "auto" , left : "auto" } ) ;
2012-11-18 16:44:12 +00:00
}
2008-12-30 16:34:23 +00:00
2008-11-21 04:01:33 +00:00
} else {
this . instance . cancelHelperRemoval = false ; //Remove the helper in the sortable instance
2009-02-05 04:21:21 +00:00
this . instance . _trigger ( "deactivate" , event , uiSortable ) ;
2008-11-21 04:01:33 +00:00
}
} ) ;
2008-06-04 02:34:33 +00:00
} ,
2013-03-27 20:47:57 +00:00
drag : function ( event , ui , inst ) {
2008-11-21 04:01:33 +00:00
2013-03-27 20:47:57 +00:00
var that = this ;
2008-11-21 04:01:33 +00:00
2012-10-30 23:12:17 +00:00
$ . each ( inst . sortables , function ( ) {
2012-10-22 01:50:03 +00:00
2012-11-18 16:44:12 +00:00
var innermostIntersecting = false ,
thisSortable = this ;
2009-02-10 15:05:01 +00:00
//Copy over some variables to allow calling the sortable's native _intersectsWith
this . instance . positionAbs = inst . positionAbs ;
this . instance . helperProportions = inst . helperProportions ;
this . instance . offset . click = inst . offset . click ;
2012-10-22 01:50:03 +00:00
2014-02-17 21:08:41 +00:00
if ( this . instance . _intersectsWith ( this . instance . containerCache ) ) {
2012-09-13 04:10:01 +00:00
innermostIntersecting = true ;
2014-02-17 21:08:41 +00:00
$ . each ( inst . sortables , function ( ) {
2012-09-13 04:10:01 +00:00
this . instance . positionAbs = inst . positionAbs ;
this . instance . helperProportions = inst . helperProportions ;
this . instance . offset . click = inst . offset . click ;
2012-11-18 16:44:12 +00:00
if ( this !== thisSortable &&
this . instance . _intersectsWith ( this . instance . containerCache ) &&
2013-02-01 22:09:43 +00:00
$ . contains ( thisSortable . instance . element [ 0 ] , this . instance . element [ 0 ] )
2012-11-18 16:44:12 +00:00
) {
2012-09-13 04:10:01 +00:00
innermostIntersecting = false ;
2012-11-18 16:44:12 +00:00
}
return innermostIntersecting ;
2012-09-13 04:10:01 +00:00
} ) ;
}
2014-02-17 21:08:41 +00:00
if ( innermostIntersecting ) {
2008-11-21 04:01:33 +00:00
//If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
2014-02-17 21:08:41 +00:00
if ( ! this . instance . isOver ) {
2009-02-10 15:05:01 +00:00
2008-11-21 04:01:33 +00:00
this . instance . isOver = 1 ;
//Now we fake the start of dragging for the sortable instance,
//by cloning the list group item, appending it to the sortable and using it as inst.currentItem
//We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
2012-12-25 17:01:09 +00:00
this . instance . currentItem = $ ( that ) . clone ( ) . removeAttr ( "id" ) . appendTo ( this . instance . element ) . data ( "ui-sortable-item" , true ) ;
2008-11-21 04:01:33 +00:00
this . instance . options . _helper = this . instance . options . helper ; //Store helper option to later restore it
this . instance . options . helper = function ( ) { return ui . helper [ 0 ] ; } ;
event . target = this . instance . currentItem [ 0 ] ;
this . instance . _mouseCapture ( event , true ) ;
this . instance . _mouseStart ( event , true , true ) ;
//Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
this . instance . offset . click . top = inst . offset . click . top ;
this . instance . offset . click . left = inst . offset . click . left ;
this . instance . offset . parent . left -= inst . offset . parent . left - this . instance . offset . parent . left ;
this . instance . offset . parent . top -= inst . offset . parent . top - this . instance . offset . parent . top ;
2009-01-08 15:49:20 +00:00
inst . _trigger ( "toSortable" , event ) ;
2009-01-08 14:03:34 +00:00
inst . dropped = this . instance . element ; //draggable revert needs that
2009-02-05 04:12:23 +00:00
//hack so receive/update callbacks work (mostly)
inst . currentItem = inst . element ;
this . instance . fromOutside = inst ;
2008-11-21 04:01:33 +00:00
}
//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
2014-02-17 21:08:41 +00:00
if ( this . instance . currentItem ) {
2012-11-18 16:44:12 +00:00
this . instance . _mouseDrag ( event ) ;
}
2008-11-21 04:01:33 +00:00
} else {
//If it doesn't intersect with the sortable, and it intersected before,
//we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
2014-02-17 21:08:41 +00:00
if ( this . instance . isOver ) {
2009-02-10 15:05:01 +00:00
2008-11-21 04:01:33 +00:00
this . instance . isOver = 0 ;
this . instance . cancelHelperRemoval = true ;
2012-10-22 01:50:03 +00:00
2009-02-10 15:05:01 +00:00
//Prevent reverting on this forced stop
this . instance . options . revert = false ;
2012-10-22 01:50:03 +00:00
2009-02-10 15:05:01 +00:00
// The out event needs to be triggered independently
2012-12-25 17:01:09 +00:00
this . instance . _trigger ( "out" , event , this . instance . _uiHash ( this . instance ) ) ;
2012-10-22 01:50:03 +00:00
2008-11-21 04:01:33 +00:00
this . instance . _mouseStop ( event , true ) ;
this . instance . options . helper = this . instance . options . _helper ;
//Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
this . instance . currentItem . remove ( ) ;
2014-02-17 21:08:41 +00:00
if ( this . instance . placeholder ) {
2012-11-18 16:44:12 +00:00
this . instance . placeholder . remove ( ) ;
}
2008-11-21 04:01:33 +00:00
2009-01-08 15:49:20 +00:00
inst . _trigger ( "fromSortable" , event ) ;
2009-01-08 14:03:34 +00:00
inst . dropped = false ; //draggable revert needs that
2008-11-21 04:01:33 +00:00
}
2012-10-30 23:12:17 +00:00
}
2008-11-21 04:01:33 +00:00
} ) ;
2008-06-04 02:34:33 +00:00
}
} ) ;
2009-01-16 02:09:45 +00:00
$ . ui . plugin . add ( "draggable" , "cursor" , {
2013-03-27 20:47:57 +00:00
start : function ( event , ui , instance ) {
var t = $ ( "body" ) ,
o = instance . options ;
2012-11-18 16:44:12 +00:00
if ( t . css ( "cursor" ) ) {
o . _cursor = t . css ( "cursor" ) ;
}
2009-01-23 13:04:08 +00:00
t . css ( "cursor" , o . cursor ) ;
2008-06-04 02:34:33 +00:00
} ,
2013-03-27 20:47:57 +00:00
stop : function ( event , ui , instance ) {
var o = instance . options ;
2012-11-18 16:44:12 +00:00
if ( o . _cursor ) {
2012-12-25 17:01:09 +00:00
$ ( "body" ) . css ( "cursor" , o . _cursor ) ;
2012-11-18 16:44:12 +00:00
}
2008-06-04 02:34:33 +00:00
}
} ) ;
2009-01-16 02:09:45 +00:00
$ . ui . plugin . add ( "draggable" , "opacity" , {
2013-03-27 20:47:57 +00:00
start : function ( event , ui , instance ) {
var t = $ ( ui . helper ) ,
o = instance . options ;
2014-02-17 21:08:41 +00:00
if ( t . css ( "opacity" ) ) {
2012-11-18 16:44:12 +00:00
o . _opacity = t . css ( "opacity" ) ;
}
2012-12-25 17:01:09 +00:00
t . css ( "opacity" , o . opacity ) ;
2008-11-21 04:01:33 +00:00
} ,
2013-03-27 20:47:57 +00:00
stop : function ( event , ui , instance ) {
var o = instance . options ;
2014-02-17 21:08:41 +00:00
if ( o . _opacity ) {
2012-12-25 17:01:09 +00:00
$ ( ui . helper ) . css ( "opacity" , o . _opacity ) ;
2012-11-18 16:44:12 +00:00
}
2008-11-21 04:01:33 +00:00
}
} ) ;
2009-01-16 02:09:45 +00:00
$ . ui . plugin . add ( "draggable" , "scroll" , {
2013-03-27 20:47:57 +00:00
start : function ( event , ui , i ) {
2014-08-10 03:11:16 +00:00
if ( ! i . scrollParentNotHidden ) {
i . scrollParentNotHidden = i . helper . scrollParent ( false ) ;
}
if ( i . scrollParentNotHidden [ 0 ] !== i . document [ 0 ] && i . scrollParentNotHidden [ 0 ] . tagName !== "HTML" ) {
i . overflowOffset = i . scrollParentNotHidden . offset ( ) ;
2012-11-18 16:44:12 +00:00
}
2008-06-04 02:34:33 +00:00
} ,
2013-03-27 20:47:57 +00:00
drag : function ( event , ui , i ) {
2008-11-10 05:18:20 +00:00
2013-03-27 20:47:57 +00:00
var o = i . options ,
2010-06-14 15:20:03 +00:00
scrolled = false ,
2014-08-10 03:11:16 +00:00
scrollParent = i . scrollParentNotHidden [ 0 ] ,
2010-06-14 15:20:03 +00:00
document = i . document [ 0 ] ;
2008-11-23 17:42:24 +00:00
2014-08-10 03:11:16 +00:00
if ( scrollParent !== document && scrollParent . tagName !== "HTML" ) {
2014-08-10 03:06:18 +00:00
if ( ! o . axis || o . axis !== "x" ) {
2014-08-10 03:11:16 +00:00
if ( ( i . overflowOffset . top + scrollParent . offsetHeight ) - event . pageY < o . scrollSensitivity ) {
scrollParent . scrollTop = scrolled = scrollParent . scrollTop + o . scrollSpeed ;
2014-08-10 03:06:18 +00:00
} else if ( event . pageY - i . overflowOffset . top < o . scrollSensitivity ) {
2014-08-10 03:11:16 +00:00
scrollParent . scrollTop = scrolled = scrollParent . scrollTop - o . scrollSpeed ;
2012-11-18 16:44:12 +00:00
}
2009-01-23 13:10:17 +00:00
}
2009-01-24 01:36:22 +00:00
2014-08-10 03:06:18 +00:00
if ( ! o . axis || o . axis !== "y" ) {
2014-08-10 03:11:16 +00:00
if ( ( i . overflowOffset . left + scrollParent . offsetWidth ) - event . pageX < o . scrollSensitivity ) {
scrollParent . scrollLeft = scrolled = scrollParent . scrollLeft + o . scrollSpeed ;
2014-08-10 03:06:18 +00:00
} else if ( event . pageX - i . overflowOffset . left < o . scrollSensitivity ) {
2014-08-10 03:11:16 +00:00
scrollParent . scrollLeft = scrolled = scrollParent . scrollLeft - o . scrollSpeed ;
2012-11-18 16:44:12 +00:00
}
2009-01-23 13:10:17 +00:00
}
2008-11-28 15:43:32 +00:00
2008-06-04 02:34:33 +00:00
} else {
2009-01-24 01:36:22 +00:00
2014-02-17 21:08:41 +00:00
if ( ! o . axis || o . axis !== "x" ) {
if ( event . pageY - $ ( document ) . scrollTop ( ) < o . scrollSensitivity ) {
2009-01-23 13:10:17 +00:00
scrolled = $ ( document ) . scrollTop ( $ ( document ) . scrollTop ( ) - o . scrollSpeed ) ;
2014-02-17 21:08:41 +00:00
} else if ( $ ( window ) . height ( ) - ( event . pageY - $ ( document ) . scrollTop ( ) ) < o . scrollSensitivity ) {
2009-01-23 13:10:17 +00:00
scrolled = $ ( document ) . scrollTop ( $ ( document ) . scrollTop ( ) + o . scrollSpeed ) ;
2012-11-18 16:44:12 +00:00
}
2009-01-23 13:10:17 +00:00
}
2009-01-24 01:36:22 +00:00
2014-02-17 21:08:41 +00:00
if ( ! o . axis || o . axis !== "y" ) {
if ( event . pageX - $ ( document ) . scrollLeft ( ) < o . scrollSensitivity ) {
2009-01-23 13:10:17 +00:00
scrolled = $ ( document ) . scrollLeft ( $ ( document ) . scrollLeft ( ) - o . scrollSpeed ) ;
2014-02-17 21:08:41 +00:00
} else if ( $ ( window ) . width ( ) - ( event . pageX - $ ( document ) . scrollLeft ( ) ) < o . scrollSensitivity ) {
2009-01-23 13:10:17 +00:00
scrolled = $ ( document ) . scrollLeft ( $ ( document ) . scrollLeft ( ) + o . scrollSpeed ) ;
2012-11-18 16:44:12 +00:00
}
2009-01-23 13:10:17 +00:00
}
2009-01-24 01:36:22 +00:00
2008-06-04 02:34:33 +00:00
}
2008-11-10 05:18:20 +00:00
2014-02-17 21:08:41 +00:00
if ( scrolled !== false && $ . ui . ddmanager && ! o . dropBehaviour ) {
2008-11-14 03:00:16 +00:00
$ . ui . ddmanager . prepareOffsets ( i , event ) ;
2012-11-18 16:44:12 +00:00
}
2008-11-10 05:18:20 +00:00
2008-06-04 02:34:33 +00:00
}
} ) ;
2009-01-16 02:09:45 +00:00
$ . ui . plugin . add ( "draggable" , "snap" , {
2013-03-27 20:47:57 +00:00
start : function ( event , ui , i ) {
2008-11-10 05:18:20 +00:00
2013-03-27 20:47:57 +00:00
var o = i . options ;
2012-11-18 16:44:12 +00:00
2009-01-23 13:04:08 +00:00
i . snapElements = [ ] ;
2008-11-10 05:18:20 +00:00
2012-12-25 17:01:09 +00:00
$ ( o . snap . constructor !== String ? ( o . snap . items || ":data(ui-draggable)" ) : o . snap ) . each ( function ( ) {
2012-11-18 16:44:12 +00:00
var $t = $ ( this ) ,
$o = $t . offset ( ) ;
2014-02-17 21:08:41 +00:00
if ( this !== i . element [ 0 ] ) {
2012-11-18 16:44:12 +00:00
i . snapElements . push ( {
item : this ,
width : $t . outerWidth ( ) , height : $t . outerHeight ( ) ,
top : $o . top , left : $o . left
} ) ;
}
2008-06-04 02:34:33 +00:00
} ) ;
2008-11-10 05:18:20 +00:00
2008-06-04 02:34:33 +00:00
} ,
2013-03-27 20:47:57 +00:00
drag : function ( event , ui , inst ) {
2008-11-10 05:18:20 +00:00
2012-11-18 16:44:12 +00:00
var ts , bs , ls , rs , l , r , t , b , i , first ,
o = inst . options ,
d = o . snapTolerance ,
x1 = ui . offset . left , x2 = x1 + inst . helperProportions . width ,
2009-02-03 03:02:30 +00:00
y1 = ui . offset . top , y2 = y1 + inst . helperProportions . height ;
2008-11-10 05:18:20 +00:00
2012-11-18 16:44:12 +00:00
for ( i = inst . snapElements . length - 1 ; i >= 0 ; i -- ) {
2008-11-10 05:18:20 +00:00
2012-11-18 16:44:12 +00:00
l = inst . snapElements [ i ] . left ;
r = l + inst . snapElements [ i ] . width ;
t = inst . snapElements [ i ] . top ;
b = t + inst . snapElements [ i ] . height ;
2008-11-10 05:18:20 +00:00
2013-03-16 18:36:06 +00:00
if ( x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d || ! $ . contains ( inst . snapElements [ i ] . item . ownerDocument , inst . snapElements [ i ] . item ) ) {
2014-02-17 21:08:41 +00:00
if ( inst . snapElements [ i ] . snapping ) {
2012-11-18 16:44:12 +00:00
( inst . options . snap . release && inst . options . snap . release . call ( inst . element , event , $ . extend ( inst . _uiHash ( ) , { snapItem : inst . snapElements [ i ] . item } ) ) ) ;
}
2008-07-17 16:13:10 +00:00
inst . snapElements [ i ] . snapping = false ;
continue ;
}
2008-11-10 05:18:20 +00:00
2014-02-17 21:08:41 +00:00
if ( o . snapMode !== "inner" ) {
2012-11-18 16:44:12 +00:00
ts = Math . abs ( t - y2 ) <= d ;
bs = Math . abs ( b - y1 ) <= d ;
ls = Math . abs ( l - x2 ) <= d ;
rs = Math . abs ( r - x1 ) <= d ;
2014-02-17 21:08:41 +00:00
if ( ts ) {
2012-11-18 16:44:12 +00:00
ui . position . top = inst . _convertPositionTo ( "relative" , { top : t - inst . helperProportions . height , left : 0 } ) . top - inst . margins . top ;
}
2014-02-17 21:08:41 +00:00
if ( bs ) {
2012-11-18 16:44:12 +00:00
ui . position . top = inst . _convertPositionTo ( "relative" , { top : b , left : 0 } ) . top - inst . margins . top ;
}
2014-02-17 21:08:41 +00:00
if ( ls ) {
2012-11-18 16:44:12 +00:00
ui . position . left = inst . _convertPositionTo ( "relative" , { top : 0 , left : l - inst . helperProportions . width } ) . left - inst . margins . left ;
}
2014-02-17 21:08:41 +00:00
if ( rs ) {
2012-11-18 16:44:12 +00:00
ui . position . left = inst . _convertPositionTo ( "relative" , { top : 0 , left : r } ) . left - inst . margins . left ;
}
2008-06-04 02:34:33 +00:00
}
2008-11-10 05:18:20 +00:00
2012-11-18 16:44:12 +00:00
first = ( ts || bs || ls || rs ) ;
2014-02-17 21:08:41 +00:00
if ( o . snapMode !== "outer" ) {
2012-11-18 16:44:12 +00:00
ts = Math . abs ( t - y1 ) <= d ;
bs = Math . abs ( b - y2 ) <= d ;
ls = Math . abs ( l - x1 ) <= d ;
rs = Math . abs ( r - x2 ) <= d ;
2014-02-17 21:08:41 +00:00
if ( ts ) {
2012-11-18 16:44:12 +00:00
ui . position . top = inst . _convertPositionTo ( "relative" , { top : t , left : 0 } ) . top - inst . margins . top ;
}
2014-02-17 21:08:41 +00:00
if ( bs ) {
2012-11-18 16:44:12 +00:00
ui . position . top = inst . _convertPositionTo ( "relative" , { top : b - inst . helperProportions . height , left : 0 } ) . top - inst . margins . top ;
}
2014-02-17 21:08:41 +00:00
if ( ls ) {
2012-11-18 16:44:12 +00:00
ui . position . left = inst . _convertPositionTo ( "relative" , { top : 0 , left : l } ) . left - inst . margins . left ;
}
2014-02-17 21:08:41 +00:00
if ( rs ) {
2012-11-18 16:44:12 +00:00
ui . position . left = inst . _convertPositionTo ( "relative" , { top : 0 , left : r - inst . helperProportions . width } ) . left - inst . margins . left ;
}
2008-06-04 02:34:33 +00:00
}
2008-11-10 05:18:20 +00:00
2014-02-17 21:08:41 +00:00
if ( ! inst . snapElements [ i ] . snapping && ( ts || bs || ls || rs || first ) ) {
2008-11-23 17:42:24 +00:00
( inst . options . snap . snap && inst . options . snap . snap . call ( inst . element , event , $ . extend ( inst . _uiHash ( ) , { snapItem : inst . snapElements [ i ] . item } ) ) ) ;
2012-11-18 16:44:12 +00:00
}
2008-07-17 16:13:10 +00:00
inst . snapElements [ i ] . snapping = ( ts || bs || ls || rs || first ) ;
2008-11-10 05:18:20 +00:00
2012-10-30 23:12:17 +00:00
}
2008-11-10 05:18:20 +00:00
2008-06-04 02:34:33 +00:00
}
} ) ;
2009-01-16 02:09:45 +00:00
$ . ui . plugin . add ( "draggable" , "stack" , {
2013-03-27 20:47:57 +00:00
start : function ( event , ui , instance ) {
2012-11-18 16:44:12 +00:00
var min ,
2013-03-27 20:47:57 +00:00
o = instance . options ,
2014-08-06 21:51:43 +00:00
group = $ . makeArray ( $ ( o . stack ) ) . sort ( function ( a , b ) {
return ( parseInt ( $ ( a ) . css ( "zIndex" ) , 10 ) || 0 ) - ( parseInt ( $ ( b ) . css ( "zIndex" ) , 10 ) || 0 ) ;
2012-11-18 16:44:12 +00:00
} ) ;
2009-01-24 01:36:22 +00:00
2010-02-18 04:46:59 +00:00
if ( ! group . length ) { return ; }
2012-10-22 01:50:03 +00:00
2013-02-12 04:29:48 +00:00
min = parseInt ( $ ( group [ 0 ] ) . css ( "zIndex" ) , 10 ) || 0 ;
2008-06-04 02:34:33 +00:00
$ ( group ) . each ( function ( i ) {
2013-02-12 04:29:48 +00:00
$ ( this ) . css ( "zIndex" , min + i ) ;
2008-06-04 02:34:33 +00:00
} ) ;
2013-02-13 02:27:21 +00:00
this . css ( "zIndex" , ( min + group . length ) ) ;
2008-06-04 02:34:33 +00:00
}
} ) ;
2009-01-16 02:09:45 +00:00
$ . ui . plugin . add ( "draggable" , "zIndex" , {
2013-03-27 20:47:57 +00:00
start : function ( event , ui , instance ) {
var t = $ ( ui . helper ) ,
o = instance . options ;
2014-02-17 21:08:41 +00:00
if ( t . css ( "zIndex" ) ) {
2012-11-18 16:44:12 +00:00
o . _zIndex = t . css ( "zIndex" ) ;
}
2012-12-25 17:01:09 +00:00
t . css ( "zIndex" , o . zIndex ) ;
2008-11-21 04:01:33 +00:00
} ,
2013-03-27 20:47:57 +00:00
stop : function ( event , ui , instance ) {
var o = instance . options ;
2014-02-17 21:08:41 +00:00
if ( o . _zIndex ) {
2012-12-25 17:01:09 +00:00
$ ( ui . helper ) . css ( "zIndex" , o . _zIndex ) ;
2012-11-18 16:44:12 +00:00
}
2008-11-21 04:01:33 +00:00
}
} ) ;
2013-07-12 16:40:48 +00:00
return $ . ui . draggable ;
} ) ) ;