app/jquery/jquery-ui.draggable.js
changeset 2420 645f4de26f99
child 2749 4e2789b8e86d
equal deleted inserted replaced
2419:82ce842da661 2420:645f4de26f99
       
     1 /*
       
     2  * jQuery UI Draggable 1.6
       
     3  *
       
     4  * Copyright (c) 2008 AUTHORS.txt (http://ui.jquery.com/about)
       
     5  * Dual licensed under the MIT (MIT-LICENSE.txt)
       
     6  * and GPL (GPL-LICENSE.txt) licenses.
       
     7  *
       
     8  * http://docs.jquery.com/UI/Draggables
       
     9  *
       
    10  * Depends:
       
    11  *	ui.core.js
       
    12  */
       
    13 (function($) {
       
    14 
       
    15 $.widget("ui.draggable", $.extend({}, $.ui.mouse, {
       
    16 
       
    17 	_init: function() {
       
    18 
       
    19 		if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
       
    20 			this.element[0].style.position = 'relative';
       
    21 
       
    22 		(this.options.cssNamespace && this.element.addClass(this.options.cssNamespace+"-draggable"));
       
    23 		(this.options.disabled && this.element.addClass('ui-draggable-disabled'));
       
    24 
       
    25 		this._mouseInit();
       
    26 
       
    27 	},
       
    28 
       
    29 	destroy: function() {
       
    30 		if(!this.element.data('draggable')) return;
       
    31 		this.element.removeData("draggable").unbind(".draggable").removeClass('ui-draggable ui-draggable-dragging ui-draggable-disabled');
       
    32 		this._mouseDestroy();
       
    33 	},
       
    34 
       
    35 	_mouseCapture: function(event) {
       
    36 
       
    37 		var o = this.options;
       
    38 
       
    39 		if (this.helper || o.disabled || $(event.target).is('.ui-resizable-handle'))
       
    40 			return false;
       
    41 
       
    42 		//Quit if we're not on a valid handle
       
    43 		this.handle = this._getHandle(event);
       
    44 		if (!this.handle)
       
    45 			return false;
       
    46 
       
    47 		return true;
       
    48 
       
    49 	},
       
    50 
       
    51 	_mouseStart: function(event) {
       
    52 
       
    53 		var o = this.options;
       
    54 
       
    55 		//Create and append the visible helper
       
    56 		this.helper = this._createHelper(event);
       
    57 
       
    58 		//Cache the helper size
       
    59 		this._cacheHelperProportions();
       
    60 
       
    61 		//If ddmanager is used for droppables, set the global draggable
       
    62 		if($.ui.ddmanager)
       
    63 			$.ui.ddmanager.current = this;
       
    64 
       
    65 		/*
       
    66 		 * - Position generation -
       
    67 		 * This block generates everything position related - it's the core of draggables.
       
    68 		 */
       
    69 
       
    70 		//Cache the margins of the original element
       
    71 		this._cacheMargins();
       
    72 
       
    73 		//Store the helper's css position
       
    74 		this.cssPosition = this.helper.css("position");
       
    75 		this.scrollParent = this.helper.scrollParent();
       
    76 
       
    77 		//The element's absolute position on the page minus margins
       
    78 		this.offset = this.element.offset();
       
    79 		this.offset = {
       
    80 			top: this.offset.top - this.margins.top,
       
    81 			left: this.offset.left - this.margins.left
       
    82 		};
       
    83 
       
    84 		$.extend(this.offset, {
       
    85 			click: { //Where the click happened, relative to the element
       
    86 				left: event.pageX - this.offset.left,
       
    87 				top: event.pageY - this.offset.top
       
    88 			},
       
    89 			parent: this._getParentOffset(),
       
    90 			relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
       
    91 		});
       
    92 
       
    93 		//Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
       
    94 		if(o.cursorAt)
       
    95 			this._adjustOffsetFromHelper(o.cursorAt);
       
    96 
       
    97 		//Generate the original position
       
    98 		this.originalPosition = this._generatePosition(event);
       
    99 
       
   100 		//Set a containment if given in the options
       
   101 		if(o.containment)
       
   102 			this._setContainment();
       
   103 
       
   104 		//Call plugins and callbacks
       
   105 		this._propagate("start", event);
       
   106 
       
   107 		//Recache the helper size
       
   108 		this._cacheHelperProportions();
       
   109 
       
   110 		//Prepare the droppable offsets
       
   111 		if ($.ui.ddmanager && !o.dropBehaviour)
       
   112 			$.ui.ddmanager.prepareOffsets(this, event);
       
   113 
       
   114 		this.helper.addClass("ui-draggable-dragging");
       
   115 		this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
       
   116 		return true;
       
   117 	},
       
   118 
       
   119 	_mouseDrag: function(event, noPropagation) {
       
   120 
       
   121 		//Compute the helpers position
       
   122 		this.position = this._generatePosition(event);
       
   123 		this.positionAbs = this._convertPositionTo("absolute");
       
   124 
       
   125 		//Call plugins and callbacks and use the resulting position if something is returned
       
   126 		if(!noPropagation) this.position = this._propagate("drag", event) || this.position;
       
   127 
       
   128 		if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
       
   129 		if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
       
   130 		if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
       
   131 
       
   132 		return false;
       
   133 	},
       
   134 
       
   135 	_mouseStop: function(event) {
       
   136 
       
   137 		//If we are using droppables, inform the manager about the drop
       
   138 		var dropped = false;
       
   139 		if ($.ui.ddmanager && !this.options.dropBehaviour)
       
   140 			var dropped = $.ui.ddmanager.drop(this, event);
       
   141 
       
   142 		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))) {
       
   143 			var self = this;
       
   144 			$(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
       
   145 				self._propagate("stop", event);
       
   146 				self._clear();
       
   147 			});
       
   148 		} else {
       
   149 			this._propagate("stop", event);
       
   150 			this._clear();
       
   151 		}
       
   152 
       
   153 		return false;
       
   154 	},
       
   155 
       
   156 	_getHandle: function(event) {
       
   157 
       
   158 		var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
       
   159 		$(this.options.handle, this.element)
       
   160 			.find("*")
       
   161 			.andSelf()
       
   162 			.each(function() {
       
   163 				if(this == event.target) handle = true;
       
   164 			});
       
   165 
       
   166 		return handle;
       
   167 
       
   168 	},
       
   169 
       
   170 	_createHelper: function(event) {
       
   171 
       
   172 		var o = this.options;
       
   173 		var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone() : this.element);
       
   174 
       
   175 		if(!helper.parents('body').length)
       
   176 			helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo));
       
   177 
       
   178 		if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position")))
       
   179 			helper.css("position", "absolute");
       
   180 
       
   181 		return helper;
       
   182 
       
   183 	},
       
   184 
       
   185 	_adjustOffsetFromHelper: function(obj) {
       
   186 		if(obj.left != undefined) this.offset.click.left = obj.left + this.margins.left;
       
   187 		if(obj.right != undefined) this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
       
   188 		if(obj.top != undefined) this.offset.click.top = obj.top + this.margins.top;
       
   189 		if(obj.bottom != undefined) this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
       
   190 	},
       
   191 
       
   192 	_getParentOffset: function() {
       
   193 
       
   194 		this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset();			//Get the offsetParent and cache its position
       
   195 
       
   196 		if((this.offsetParent[0] == document.body && $.browser.mozilla)	//Ugly FF3 fix
       
   197 		|| (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix
       
   198 			po = { top: 0, left: 0 };
       
   199 
       
   200 		return {
       
   201 			top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
       
   202 			left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
       
   203 		};
       
   204 
       
   205 	},
       
   206 
       
   207 	_getRelativeOffset: function() {
       
   208 
       
   209 		if(this.cssPosition == "relative") {
       
   210 			var p = this.element.position();
       
   211 			return {
       
   212 				top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
       
   213 				left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
       
   214 			};
       
   215 		} else {
       
   216 			return { top: 0, left: 0 };
       
   217 		}
       
   218 
       
   219 	},
       
   220 
       
   221 	_cacheMargins: function() {
       
   222 		this.margins = {
       
   223 			left: (parseInt(this.element.css("marginLeft"),10) || 0),
       
   224 			top: (parseInt(this.element.css("marginTop"),10) || 0)
       
   225 		};
       
   226 	},
       
   227 
       
   228 	_cacheHelperProportions: function() {
       
   229 		this.helperProportions = {
       
   230 			width: this.helper.outerWidth(),
       
   231 			height: this.helper.outerHeight()
       
   232 		};
       
   233 	},
       
   234 
       
   235 	_setContainment: function() {
       
   236 
       
   237 		var o = this.options;
       
   238 		if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
       
   239 		if(o.containment == 'document' || o.containment == 'window') this.containment = [
       
   240 			0 - this.offset.relative.left - this.offset.parent.left,
       
   241 			0 - this.offset.relative.top - this.offset.parent.top,
       
   242 			$(o.containment == 'document' ? document : window).width() - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0),
       
   243 			($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0)
       
   244 		];
       
   245 
       
   246 		if(!(/^(document|window|parent)$/).test(o.containment)) {
       
   247 			var ce = $(o.containment)[0];
       
   248 			var co = $(o.containment).offset();
       
   249 			var over = ($(ce).css("overflow") != 'hidden');
       
   250 
       
   251 			this.containment = [
       
   252 				co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left - this.margins.left,
       
   253 				co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top - this.margins.top,
       
   254 				co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left,
       
   255 				co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top
       
   256 			];
       
   257 		}
       
   258 
       
   259 	},
       
   260 
       
   261 	_convertPositionTo: function(d, pos) {
       
   262 
       
   263 		if(!pos) pos = this.position;
       
   264 		var mod = d == "absolute" ? 1 : -1;
       
   265 		var scroll = this[(this.cssPosition == 'absolute' ? 'offset' : 'scroll')+'Parent'], scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
       
   266 
       
   267 		return {
       
   268 			top: (
       
   269 				pos.top																	// the calculated relative position
       
   270 				+ this.offset.relative.top	* mod										// Only for relative positioned nodes: Relative offset from element to offset parent
       
   271 				+ this.offset.parent.top * mod											// The offsetParent's offset without borders (offset + border)
       
   272 				+ ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod
       
   273 				+ this.margins.top * mod												//Add the margin (you don't want the margin counting in intersection methods)
       
   274 			),
       
   275 			left: (
       
   276 				pos.left																// the calculated relative position
       
   277 				+ this.offset.relative.left	* mod										// Only for relative positioned nodes: Relative offset from element to offset parent
       
   278 				+ this.offset.parent.left * mod											// The offsetParent's offset without borders (offset + border)
       
   279 				+ ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : ( scrollIsRootNode ? 0 : scroll.scrollLeft() ) ) * mod
       
   280 				+ this.margins.left * mod												//Add the margin (you don't want the margin counting in intersection methods)
       
   281 			)
       
   282 		};
       
   283 	},
       
   284 
       
   285 	_generatePosition: function(event) {
       
   286 
       
   287 		var o = this.options, scroll = this[(this.cssPosition == 'absolute' ? 'offset' : 'scroll')+'Parent'], scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
       
   288 
       
   289 		var position = {
       
   290 			top: (
       
   291 				event.pageY																// The absolute mouse position
       
   292 				- this.offset.click.top													// Click offset (relative to the element)
       
   293 				- this.offset.relative.top												// Only for relative positioned nodes: Relative offset from element to offset parent
       
   294 				- this.offset.parent.top												// The offsetParent's offset without borders (offset + border)
       
   295 				+ ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) )
       
   296 			),
       
   297 			left: (
       
   298 				event.pageX																// The absolute mouse position
       
   299 				- this.offset.click.left												// Click offset (relative to the element)
       
   300 				- this.offset.relative.left												// Only for relative positioned nodes: Relative offset from element to offset parent
       
   301 				- this.offset.parent.left												// The offsetParent's offset without borders (offset + border)
       
   302 				+ ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() )
       
   303 			)
       
   304 		};
       
   305 
       
   306 		if(!this.originalPosition) return position;										//If we are not dragging yet, we won't check for options
       
   307 
       
   308 		/*
       
   309 		 * - Position constraining -
       
   310 		 * Constrain the position to a mix of grid, containment.
       
   311 		 */
       
   312 		if(this.containment) {
       
   313 			if(position.left < this.containment[0]) position.left = this.containment[0];
       
   314 			if(position.top < this.containment[1]) position.top = this.containment[1];
       
   315 			if(position.left > this.containment[2]) position.left = this.containment[2];
       
   316 			if(position.top > this.containment[3]) position.top = this.containment[3];
       
   317 		}
       
   318 
       
   319 		if(o.grid) {
       
   320 			var top = this.originalPosition.top + Math.round((position.top - this.originalPosition.top) / o.grid[1]) * o.grid[1];
       
   321 			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;
       
   322 
       
   323 			var left = this.originalPosition.left + Math.round((position.left - this.originalPosition.left) / o.grid[0]) * o.grid[0];
       
   324 			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;
       
   325 		}
       
   326 
       
   327 		return position;
       
   328 	},
       
   329 
       
   330 	_clear: function() {
       
   331 		this.helper.removeClass("ui-draggable-dragging");
       
   332 		if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove();
       
   333 		//if($.ui.ddmanager) $.ui.ddmanager.current = null;
       
   334 		this.helper = null;
       
   335 		this.cancelHelperRemoval = false;
       
   336 	},
       
   337 
       
   338 	// From now on bulk stuff - mainly helpers
       
   339 
       
   340 	_propagate: function(n, event) {
       
   341 		$.ui.plugin.call(this, n, [event, this._uiHash()]);
       
   342 		if(n == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins
       
   343 		return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [event, this._uiHash()], this.options[n]);
       
   344 	},
       
   345 
       
   346 	plugins: {},
       
   347 
       
   348 	_uiHash: function(event) {
       
   349 		return {
       
   350 			helper: this.helper,
       
   351 			position: this.position,
       
   352 			absolutePosition: this.positionAbs,
       
   353 			options: this.options
       
   354 		};
       
   355 	}
       
   356 
       
   357 }));
       
   358 
       
   359 $.extend($.ui.draggable, {
       
   360 	version: "1.6",
       
   361 	defaults: {
       
   362 		appendTo: "parent",
       
   363 		axis: false,
       
   364 		cancel: ":input",
       
   365 		connectToSortable: false,
       
   366 		containment: false,
       
   367 		cssNamespace: "ui",
       
   368 		cursor: "default",
       
   369 		cursorAt: null,
       
   370 		delay: 0,
       
   371 		distance: 1,
       
   372 		grid: false,
       
   373 		handle: false,
       
   374 		helper: "original",
       
   375 		iframeFix: false,
       
   376 		opacity: 1,
       
   377 		refreshPositions: false,
       
   378 		revert: false,
       
   379 		revertDuration: 500,
       
   380 		scope: "default",
       
   381 		scroll: true,
       
   382 		scrollSensitivity: 20,
       
   383 		scrollSpeed: 20,
       
   384 		snap: false,
       
   385 		snapMode: "both",
       
   386 		snapTolerance: 20,
       
   387 		stack: false,
       
   388 		zIndex: null
       
   389 	}
       
   390 });
       
   391 
       
   392 $.ui.plugin.add("draggable", "connectToSortable", {
       
   393 	start: function(event, ui) {
       
   394 
       
   395 		var inst = $(this).data("draggable");
       
   396 		inst.sortables = [];
       
   397 		$(ui.options.connectToSortable).each(function() {
       
   398 			// 'this' points to a string, and should therefore resolved as query, but instead, if the string is assigned to a variable, it loops through the strings properties,
       
   399 			// so we have to append '' to make it anonymous again
       
   400 			$(this+'').each(function() {
       
   401 				if($.data(this, 'sortable')) {
       
   402 					var sortable = $.data(this, 'sortable');
       
   403 					inst.sortables.push({
       
   404 						instance: sortable,
       
   405 						shouldRevert: sortable.options.revert
       
   406 					});
       
   407 					sortable._refreshItems();	//Do a one-time refresh at start to refresh the containerCache
       
   408 					sortable._propagate("activate", event, inst);
       
   409 				}
       
   410 			});
       
   411 		});
       
   412 
       
   413 	},
       
   414 	stop: function(event, ui) {
       
   415 
       
   416 		//If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
       
   417 		var inst = $(this).data("draggable");
       
   418 
       
   419 		$.each(inst.sortables, function() {
       
   420 			if(this.instance.isOver) {
       
   421 				this.instance.isOver = 0;
       
   422 				inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
       
   423 				this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
       
   424 				if(this.shouldRevert) this.instance.options.revert = true; //revert here
       
   425 				this.instance._mouseStop(event);
       
   426 
       
   427 				//Also propagate receive event, since the sortable is actually receiving a element
       
   428 				this.instance.element.triggerHandler("sortreceive", [event, $.extend(this.instance._ui(), { sender: inst.element })], this.instance.options["receive"]);
       
   429 
       
   430 				this.instance.options.helper = this.instance.options._helper;
       
   431 				
       
   432 				if(inst.options.helper == 'original') {
       
   433 					this.instance.currentItem.css({ top: 'auto', left: 'auto' });
       
   434 				}
       
   435 
       
   436 			} else {
       
   437 				this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
       
   438 				this.instance._propagate("deactivate", event, inst);
       
   439 			}
       
   440 
       
   441 		});
       
   442 
       
   443 	},
       
   444 	drag: function(event, ui) {
       
   445 
       
   446 		var inst = $(this).data("draggable"), self = this;
       
   447 
       
   448 		var checkPos = function(o) {
       
   449 			var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
       
   450 			var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
       
   451 			var itemHeight = o.height, itemWidth = o.width;
       
   452 			var itemTop = o.top, itemLeft = o.left;
       
   453 
       
   454 			return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth);
       
   455 		};
       
   456 
       
   457 		$.each(inst.sortables, function(i) {
       
   458 
       
   459 			if(checkPos.call(inst, this.instance.containerCache)) {
       
   460 
       
   461 				//If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
       
   462 				if(!this.instance.isOver) {
       
   463 					this.instance.isOver = 1;
       
   464 					//Now we fake the start of dragging for the sortable instance,
       
   465 					//by cloning the list group item, appending it to the sortable and using it as inst.currentItem
       
   466 					//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)
       
   467 					this.instance.currentItem = $(self).clone().appendTo(this.instance.element).data("sortable-item", true);
       
   468 					this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
       
   469 					this.instance.options.helper = function() { return ui.helper[0]; };
       
   470 
       
   471 					event.target = this.instance.currentItem[0];
       
   472 					this.instance._mouseCapture(event, true);
       
   473 					this.instance._mouseStart(event, true, true);
       
   474 
       
   475 					//Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
       
   476 					this.instance.offset.click.top = inst.offset.click.top;
       
   477 					this.instance.offset.click.left = inst.offset.click.left;
       
   478 					this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
       
   479 					this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
       
   480 
       
   481 					inst._propagate("toSortable", event);
       
   482 
       
   483 				}
       
   484 
       
   485 				//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
       
   486 				if(this.instance.currentItem) this.instance._mouseDrag(event);
       
   487 
       
   488 			} else {
       
   489 
       
   490 				//If it doesn't intersect with the sortable, and it intersected before,
       
   491 				//we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
       
   492 				if(this.instance.isOver) {
       
   493 					this.instance.isOver = 0;
       
   494 					this.instance.cancelHelperRemoval = true;
       
   495 					this.instance.options.revert = false; //No revert here
       
   496 					this.instance._mouseStop(event, true);
       
   497 					this.instance.options.helper = this.instance.options._helper;
       
   498 
       
   499 					//Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
       
   500 					this.instance.currentItem.remove();
       
   501 					if(this.instance.placeholder) this.instance.placeholder.remove();
       
   502 
       
   503 					inst._propagate("fromSortable", event);
       
   504 				}
       
   505 
       
   506 			};
       
   507 
       
   508 		});
       
   509 
       
   510 	}
       
   511 });
       
   512 
       
   513 $.ui.plugin.add("draggable", "cursor", {
       
   514 	start: function(event, ui) {
       
   515 		var t = $('body');
       
   516 		if (t.css("cursor")) ui.options._cursor = t.css("cursor");
       
   517 		t.css("cursor", ui.options.cursor);
       
   518 	},
       
   519 	stop: function(event, ui) {
       
   520 		if (ui.options._cursor) $('body').css("cursor", ui.options._cursor);
       
   521 	}
       
   522 });
       
   523 
       
   524 $.ui.plugin.add("draggable", "iframeFix", {
       
   525 	start: function(event, ui) {
       
   526 		$(ui.options.iframeFix === true ? "iframe" : ui.options.iframeFix).each(function() {
       
   527 			$('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
       
   528 			.css({
       
   529 				width: this.offsetWidth+"px", height: this.offsetHeight+"px",
       
   530 				position: "absolute", opacity: "0.001", zIndex: 1000
       
   531 			})
       
   532 			.css($(this).offset())
       
   533 			.appendTo("body");
       
   534 		});
       
   535 	},
       
   536 	stop: function(event, ui) {
       
   537 		$("div.ui-draggable-iframeFix").each(function() { this.parentNode.removeChild(this); }); //Remove frame helpers
       
   538 	}
       
   539 });
       
   540 
       
   541 $.ui.plugin.add("draggable", "opacity", {
       
   542 	start: function(event, ui) {
       
   543 		var t = $(ui.helper);
       
   544 		if(t.css("opacity")) ui.options._opacity = t.css("opacity");
       
   545 		t.css('opacity', ui.options.opacity);
       
   546 	},
       
   547 	stop: function(event, ui) {
       
   548 		if(ui.options._opacity) $(ui.helper).css('opacity', ui.options._opacity);
       
   549 	}
       
   550 });
       
   551 
       
   552 $.ui.plugin.add("draggable", "scroll", {
       
   553 	start: function(event, ui) {
       
   554 		var o = ui.options;
       
   555 		var i = $(this).data("draggable");
       
   556 
       
   557 		if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset();
       
   558 
       
   559 	},
       
   560 	drag: function(event, ui) {
       
   561 
       
   562 		var o = ui.options, scrolled = false;
       
   563 		var i = $(this).data("draggable");
       
   564 
       
   565 		if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') {
       
   566 
       
   567 			if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
       
   568 				i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed;
       
   569 			else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity)
       
   570 				i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed;
       
   571 
       
   572 			if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
       
   573 				i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed;
       
   574 			else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity)
       
   575 				i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed;
       
   576 
       
   577 		} else {
       
   578 
       
   579 			if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
       
   580 				scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
       
   581 			else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
       
   582 				scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
       
   583 
       
   584 			if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
       
   585 				scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
       
   586 			else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
       
   587 				scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
       
   588 
       
   589 		}
       
   590 
       
   591 		if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
       
   592 			$.ui.ddmanager.prepareOffsets(i, event);
       
   593 
       
   594 
       
   595 
       
   596 		// This is a special case where we need to modify a offset calculated on start, since the following happened:
       
   597 		// 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
       
   598 		// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
       
   599 		//    the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
       
   600 		if(scrolled !== false && i.cssPosition == 'absolute' && i.scrollParent[0] != document && $.ui.contains(i.scrollParent[0], i.offsetParent[0])) {
       
   601 			i.offset.parent = i._getParentOffset();
       
   602 			
       
   603 		}
       
   604 		
       
   605 		// This is another very weird special case that only happens for relative elements:
       
   606 		// 1. If the css position is relative
       
   607 		// 2. and the scroll parent is the document or similar to the offset parent
       
   608 		// we have to refresh the relative offset during the scroll so there are no jumps
       
   609 		if(scrolled !== false && i.cssPosition == 'relative' && !(i.scrollParent[0] != document && i.scrollParent[0] != i.offsetParent[0])) {
       
   610 			i.offset.relative = i._getRelativeOffset();
       
   611 		}
       
   612 		
       
   613 
       
   614 	}
       
   615 });
       
   616 
       
   617 $.ui.plugin.add("draggable", "snap", {
       
   618 	start: function(event, ui) {
       
   619 
       
   620 		var inst = $(this).data("draggable");
       
   621 		inst.snapElements = [];
       
   622 
       
   623 		$(ui.options.snap.constructor != String ? ( ui.options.snap.items || ':data(draggable)' ) : ui.options.snap).each(function() {
       
   624 			var $t = $(this); var $o = $t.offset();
       
   625 			if(this != inst.element[0]) inst.snapElements.push({
       
   626 				item: this,
       
   627 				width: $t.outerWidth(), height: $t.outerHeight(),
       
   628 				top: $o.top, left: $o.left
       
   629 			});
       
   630 		});
       
   631 
       
   632 	},
       
   633 	drag: function(event, ui) {
       
   634 
       
   635 		var inst = $(this).data("draggable");
       
   636 		var d = ui.options.snapTolerance;
       
   637 
       
   638 		var x1 = ui.absolutePosition.left, x2 = x1 + inst.helperProportions.width,
       
   639 			y1 = ui.absolutePosition.top, y2 = y1 + inst.helperProportions.height;
       
   640 
       
   641 		for (var i = inst.snapElements.length - 1; i >= 0; i--){
       
   642 
       
   643 			var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width,
       
   644 				t = inst.snapElements[i].top, b = t + inst.snapElements[i].height;
       
   645 
       
   646 			//Yes, I know, this is insane ;)
       
   647 			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))) {
       
   648 				if(inst.snapElements[i].snapping) (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
       
   649 				inst.snapElements[i].snapping = false;
       
   650 				continue;
       
   651 			}
       
   652 
       
   653 			if(ui.options.snapMode != 'inner') {
       
   654 				var ts = Math.abs(t - y2) <= d;
       
   655 				var bs = Math.abs(b - y1) <= d;
       
   656 				var ls = Math.abs(l - x2) <= d;
       
   657 				var rs = Math.abs(r - x1) <= d;
       
   658 				if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top;
       
   659 				if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top;
       
   660 				if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left;
       
   661 				if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left;
       
   662 			}
       
   663 
       
   664 			var first = (ts || bs || ls || rs);
       
   665 
       
   666 			if(ui.options.snapMode != 'outer') {
       
   667 				var ts = Math.abs(t - y1) <= d;
       
   668 				var bs = Math.abs(b - y2) <= d;
       
   669 				var ls = Math.abs(l - x1) <= d;
       
   670 				var rs = Math.abs(r - x2) <= d;
       
   671 				if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top;
       
   672 				if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top;
       
   673 				if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left;
       
   674 				if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left;
       
   675 			}
       
   676 
       
   677 			if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first))
       
   678 				(inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
       
   679 			inst.snapElements[i].snapping = (ts || bs || ls || rs || first);
       
   680 
       
   681 		};
       
   682 
       
   683 	}
       
   684 });
       
   685 
       
   686 $.ui.plugin.add("draggable", "stack", {
       
   687 	start: function(event, ui) {
       
   688 		var group = $.makeArray($(ui.options.stack.group)).sort(function(a,b) {
       
   689 			return (parseInt($(a).css("zIndex"),10) || ui.options.stack.min) - (parseInt($(b).css("zIndex"),10) || ui.options.stack.min);
       
   690 		});
       
   691 
       
   692 		$(group).each(function(i) {
       
   693 			this.style.zIndex = ui.options.stack.min + i;
       
   694 		});
       
   695 
       
   696 		this[0].style.zIndex = ui.options.stack.min + group.length;
       
   697 	}
       
   698 });
       
   699 
       
   700 $.ui.plugin.add("draggable", "zIndex", {
       
   701 	start: function(event, ui) {
       
   702 		var t = $(ui.helper);
       
   703 		if(t.css("zIndex")) ui.options._zIndex = t.css("zIndex");
       
   704 		t.css('zIndex', ui.options.zIndex);
       
   705 	},
       
   706 	stop: function(event, ui) {
       
   707 		if(ui.options._zIndex) $(ui.helper).css('zIndex', ui.options._zIndex);
       
   708 	}
       
   709 });
       
   710 
       
   711 })(jQuery);