Changeset 435

Show
Ignore:
Timestamp:
07/09/08 17:56:29 (20 months ago)
Author:
eduardo.lundgren
Message:

Sortable math accuracy for tolerance pointer - checking the direction before rearrange

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/ui.sortable.js

    r432 r435  
    9191                var l = item.left, r = l + item.width,  
    9292                t = item.top, b = t + item.height; 
    93  
    94                 if (this.options.tolerance == "pointer" || this.options.forcePointerForContainers || (this.options.tolerance == "guess" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])) { 
    95                         return (y1 + this.offset.click.top > t && y1 + this.offset.click.top < b && x1 + this.offset.click.left > l && x1 + this.offset.click.left < r); 
     93                 
     94                var dyClick = this.offset.click.top, dxClick = this.offset.click.left; 
     95                var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r; 
     96                 
     97                if(this.options.tolerance == "pointer" || this.options.forcePointerForContainers || (this.options.tolerance == "guess" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])) { 
     98                        return isOverElement; 
    9699                } else { 
     100                 
    97101                        return (l < x1 + (this.helperProportions.width / 2) // Right Half 
    98102                                && x2 - (this.helperProportions.width / 2) < r // Left Half 
    99103                                && t < y1 + (this.helperProportions.height / 2) // Bottom Half 
    100104                                && y2 - (this.helperProportions.height / 2) < b ); // Top Half 
    101                 } 
    102                  
     105                 
     106                } 
    103107        }, 
    104108        intersectsWithEdge: function(item) {     
    105109                var x1 = this.positionAbs.left, x2 = x1 + this.helperProportions.width, 
    106110                        y1 = this.positionAbs.top, y2 = y1 + this.helperProportions.height; 
     111                 
    107112                var l = item.left, r = l + item.width,  
    108113                        t = item.top, b = t + item.height; 
    109  
     114                 
     115                var dyClick = this.offset.click.top, dxClick = this.offset.click.left; 
     116                var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r; 
     117                 
    110118                if(this.options.tolerance == "pointer" || (this.options.tolerance == "guess" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])) { 
    111                          
    112                         if(!(y1 + this.offset.click.top > t && y1 + this.offset.click.top < b && x1 + this.offset.click.left > l && x1 + this.offset.click.left < r)) return false; 
    113                          
     119                        if(!isOverElement) return false; 
     120 
    114121                        if(this.floating) { 
    115                                 if(x1 + this.offset.click.left > l && x1 + this.offset.click.left < l + item.width/2) return 2; 
    116                                 if(x1 + this.offset.click.left > l+item.width/2 && x1 + this.offset.click.left < r) return 1; 
     122                                if ((x1 + dxClick) > l && (x1 + dxClick) < l + item.width/2) return 2; 
     123                                if ((x1 + dxClick) > l + item.width/2 && (x1 + dxClick) < r) return 1; 
    117124                        } else { 
    118                                 if(y1 + this.offset.click.top > t && y1 + this.offset.click.top < t) return 2; 
    119                                 if(y1 + this.offset.click.top > t && y1 + this.offset.click.top < b) return 1; 
     125                                var height = item.height, helperHeight = this.helperProportions.height; 
     126                                var direction = y1 - this.originalPosition.top < 0 ? 2 : 1; // 2 = up 
     127                                 
     128                                if (direction == 1 && (y1 + dyClick) < t + height/2) { return 2; } // up 
     129                                else if (direction == 2 && (y1 + dyClick) > t + height/2) { return 1; } // down 
    120130                        } 
    121                          
     131 
    122132                } else { 
    123                  
    124133                        if (!(l < x1 + (this.helperProportions.width / 2) // Right Half 
    125134                                && x2 - (this.helperProportions.width / 2) < r // Left Half 
     
    134143                                if(y1 < b && y2 > b) return 2; //Crosses bottom edge 
    135144                        } 
    136                  
    137145                } 
    138146