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