client/player/res/js/ui/jquery.ui.droppable.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.droppable.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 Droppable 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/Droppables
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.widget.js
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    13
 *	jquery.ui.mouse.js
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    14
 *	jquery.ui.draggable.js
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    15
 */
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    16
(function($) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    17
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    18
$.widget("ui.droppable", {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    19
	widgetEventPrefix: "drop",
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    20
	options: {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    21
		accept: '*',
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    22
		activeClass: false,
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    23
		addClasses: true,
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    24
		greedy: false,
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    25
		hoverClass: false,
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    26
		scope: 'default',
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    27
		tolerance: 'intersect'
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    28
	},
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    29
	_create: function() {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    30
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    31
		var o = this.options, accept = o.accept;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    32
		this.isover = 0; this.isout = 1;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    33
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    34
		this.accept = $.isFunction(accept) ? accept : function(d) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    35
			return d.is(accept);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    36
		};
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    37
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    38
		//Store the droppable's proportions
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    39
		this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    40
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    41
		// Add the reference and positions to the manager
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    42
		$.ui.ddmanager.droppables[o.scope] = $.ui.ddmanager.droppables[o.scope] || [];
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    43
		$.ui.ddmanager.droppables[o.scope].push(this);
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
		(o.addClasses && this.element.addClass("ui-droppable"));
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    46
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    47
	},
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
	destroy: function() {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    50
		var drop = $.ui.ddmanager.droppables[this.options.scope];
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    51
		for ( var i = 0; i < drop.length; i++ )
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    52
			if ( drop[i] == this )
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    53
				drop.splice(i, 1);
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
		this.element
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    56
			.removeClass("ui-droppable ui-droppable-disabled")
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    57
			.removeData("droppable")
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    58
			.unbind(".droppable");
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    59
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    60
		return this;
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
	_setOption: function(key, value) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    64
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    65
		if(key == 'accept') {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    66
			this.accept = $.isFunction(value) ? value : function(d) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    67
				return d.is(value);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    68
			};
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
		$.Widget.prototype._setOption.apply(this, arguments);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    71
	},
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
	_activate: function(event) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    74
		var draggable = $.ui.ddmanager.current;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    75
		if(this.options.activeClass) this.element.addClass(this.options.activeClass);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    76
		(draggable && this._trigger('activate', event, this.ui(draggable)));
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    77
	},
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    78
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    79
	_deactivate: function(event) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    80
		var draggable = $.ui.ddmanager.current;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    81
		if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    82
		(draggable && this._trigger('deactivate', event, this.ui(draggable)));
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    83
	},
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    84
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    85
	_over: function(event) {
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
		var draggable = $.ui.ddmanager.current;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    88
		if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
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.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    91
			if(this.options.hoverClass) this.element.addClass(this.options.hoverClass);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    92
			this._trigger('over', event, this.ui(draggable));
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
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
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
    97
	_out: function(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
		var draggable = $.ui.ddmanager.current;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   100
		if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   101
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   102
		if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   103
			if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   104
			this._trigger('out', event, this.ui(draggable));
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
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
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   109
	_drop: function(event,custom) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   110
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   111
		var draggable = custom || $.ui.ddmanager.current;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   112
		if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   113
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   114
		var childrenIntersection = false;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   115
		this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   116
			var inst = $.data(this, 'droppable');
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   117
			if(
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   118
				inst.options.greedy
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   119
				&& !inst.options.disabled
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   120
				&& inst.options.scope == draggable.options.scope
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   121
				&& inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element))
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   122
				&& $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   123
			) { childrenIntersection = true; return false; }
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   124
		});
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   125
		if(childrenIntersection) return false;
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
		if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   128
			if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   129
			if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   130
			this._trigger('drop', event, this.ui(draggable));
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   131
			return this.element;
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
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   134
		return false;
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
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   138
	ui: function(c) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   139
		return {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   140
			draggable: (c.currentItem || c.element),
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   141
			helper: c.helper,
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   142
			position: c.position,
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   143
			offset: c.positionAbs
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   144
		};
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   145
	}
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
});
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   148
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   149
$.extend($.ui.droppable, {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   150
	version: "1.8.1"
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   151
});
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
$.ui.intersect = function(draggable, droppable, toleranceMode) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   154
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   155
	if (!droppable.offset) return false;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   156
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   157
	var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   158
		y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   159
	var l = droppable.offset.left, r = l + droppable.proportions.width,
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   160
		t = droppable.offset.top, b = t + droppable.proportions.height;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   161
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   162
	switch (toleranceMode) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   163
		case 'fit':
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   164
			return (l < x1 && x2 < r
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   165
				&& t < y1 && y2 < b);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   166
			break;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   167
		case 'intersect':
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   168
			return (l < x1 + (draggable.helperProportions.width / 2) // Right Half
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   169
				&& x2 - (draggable.helperProportions.width / 2) < r // Left Half
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   170
				&& t < y1 + (draggable.helperProportions.height / 2) // Bottom Half
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   171
				&& y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   172
			break;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   173
		case 'pointer':
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   174
			var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left),
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   175
				draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top),
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   176
				isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   177
			return isOver;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   178
			break;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   179
		case 'touch':
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   180
			return (
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   181
					(y1 >= t && y1 <= b) ||	// Top edge touching
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   182
					(y2 >= t && y2 <= b) ||	// Bottom edge touching
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   183
					(y1 < t && y2 > b)		// Surrounded vertically
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   184
				) && (
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   185
					(x1 >= l && x1 <= r) ||	// Left edge touching
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   186
					(x2 >= l && x2 <= r) ||	// Right edge touching
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   187
					(x1 < l && x2 > r)		// Surrounded horizontally
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   188
				);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   189
			break;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   190
		default:
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   191
			return false;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   192
			break;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   193
		}
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
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   197
/*
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   198
	This manager tracks offsets of draggables and droppables
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
$.ui.ddmanager = {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   201
	current: null,
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   202
	droppables: { 'default': [] },
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   203
	prepareOffsets: function(t, event) {
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
		var m = $.ui.ddmanager.droppables[t.options.scope] || [];
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   206
		var type = event ? event.type : null; // workaround for #2317
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   207
		var list = (t.currentItem || t.element).find(":data(droppable)").andSelf();
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   208
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   209
		droppablesLoop: for (var i = 0; i < m.length; i++) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   210
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   211
			if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue;	//No disabled and non-accepted
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   212
			for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   213
			m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; 									//If the element is not visible, continue
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   214
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   215
			m[i].offset = m[i].element.offset();
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   216
			m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
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
			if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   219
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   220
		}
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
	drop: function(draggable, event) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   224
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   225
		var dropped = false;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   226
		$.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   227
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   228
			if(!this.options) return;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   229
			if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance))
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   230
				dropped = dropped || this._drop.call(this, event);
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
			if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   233
				this.isout = 1; this.isover = 0;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   234
				this._deactivate.call(this, event);
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
		return dropped;
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
	},
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   241
	drag: function(draggable, event) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   242
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   243
		//If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   244
		if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   245
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   246
		//Run through all droppables and check their positions based on specific tolerance options
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   247
		$.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   248
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   249
			if(this.options.disabled || this.greedyChild || !this.visible) return;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   250
			var intersects = $.ui.intersect(draggable, this, this.options.tolerance);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   251
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   252
			var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   253
			if(!c) return;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   254
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   255
			var parentInstance;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   256
			if (this.options.greedy) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   257
				var parent = this.element.parents(':data(droppable):eq(0)');
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   258
				if (parent.length) {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   259
					parentInstance = $.data(parent[0], 'droppable');
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   260
					parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   261
				}
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
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   264
			// we just moved into a greedy child
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   265
			if (parentInstance && c == 'isover') {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   266
				parentInstance['isover'] = 0;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   267
				parentInstance['isout'] = 1;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   268
				parentInstance._out.call(parentInstance, event);
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
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   271
			this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   272
			this[c == "isover" ? "_over" : "_out"].call(this, event);
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   273
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   274
			// we just moved out of a greedy child
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   275
			if (parentInstance && c == 'isout') {
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   276
				parentInstance['isout'] = 0;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   277
				parentInstance['isover'] = 1;
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   278
				parentInstance._over.call(parentInstance, 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
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   282
	}
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
44c6b827825d Commit new player (version radio) with new path organisation
hurons
parents:
diff changeset
   285
})(jQuery);