Merge "Added result properties to action=paraminfo"
[lhc/web/wiklou.git] / resources / jquery.ui / jquery.ui.sortable.js
index 2c94cb1..45fbb1c 100644 (file)
@@ -1,7 +1,7 @@
-/*
- * jQuery UI Sortable 1.8.16
+/*!
+ * jQuery UI Sortable 1.8.21
  *
- * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
+ * Copyright 2012, AUTHORS.txt (http://jqueryui.com/about)
  * Dual licensed under the MIT or GPL Version 2 licenses.
  * http://jquery.org/license
  *
@@ -16,6 +16,7 @@
 
 $.widget("ui.sortable", $.ui.mouse, {
        widgetEventPrefix: "sort",
+       ready: false,
        options: {
                appendTo: "parent",
                axis: false,
@@ -57,18 +58,20 @@ $.widget("ui.sortable", $.ui.mouse, {
 
                //Initialize mouse events for interaction
                this._mouseInit();
+               
+               //We're ready to go
+               this.ready = true
 
        },
 
        destroy: function() {
+               $.Widget.prototype.destroy.call( this );
                this.element
-                       .removeClass("ui-sortable ui-sortable-disabled")
-                       .removeData("sortable")
-                       .unbind(".sortable");
+                       .removeClass("ui-sortable ui-sortable-disabled");
                this._mouseDestroy();
 
                for ( var i = this.items.length - 1; i >= 0; i-- )
-                       this.items[i].item.removeData("sortable-item");
+                       this.items[i].item.removeData(this.widgetName + "-item");
 
                return this;
        },
@@ -86,6 +89,7 @@ $.widget("ui.sortable", $.ui.mouse, {
        },
 
        _mouseCapture: function(event, overrideHandle) {
+               var that = this;
 
                if (this.reverting) {
                        return false;
@@ -98,12 +102,12 @@ $.widget("ui.sortable", $.ui.mouse, {
 
                //Find out if the clicked node (or one of its parents) is a actual item in this.items
                var currentItem = null, self = this, nodes = $(event.target).parents().each(function() {
-                       if($.data(this, 'sortable-item') == self) {
+                       if($.data(this, that.widgetName + '-item') == self) {
                                currentItem = $(this);
                                return false;
                        }
                });
-               if($.data(event.target, 'sortable-item') == self) currentItem = $(event.target);
+               if($.data(event.target, that.widgetName + '-item') == self) currentItem = $(event.target);
 
                if(!currentItem) return false;
                if(this.options.handle && !overrideHandle) {
@@ -151,11 +155,6 @@ $.widget("ui.sortable", $.ui.mouse, {
                        left: this.offset.left - this.margins.left
                };
 
-               // Only after we got the offset, we can change the helper's position to absolute
-               // TODO: Still need to figure out a way to make relative sorting possible
-               this.helper.css("position", "absolute");
-               this.cssPosition = this.helper.css("position");
-
                $.extend(this.offset, {
                        click: { //Where the click happened, relative to the element
                                left: event.pageX - this.offset.left,
@@ -165,6 +164,11 @@ $.widget("ui.sortable", $.ui.mouse, {
                        relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
                });
 
+               // Only after we got the offset, we can change the helper's position to absolute
+               // TODO: Still need to figure out a way to make relative sorting possible
+               this.helper.css("position", "absolute");
+               this.cssPosition = this.helper.css("position");
+               
                //Generate the original position
                this.originalPosition = this._generatePosition(event);
                this.originalPageX = event.pageX;
@@ -464,8 +468,8 @@ $.widget("ui.sortable", $.ui.mouse, {
 
        _intersectsWithPointer: function(item) {
 
-               var isOverElementHeight = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
-                       isOverElementWidth = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
+               var isOverElementHeight = (this.options.axis === 'x') || $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
+                       isOverElementWidth = (this.options.axis === 'y') || $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
                        isOverElement = isOverElementHeight && isOverElementWidth,
                        verticalDirection = this._getDragVerticalDirection(),
                        horizontalDirection = this._getDragHorizontalDirection();
@@ -528,7 +532,7 @@ $.widget("ui.sortable", $.ui.mouse, {
                        for (var i = connectWith.length - 1; i >= 0; i--){
                                var cur = $(connectWith[i]);
                                for (var j = cur.length - 1; j >= 0; j--){
-                                       var inst = $.data(cur[j], 'sortable');
+                                       var inst = $.data(cur[j], this.widgetName);
                                        if(inst && inst != this && !inst.options.disabled) {
                                                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]);
                                        }
@@ -550,7 +554,7 @@ $.widget("ui.sortable", $.ui.mouse, {
 
        _removeCurrentsFromItems: function() {
 
-               var list = this.currentItem.find(":data(sortable-item)");
+               var list = this.currentItem.find(":data(" + this.widgetName + "-item)");
 
                for (var i=0; i < this.items.length; i++) {
 
@@ -572,11 +576,11 @@ $.widget("ui.sortable", $.ui.mouse, {
                var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]];
                var connectWith = this._connectWith();
 
-               if(connectWith) {
+               if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down
                        for (var i = connectWith.length - 1; i >= 0; i--){
                                var cur = $(connectWith[i]);
                                for (var j = cur.length - 1; j >= 0; j--){
-                                       var inst = $.data(cur[j], 'sortable');
+                                       var inst = $.data(cur[j], this.widgetName);
                                        if(inst && inst != this && !inst.options.disabled) {
                                                queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]);
                                                this.containers.push(inst);
@@ -592,7 +596,7 @@ $.widget("ui.sortable", $.ui.mouse, {
                        for (var j=0, queriesLength = _queries.length; j < queriesLength; j++) {
                                var item = $(_queries[j]);
 
-                               item.data('sortable-item', targetData); // Data for target checking (mouse manager)
+                               item.data(this.widgetName + '-item', targetData); // Data for target checking (mouse manager)
 
                                items.push({
                                        item: item,
@@ -726,30 +730,31 @@ $.widget("ui.sortable", $.ui.mouse, {
                if(this.containers.length === 1) {
                        this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
                        this.containers[innermostIndex].containerCache.over = 1;
-               } else if(this.currentContainer != this.containers[innermostIndex]) { 
-
-                       //When entering a new container, we will find the item with the least distance and append our item near it 
-                       var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[innermostIndex].floating ? 'left' : 'top']; 
-                       for (var j = this.items.length - 1; j >= 0; j--) { 
-                               if(!$.ui.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue; 
-                               var cur = this.items[j][this.containers[innermostIndex].floating ? 'left' : 'top']; 
-                               if(Math.abs(cur - base) < dist) { 
-                                       dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j]; 
-                               } 
-                       } 
-
-                       if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled 
-                               return; 
-
-                       this.currentContainer = this.containers[innermostIndex]; 
-                       itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true); 
-                       this._trigger("change", event, this._uiHash()); 
-                       this.containers[innermostIndex]._trigger("change", event, this._uiHash(this)); 
-
-                       //Update the placeholder 
-                       this.options.placeholder.update(this.currentContainer, this.placeholder); 
-               
-                       this.containers[innermostIndex]._trigger("over", event, this._uiHash(this)); 
+               } else if(this.currentContainer != this.containers[innermostIndex]) {
+
+                       //When entering a new container, we will find the item with the least distance and append our item near it
+                       var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[innermostIndex].floating ? 'left' : 'top'];
+                       for (var j = this.items.length - 1; j >= 0; j--) {
+                               if(!$.ui.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue;
+                               var cur = this.containers[innermostIndex].floating ? this.items[j].item.offset().left : this.items[j].item.offset().top;
+                               if(Math.abs(cur - base) < dist) {
+                                       dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
+                                       this.direction = (cur - base > 0) ? 'down' : 'up';
+                               }
+                       }
+
+                       if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled
+                               return;
+
+                       this.currentContainer = this.containers[innermostIndex];
+                       itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
+                       this._trigger("change", event, this._uiHash());
+                       this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
+
+                       //Update the placeholder
+                       this.options.placeholder.update(this.currentContainer, this.placeholder);
+
+                       this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
                        this.containers[innermostIndex].containerCache.over = 1;
                } 
        
@@ -1071,7 +1076,7 @@ $.widget("ui.sortable", $.ui.mouse, {
 });
 
 $.extend($.ui.sortable, {
-       version: "1.8.16"
+       version: "1.8.21"
 });
 
 })(jQuery);