client/player/development-bundle/ui/jquery.ui.sortable.js
author ymh <ymh.work@gmail.com>
Sat, 12 Jun 2010 04:25:05 +0200
changeset 0 cc4a51750724
permissions -rw-r--r--
first commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
/*
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
 * jQuery UI Sortable 1.8.1
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 *
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * Dual licensed under the MIT (MIT-LICENSE.txt)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * and GPL (GPL-LICENSE.txt) licenses.
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 *
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * http://docs.jquery.com/UI/Sortables
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 *
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * Depends:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *	jquery.ui.core.js
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 *	jquery.ui.mouse.js
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 *	jquery.ui.widget.js
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 */
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
(function($) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
$.widget("ui.sortable", $.ui.mouse, {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
	widgetEventPrefix: "sort",
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	options: {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
		appendTo: "parent",
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
		axis: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
		connectWith: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
		containment: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
		cursor: 'auto',
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		cursorAt: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		dropOnEmpty: true,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
		forcePlaceholderSize: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
		forceHelperSize: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		grid: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
		handle: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		helper: "original",
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
		items: '> *',
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
		opacity: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
		placeholder: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
		revert: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
		scroll: true,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
		scrollSensitivity: 20,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
		scrollSpeed: 20,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
		scope: "default",
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
		tolerance: "intersect",
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
		zIndex: 1000
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	_create: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
		var o = this.options;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
		this.containerCache = {};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
		this.element.addClass("ui-sortable");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		//Get the items
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
		this.refresh();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
		//Let's determine if the items are floating
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
		this.floating = this.items.length ? (/left|right/).test(this.items[0].item.css('float')) : false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
		//Let's determine the parent's offset
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		this.offset = this.element.offset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
		//Initialize mouse events for interaction
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		this._mouseInit();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	destroy: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
		this.element
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
			.removeClass("ui-sortable ui-sortable-disabled")
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
			.removeData("sortable")
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
			.unbind(".sortable");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
		this._mouseDestroy();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
		for ( var i = this.items.length - 1; i >= 0; i-- )
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
			this.items[i].item.removeData("sortable-item");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
		return this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	_setOption: function(key, value){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
		if ( key === "disabled" ) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
			this.options[ key ] = value;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
			this.widget()
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
				[ value ? "addClass" : "removeClass"]( "ui-sortable-disabled" );
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
			// Don't call widget base _setOption for disable as it adds ui-state-disabled class
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
			$.Widget.prototype._setOption.apply(self, arguments);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	_mouseCapture: function(event, overrideHandle) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		if (this.reverting) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
			return false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		if(this.options.disabled || this.options.type == 'static') return false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
		//We have to refresh the items data once first
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
		this._refreshItems(event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
		//Find out if the clicked node (or one of its parents) is a actual item in this.items
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
		var currentItem = null, self = this, nodes = $(event.target).parents().each(function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
			if($.data(this, 'sortable-item') == self) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
				currentItem = $(this);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
				return false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
		});
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		if($.data(event.target, 'sortable-item') == self) currentItem = $(event.target);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
		if(!currentItem) return false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
		if(this.options.handle && !overrideHandle) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
			var validHandle = false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
			$(this.options.handle, currentItem).find("*").andSelf().each(function() { if(this == event.target) validHandle = true; });
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
			if(!validHandle) return false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
		this.currentItem = currentItem;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		this._removeCurrentsFromItems();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		return true;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
	_mouseStart: function(event, overrideHandle, noActivation) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
		var o = this.options, self = this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
		this.currentContainer = this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
		//We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
		this.refreshPositions();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
		//Create and append the visible helper
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		this.helper = this._createHelper(event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		//Cache the helper size
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
		this._cacheHelperProportions();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		/*
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
		 * - Position generation -
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
		 * This block generates everything position related - it's the core of draggables.
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
		 */
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
		//Cache the margins of the original element
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
		this._cacheMargins();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
		//Get the next scrolling parent
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
		this.scrollParent = this.helper.scrollParent();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
		//The element's absolute position on the page minus margins
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
		this.offset = this.currentItem.offset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
		this.offset = {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
			top: this.offset.top - this.margins.top,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
			left: this.offset.left - this.margins.left
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
		// Only after we got the offset, we can change the helper's position to absolute
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
		// TODO: Still need to figure out a way to make relative sorting possible
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
		this.helper.css("position", "absolute");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
		this.cssPosition = this.helper.css("position");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
		$.extend(this.offset, {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
			click: { //Where the click happened, relative to the element
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
				left: event.pageX - this.offset.left,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
				top: event.pageY - this.offset.top
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
			},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
			parent: this._getParentOffset(),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
			relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
		});
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
		//Generate the original position
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
		this.originalPosition = this._generatePosition(event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
		this.originalPageX = event.pageX;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		this.originalPageY = event.pageY;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
		//Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
		(o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
		//Cache the former DOM position
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
		this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] };
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
		//If the helper is not the original, hide the original so it's not playing any role during the drag, won't cause anything bad this way
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
		if(this.helper[0] != this.currentItem[0]) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
			this.currentItem.hide();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
		//Create the placeholder
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
		this._createPlaceholder();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
		//Set a containment if given in the options
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
		if(o.containment)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
			this._setContainment();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
		if(o.cursor) { // cursor option
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
			if ($('body').css("cursor")) this._storedCursor = $('body').css("cursor");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
			$('body').css("cursor", o.cursor);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
		if(o.opacity) { // opacity option
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
			if (this.helper.css("opacity")) this._storedOpacity = this.helper.css("opacity");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
			this.helper.css("opacity", o.opacity);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		if(o.zIndex) { // zIndex option
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
			if (this.helper.css("zIndex")) this._storedZIndex = this.helper.css("zIndex");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
			this.helper.css("zIndex", o.zIndex);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
		//Prepare scrolling
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
		if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML')
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
			this.overflowOffset = this.scrollParent.offset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		//Call callbacks
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
		this._trigger("start", event, this._uiHash());
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
		//Recache the helper size
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
		if(!this._preserveHelperProportions)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
			this._cacheHelperProportions();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
		//Post 'activate' events to possible containers
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
		if(!noActivation) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
			 for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, self._uiHash(this)); }
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
		//Prepare possible droppables
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
		if($.ui.ddmanager)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
			$.ui.ddmanager.current = this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
		if ($.ui.ddmanager && !o.dropBehaviour)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
			$.ui.ddmanager.prepareOffsets(this, event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
		this.dragging = true;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		this.helper.addClass("ui-sortable-helper");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
		this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
		return true;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
	_mouseDrag: function(event) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
		//Compute the helpers position
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
		this.position = this._generatePosition(event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
		this.positionAbs = this._convertPositionTo("absolute");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
		if (!this.lastPositionAbs) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
			this.lastPositionAbs = this.positionAbs;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
		//Do scrolling
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
		if(this.options.scroll) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
			var o = this.options, scrolled = false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
			if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
				if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
					this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
				else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
					this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
				if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
					this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
				else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
					this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
			} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
				if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
					scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
				else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
					scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
				if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
					scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
				else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
					scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
			if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
				$.ui.ddmanager.prepareOffsets(this, event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
		//Regenerate the absolute position used for position checks
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
		this.positionAbs = this._convertPositionTo("absolute");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
		//Set the helper position
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
		if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
		if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
		//Rearrange
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
		for (var i = this.items.length - 1; i >= 0; i--) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
			//Cache variables and intersection, continue if no intersection
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
			var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
			if (!intersection) continue;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
			if(itemElement != this.currentItem[0] //cannot intersect with itself
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
				&&	this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
				&&	!$.ui.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
				&& (this.options.type == 'semi-dynamic' ? !$.ui.contains(this.element[0], itemElement) : true)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
				//&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
			) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
				this.direction = intersection == 1 ? "down" : "up";
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
				if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
					this._rearrange(event, item);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
				} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
					break;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
				}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
				this._trigger("change", event, this._uiHash());
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
				break;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
		//Post events to containers
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
		this._contactContainers(event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
		//Interconnect with droppables
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
		if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
		//Call callbacks
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
		this._trigger('sort', event, this._uiHash());
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
		this.lastPositionAbs = this.positionAbs;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
		return false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
	_mouseStop: function(event, noPropagation) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
		if(!event) return;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
		//If we are using droppables, inform the manager about the drop
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
		if ($.ui.ddmanager && !this.options.dropBehaviour)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
			$.ui.ddmanager.drop(this, event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
		if(this.options.revert) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
			var self = this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
			var cur = self.placeholder.offset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
			self.reverting = true;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
			$(this.helper).animate({
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
				left: cur.left - this.offset.parent.left - self.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
				top: cur.top - this.offset.parent.top - self.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
			}, parseInt(this.options.revert, 10) || 500, function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
				self._clear(event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
			});
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
		} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
			this._clear(event, noPropagation);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		return false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
	cancel: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
		var self = this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
		if(this.dragging) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
			this._mouseUp();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
			if(this.options.helper == "original")
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
				this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
			else
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
				this.currentItem.show();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
			//Post deactivating events to containers
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
			for (var i = this.containers.length - 1; i >= 0; i--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
				this.containers[i]._trigger("deactivate", null, self._uiHash(this));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
				if(this.containers[i].containerCache.over) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
					this.containers[i]._trigger("out", null, self._uiHash(this));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
					this.containers[i].containerCache.over = 0;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
				}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
		//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
		if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
		if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
		$.extend(this, {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
			helper: null,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
			dragging: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
			reverting: false,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
			_noFinalSort: null
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
		});
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
		if(this.domPosition.prev) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
			$(this.domPosition.prev).after(this.currentItem);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
		} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
			$(this.domPosition.parent).prepend(this.currentItem);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
		return this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
	serialize: function(o) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
		var items = this._getItemsAsjQuery(o && o.connected);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
		var str = []; o = o || {};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
		$(items).each(function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
			var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
			if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2]));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
		});
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
		return str.join('&');
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
	toArray: function(o) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
		var items = this._getItemsAsjQuery(o && o.connected);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
		var ret = []; o = o || {};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
		items.each(function() { ret.push($(o.item || this).attr(o.attribute || 'id') || ''); });
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
		return ret;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
	/* Be careful with the following core functions */
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
	_intersectsWith: function(item) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
		var x1 = this.positionAbs.left,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
			x2 = x1 + this.helperProportions.width,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
			y1 = this.positionAbs.top,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
			y2 = y1 + this.helperProportions.height;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
		var l = item.left,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
			r = l + item.width,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
			t = item.top,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
			b = t + item.height;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
		var dyClick = this.offset.click.top,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
			dxClick = this.offset.click.left;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
		var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
		if(	   this.options.tolerance == "pointer"
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
			|| this.options.forcePointerForContainers
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
			|| (this.options.tolerance != "pointer" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
		) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
			return isOverElement;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
		} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
			return (l < x1 + (this.helperProportions.width / 2) // Right Half
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
				&& x2 - (this.helperProportions.width / 2) < r // Left Half
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
				&& t < y1 + (this.helperProportions.height / 2) // Bottom Half
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
				&& y2 - (this.helperProportions.height / 2) < b ); // Top Half
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
	_intersectsWithPointer: function(item) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
		var isOverElementHeight = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
			isOverElementWidth = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
			isOverElement = isOverElementHeight && isOverElementWidth,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
			verticalDirection = this._getDragVerticalDirection(),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
			horizontalDirection = this._getDragHorizontalDirection();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
		if (!isOverElement)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
			return false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
		return this.floating ?
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
			( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 )
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
			: ( verticalDirection && (verticalDirection == "down" ? 2 : 1) );
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
	_intersectsWithSides: function(item) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
		var isOverBottomHalf = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
			isOverRightHalf = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
			verticalDirection = this._getDragVerticalDirection(),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
			horizontalDirection = this._getDragHorizontalDirection();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		if (this.floating && horizontalDirection) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
			return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
		} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
			return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && !isOverBottomHalf));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	_getDragVerticalDirection: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
		var delta = this.positionAbs.top - this.lastPositionAbs.top;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
		return delta != 0 && (delta > 0 ? "down" : "up");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
	_getDragHorizontalDirection: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
		var delta = this.positionAbs.left - this.lastPositionAbs.left;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
		return delta != 0 && (delta > 0 ? "right" : "left");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	refresh: function(event) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
		this._refreshItems(event);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
		this.refreshPositions();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
		return this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
	_connectWith: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
		var options = this.options;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
		return options.connectWith.constructor == String
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
			? [options.connectWith]
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
			: options.connectWith;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
	
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
	_getItemsAsjQuery: function(connected) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
		var self = this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
		var items = [];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
		var queries = [];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
		var connectWith = this._connectWith();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
		if(connectWith && connected) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
			for (var i = connectWith.length - 1; i >= 0; i--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
				var cur = $(connectWith[i]);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
				for (var j = cur.length - 1; j >= 0; j--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
					var inst = $.data(cur[j], 'sortable');
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
					if(inst && inst != this && !inst.options.disabled) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
						queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), inst]);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
					}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
				};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
			};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
		queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not('.ui-sortable-placeholder'), this]);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
		for (var i = queries.length - 1; i >= 0; i--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
			queries[i][0].each(function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
				items.push(this);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
			});
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
		return $(items);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
	_removeCurrentsFromItems: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
		var list = this.currentItem.find(":data(sortable-item)");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
		for (var i=0; i < this.items.length; i++) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
			for (var j=0; j < list.length; j++) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
				if(list[j] == this.items[i].item[0])
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
					this.items.splice(i,1);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
			};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
	_refreshItems: function(event) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
		this.items = [];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
		this.containers = [this];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
		var items = this.items;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
		var self = this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
		var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
		var connectWith = this._connectWith();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
		if(connectWith) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
			for (var i = connectWith.length - 1; i >= 0; i--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
				var cur = $(connectWith[i]);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
				for (var j = cur.length - 1; j >= 0; j--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
					var inst = $.data(cur[j], 'sortable');
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
					if(inst && inst != this && !inst.options.disabled) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
						queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
						this.containers.push(inst);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
					}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
				};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
			};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
		for (var i = queries.length - 1; i >= 0; i--) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
			var targetData = queries[i][1];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
			var _queries = queries[i][0];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
			for (var j=0, queriesLength = _queries.length; j < queriesLength; j++) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
				var item = $(_queries[j]);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
				item.data('sortable-item', targetData); // Data for target checking (mouse manager)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
				items.push({
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
					item: item,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
					instance: targetData,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
					width: 0, height: 0,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
					left: 0, top: 0
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
				});
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
			};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	refreshPositions: function(fast) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
		//This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
		if(this.offsetParent && this.helper) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
			this.offset.parent = this._getParentOffset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
		for (var i = this.items.length - 1; i >= 0; i--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
			var item = this.items[i];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
			var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
			if (!fast) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
				item.width = t.outerWidth();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
				item.height = t.outerHeight();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
			var p = t.offset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
			item.left = p.left;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
			item.top = p.top;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
		if(this.options.custom && this.options.custom.refreshContainers) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
			this.options.custom.refreshContainers.call(this);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
		} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
			for (var i = this.containers.length - 1; i >= 0; i--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
				var p = this.containers[i].element.offset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
				this.containers[i].containerCache.left = p.left;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
				this.containers[i].containerCache.top = p.top;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
				this.containers[i].containerCache.width	= this.containers[i].element.outerWidth();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
				this.containers[i].containerCache.height = this.containers[i].element.outerHeight();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
			};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
		return this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
	_createPlaceholder: function(that) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
		var self = that || this, o = self.options;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
		if(!o.placeholder || o.placeholder.constructor == String) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
			var className = o.placeholder;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
			o.placeholder = {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
				element: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
					var el = $(document.createElement(self.currentItem[0].nodeName))
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
						.addClass(className || self.currentItem[0].className+" ui-sortable-placeholder")
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
						.removeClass("ui-sortable-helper")[0];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
					if(!className)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
						el.style.visibility = "hidden";
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
					return el;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
				},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
				update: function(container, p) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
					// 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
					// 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
					if(className && !o.forcePlaceholderSize) return;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
					//If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
					if(!p.height()) { p.height(self.currentItem.innerHeight() - parseInt(self.currentItem.css('paddingTop')||0, 10) - parseInt(self.currentItem.css('paddingBottom')||0, 10)); };
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
					if(!p.width()) { p.width(self.currentItem.innerWidth() - parseInt(self.currentItem.css('paddingLeft')||0, 10) - parseInt(self.currentItem.css('paddingRight')||0, 10)); };
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
				}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
			};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
		//Create the placeholder
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
		self.placeholder = $(o.placeholder.element.call(self.element, self.currentItem));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
		//Append it after the actual current item
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
		self.currentItem.after(self.placeholder);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
		//Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
		o.placeholder.update(self, self.placeholder);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
	_contactContainers: function(event) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
		
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
		// get innermost container that intersects with item 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
		var innermostContainer = null, innermostIndex = null;		
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
		
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
		
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
		for (var i = this.containers.length - 1; i >= 0; i--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
			// never consider a container that's located within the item itself 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
			if($.ui.contains(this.currentItem[0], this.containers[i].element[0]))
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
				continue;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
			if(this._intersectsWith(this.containers[i].containerCache)) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
				// if we've already found a container and it's more "inner" than this, then continue 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
				if(innermostContainer && $.ui.contains(this.containers[i].element[0], innermostContainer.element[0]))
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
					continue;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
				innermostContainer = this.containers[i]; 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
				innermostIndex = i;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
					
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
			} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
				// container doesn't intersect. trigger "out" event if necessary 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
				if(this.containers[i].containerCache.over) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
					this.containers[i]._trigger("out", event, this._uiHash(this));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
					this.containers[i].containerCache.over = 0;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
				}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
		
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
		// if no intersecting containers found, return 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
		if(!innermostContainer) return; 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		// move the item into the container if it's not there already
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
		if(this.containers.length === 1) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
			this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
			this.containers[innermostIndex].containerCache.over = 1;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
		} else if(this.currentContainer != this.containers[innermostIndex]) { 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
			//When entering a new container, we will find the item with the least distance and append our item near it 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
			var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[innermostIndex].floating ? 'left' : 'top']; 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
			for (var j = this.items.length - 1; j >= 0; j--) { 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
				if(!$.ui.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue; 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
				var cur = this.items[j][this.containers[innermostIndex].floating ? 'left' : 'top']; 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
				if(Math.abs(cur - base) < dist) { 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
					dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j]; 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
				} 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
			} 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
			if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
				return; 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
			this.currentContainer = this.containers[innermostIndex]; 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
			itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true); 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
			this._trigger("change", event, this._uiHash()); 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
			this.containers[innermostIndex]._trigger("change", event, this._uiHash(this)); 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
			//Update the placeholder 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
			this.options.placeholder.update(this.currentContainer, this.placeholder); 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
		
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
			this.containers[innermostIndex]._trigger("over", event, this._uiHash(this)); 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
			this.containers[innermostIndex].containerCache.over = 1;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
		} 
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
	
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
		
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
	_createHelper: function(event) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
		var o = this.options;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
		var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper == 'clone' ? this.currentItem.clone() : this.currentItem);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
		if(!helper.parents('body').length) //Add the helper to the DOM if that didn't happen already
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
			$(o.appendTo != 'parent' ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
		if(helper[0] == this.currentItem[0])
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
			this._storedCSS = { width: this.currentItem[0].style.width, height: this.currentItem[0].style.height, position: this.currentItem.css("position"), top: this.currentItem.css("top"), left: this.currentItem.css("left") };
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
		if(helper[0].style.width == '' || o.forceHelperSize) helper.width(this.currentItem.width());
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
		if(helper[0].style.height == '' || o.forceHelperSize) helper.height(this.currentItem.height());
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
		return helper;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
	_adjustOffsetFromHelper: function(obj) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
		if (typeof obj == 'string') {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
			obj = obj.split(' ');
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
		if ($.isArray(obj)) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
			obj = {left: +obj[0], top: +obj[1] || 0};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
		if ('left' in obj) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
			this.offset.click.left = obj.left + this.margins.left;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
		if ('right' in obj) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
			this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
		if ('top' in obj) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
			this.offset.click.top = obj.top + this.margins.top;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
		if ('bottom' in obj) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
			this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
	_getParentOffset: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
		//Get the offsetParent and cache its position
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
		this.offsetParent = this.helper.offsetParent();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
		var po = this.offsetParent.offset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
		// This is a special case where we need to modify a offset calculated on start, since the following happened:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
		// 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
		// 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
		//    the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
		if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
			po.left += this.scrollParent.scrollLeft();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
			po.top += this.scrollParent.scrollTop();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
		if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
		|| (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
			po = { top: 0, left: 0 };
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
		return {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
			top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
			left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
	_getRelativeOffset: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
		if(this.cssPosition == "relative") {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
			var p = this.currentItem.position();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
			return {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
				top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
				left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
			};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
		} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
			return { top: 0, left: 0 };
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
	_cacheMargins: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
		this.margins = {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
			left: (parseInt(this.currentItem.css("marginLeft"),10) || 0),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
			top: (parseInt(this.currentItem.css("marginTop"),10) || 0)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
	_cacheHelperProportions: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
		this.helperProportions = {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
			width: this.helper.outerWidth(),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
			height: this.helper.outerHeight()
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
	_setContainment: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
		var o = this.options;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
		if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
		if(o.containment == 'document' || o.containment == 'window') this.containment = [
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
			0 - this.offset.relative.left - this.offset.parent.left,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
			0 - this.offset.relative.top - this.offset.parent.top,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
			$(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
			($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
		];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
		if(!(/^(document|window|parent)$/).test(o.containment)) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
			var ce = $(o.containment)[0];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
			var co = $(o.containment).offset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
			var over = ($(ce).css("overflow") != 'hidden');
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
			this.containment = [
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
				co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
				co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
				co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
				co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
			];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
	_convertPositionTo: function(d, pos) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
		if(!pos) pos = this.position;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
		var mod = d == "absolute" ? 1 : -1;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
		var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
		return {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
			top: (
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
				pos.top																	// The absolute mouse position
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
				+ this.offset.relative.top * mod										// Only for relative positioned nodes: Relative offset from element to offset parent
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
				+ this.offset.parent.top * mod											// The offsetParent's offset without borders (offset + border)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
				- ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
			),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
			left: (
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
				pos.left																// The absolute mouse position
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
				+ this.offset.relative.left * mod										// Only for relative positioned nodes: Relative offset from element to offset parent
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
				+ this.offset.parent.left * mod											// The offsetParent's offset without borders (offset + border)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
				- ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
			)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
	_generatePosition: function(event) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
		var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
		// This is another very weird special case that only happens for relative elements:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
		// 1. If the css position is relative
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
		// 2. and the scroll parent is the document or similar to the offset parent
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
		// we have to refresh the relative offset during the scroll so there are no jumps
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
		if(this.cssPosition == 'relative' && !(this.scrollParent[0] != document && this.scrollParent[0] != this.offsetParent[0])) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
			this.offset.relative = this._getRelativeOffset();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
		var pageX = event.pageX;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
		var pageY = event.pageY;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
		/*
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
		 * - Position constraining -
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
		 * Constrain the position to a mix of grid, containment.
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
		 */
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
		if(this.originalPosition) { //If we are not dragging yet, we won't check for options
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
			if(this.containment) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
				if(event.pageX - this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
				if(event.pageY - this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
				if(event.pageX - this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
				if(event.pageY - this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
			if(o.grid) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
				var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
				pageY = this.containment ? (!(top - this.offset.click.top < this.containment[1] || top - this.offset.click.top > this.containment[3]) ? top : (!(top - this.offset.click.top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
				var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
				pageX = this.containment ? (!(left - this.offset.click.left < this.containment[0] || left - this.offset.click.left > this.containment[2]) ? left : (!(left - this.offset.click.left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
		return {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
			top: (
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
				pageY																// The absolute mouse position
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
				- this.offset.click.top													// Click offset (relative to the element)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
				- this.offset.relative.top												// Only for relative positioned nodes: Relative offset from element to offset parent
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
				- this.offset.parent.top												// The offsetParent's offset without borders (offset + border)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
				+ ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
			),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
			left: (
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
				pageX																// The absolute mouse position
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
				- this.offset.click.left												// Click offset (relative to the element)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
				- this.offset.relative.left												// Only for relative positioned nodes: Relative offset from element to offset parent
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
				- this.offset.parent.left												// The offsetParent's offset without borders (offset + border)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
				+ ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
			)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
	_rearrange: function(event, i, a, hardRefresh) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
		a ? a[0].appendChild(this.placeholder[0]) : i.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction == 'down' ? i.item[0] : i.item[0].nextSibling));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
		//Various things done here to improve the performance:
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
		// 1. we create a setTimeout, that calls refreshPositions
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
		// 2. on the instance, we have a counter variable, that get's higher after every append
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
		// 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
		// 4. this lets only the last addition to the timeout stack through
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
		this.counter = this.counter ? ++this.counter : 1;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
		var self = this, counter = this.counter;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
		window.setTimeout(function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
			if(counter == self.counter) self.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
		},0);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
	_clear: function(event, noPropagation) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
		this.reverting = false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
		// We delay all events that have to be triggered to after the point where the placeholder has been removed and
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
		// everything else normalized again
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
		var delayedTriggers = [], self = this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
		// We first have to update the dom position of the actual currentItem
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
		// Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088)
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
		if(!this._noFinalSort && this.currentItem[0].parentNode) this.placeholder.before(this.currentItem);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
		this._noFinalSort = null;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
		if(this.helper[0] == this.currentItem[0]) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
			for(var i in this._storedCSS) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
				if(this._storedCSS[i] == 'auto' || this._storedCSS[i] == 'static') this._storedCSS[i] = '';
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
			this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
		} else {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
			this.currentItem.show();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
		if(this.fromOutside && !noPropagation) delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); });
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
		if((this.fromOutside || this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) && !noPropagation) delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
		if(!$.ui.contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
			if(!noPropagation) delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); });
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
			for (var i = this.containers.length - 1; i >= 0; i--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
				if($.ui.contains(this.containers[i].element[0], this.currentItem[0]) && !noPropagation) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
					delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); };  }).call(this, this.containers[i]));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
					delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this));  }; }).call(this, this.containers[i]));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
				}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
			};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
		//Post events to containers
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
		for (var i = this.containers.length - 1; i >= 0; i--){
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
			if(!noPropagation) delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); };  }).call(this, this.containers[i]));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
			if(this.containers[i].containerCache.over) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
				delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); };  }).call(this, this.containers[i]));
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
				this.containers[i].containerCache.over = 0;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
		//Do what was originally in plugins
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
		if(this._storedCursor) $('body').css("cursor", this._storedCursor); //Reset cursor
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
		if(this._storedOpacity) this.helper.css("opacity", this._storedOpacity); //Reset opacity
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
		if(this._storedZIndex) this.helper.css("zIndex", this._storedZIndex == 'auto' ? '' : this._storedZIndex); //Reset z-index
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
		this.dragging = false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
		if(this.cancelHelperRemoval) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
			if(!noPropagation) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
				this._trigger("beforeStop", event, this._uiHash());
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
				for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
				this._trigger("stop", event, this._uiHash());
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
			}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
			return false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
		if(!noPropagation) this._trigger("beforeStop", event, this._uiHash());
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
		//$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
		this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
		if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
		if(!noPropagation) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
			for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
			this._trigger("stop", event, this._uiHash());
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
		this.fromOutside = false;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
		return true;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
	_trigger: function() {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
		if ($.Widget.prototype._trigger.apply(this, arguments) === false) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
			this.cancel();
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
		}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
	},
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
	_uiHash: function(inst) {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1049
		var self = inst || this;
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
		return {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1051
			helper: self.helper,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
			placeholder: self.placeholder || $([]),
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
			position: self.position,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
			originalPosition: self.originalPosition,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1055
			offset: self.positionAbs,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
			item: self.currentItem,
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
			sender: inst ? inst.element : null
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
		};
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
	}
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
});
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
$.extend($.ui.sortable, {
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1064
	version: "1.8.1"
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
});
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1066
cc4a51750724 first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1067
})(jQuery);