Skip to content

Commit

Permalink
Core and Sortable: $.ui.contains method moved into the core. This met…
Browse files Browse the repository at this point in the history
…hod could be util for another components.
  • Loading branch information
eduardolundgren committed Nov 12, 2008
1 parent 657d31a commit d7707b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
16 changes: 14 additions & 2 deletions ui/ui.core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -66,7 +66,19 @@ $.ui = {
set[i][1].apply(instance.element, args); set[i][1].apply(instance.element, args);
} }
} }
} }
},

contains: function(a, b) {
var safari2 = $.browser.safari && $.browser.version < 522;
if (a.contains && !safari2) {
return a.contains(b);
}
if (a.compareDocumentPosition)
return !!(a.compareDocumentPosition(b) & 16);
while (b = b.parentNode)
if (b == a) return true;
return false;
}, },


cssCache: {}, cssCache: {},
Expand All @@ -80,7 +92,7 @@ $.ui = {
//Opera and Safari set width and height to 0px instead of auto //Opera and Safari set width and height to 0px instead of auto
//Safari returns rgba(0,0,0,0) when bgcolor is not set //Safari returns rgba(0,0,0,0) when bgcolor is not set
$.ui.cssCache[name] = !!( $.ui.cssCache[name] = !!(
(!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) || (!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) ||
!(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor'))) !(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor')))
); );
try { $('body').get(0).removeChild(tmp.get(0)); } catch(e){} try { $('body').get(0).removeChild(tmp.get(0)); } catch(e){}
Expand Down
28 changes: 10 additions & 18 deletions ui/ui.sortable.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
*/ */
(function($) { (function($) {


function contains(a, b) {
var safari2 = $.browser.safari && $.browser.version < 522;
if (a.contains && !safari2) {
return a.contains(b);
}
if (a.compareDocumentPosition)
return !!(a.compareDocumentPosition(b) & 16);
while (b = b.parentNode)
if (b == a) return true;
return false;
};

$.widget("ui.sortable", $.extend({}, $.ui.mouse, { $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
_init: function() { _init: function() {


Expand Down Expand Up @@ -160,6 +148,10 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
var itemHeight = item.height, itemWidth = item.width; var itemHeight = item.height, itemWidth = item.width;
var itemTop = item.top, itemLeft = item.left; var itemTop = item.top, itemLeft = item.left;


if (this.cancelIntersection) {
return false;
}

var isOverElementHeight = $.ui.isOverHeight(helperTop + dyClick, itemTop, itemHeight); var isOverElementHeight = $.ui.isOverHeight(helperTop + dyClick, itemTop, itemHeight);
var isOverElementWidth = $.ui.isOverWidth(helperLeft + dxClick, itemLeft, itemWidth); var isOverElementWidth = $.ui.isOverWidth(helperLeft + dxClick, itemLeft, itemWidth);
var isOverElement = isOverElementHeight && isOverElementWidth; var isOverElement = isOverElementHeight && isOverElementWidth;
Expand Down Expand Up @@ -419,7 +411,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
//When entering a new container, we will find the item with the least distance and append our item near it //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[i].floating ? 'left' : 'top']; var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[i].floating ? 'left' : 'top'];
for (var j = this.items.length - 1; j >= 0; j--) { for (var j = this.items.length - 1; j >= 0; j--) {
if(!contains(this.containers[i].element[0], this.items[j].item[0])) continue; if(!$.ui.contains(this.containers[i].element[0], this.items[j].item[0])) continue;
var cur = this.items[j][this.containers[i].floating ? 'left' : 'top']; var cur = this.items[j][this.containers[i].floating ? 'left' : 'top'];
if(Math.abs(cur - base) < dist) { if(Math.abs(cur - base) < dist) {
dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j]; dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
Expand Down Expand Up @@ -711,14 +703,14 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {


var intersection = this._intersectsWithEdge(this.items[i]); var intersection = this._intersectsWithEdge(this.items[i]);


if(!intersection) continue; if (!intersection) continue;


var item = this.items[i].item[0]; var item = this.items[i].item[0];


if(item != this.currentItem[0] //cannot intersect with itself if(item != this.currentItem[0] //cannot intersect with itself
&& this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != item //no useless actions that have been done before && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != item //no useless actions that have been done before
&& !contains(this.placeholder[0], item) //no action if the item moved is the parent of the item checked && !$.ui.contains(this.placeholder[0], item) //no action if the item moved is the parent of the item checked
&& (this.options.type == 'semi-dynamic' ? !contains(this.element[0], item) : true) && (this.options.type == 'semi-dynamic' ? !$.ui.contains(this.element[0], item) : true)
) { ) {


this.direction = intersection == 1 ? "down" : "up"; this.direction = intersection == 1 ? "down" : "up";
Expand Down Expand Up @@ -803,10 +795,10 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
this.currentItem.show(); this.currentItem.show();


if(this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) this._propagate("update", e, null, noPropagation); //Trigger update callback if the DOM position has changed if(this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) this._propagate("update", e, null, noPropagation); //Trigger update callback if the DOM position has changed
if(!contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element if(!$.ui.contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element
this._propagate("remove", e, null, noPropagation); this._propagate("remove", e, null, noPropagation);
for (var i = this.containers.length - 1; i >= 0; i--){ for (var i = this.containers.length - 1; i >= 0; i--){
if(contains(this.containers[i].element[0], this.currentItem[0])) { if($.ui.contains(this.containers[i].element[0], this.currentItem[0])) {
this.containers[i]._propagate("update", e, this, noPropagation); this.containers[i]._propagate("update", e, this, noPropagation);
this.containers[i]._propagate("receive", e, this, noPropagation); this.containers[i]._propagate("receive", e, this, noPropagation);
} }
Expand Down

0 comments on commit d7707b1

Please sign in to comment.