Show
Ignore:
Timestamp:
07/28/08 17:10:51 (20 months ago)
Author:
paul.bakaus
Message:

draggable: fixed overflow calculation in the positioning methods

Files:
1 modified

Legend:

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

    r489 r491  
    6868                        top: e.pageY - this.offset.top 
    6969                }; 
     70 
     71                this.scrollTopParent = function(el) { 
     72                        do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode); 
     73                        return $(document); 
     74                }(this.element); 
     75                this.scrollLeftParent = function(el) { 
     76                        do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return el; el = el.parent(); } while (el[0].parentNode); 
     77                        return $(document); 
     78                }(this.element); 
    7079                 
    7180                this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset();                    //Get the offsetParent and cache its position 
     
    7887                var p = this.element.position();                                                                                                                                //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helpers 
    7988                this.offset.relative = this.cssPosition == "relative" ? { 
    80                         top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.offsetParent[0].scrollTop, 
    81                         left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.offsetParent[0].scrollLeft 
     89                        top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollTopParent[0].scrollTop, 
     90                        left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollLeftParent[0].scrollLeft 
    8291                } : { top: 0, left: 0 }; 
    8392                 
     
    138147                                + this.offset.relative.top      * mod                                                                           // Only for relative positioned nodes: Relative offset from element to offset parent 
    139148                                + this.offset.parent.top * mod                                                                                  // The offsetParent's offset without borders (offset + border) 
    140                                 - (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.offsetParent[0].scrollTop) * mod // The offsetParent's scroll position, not if the element is fixed 
     149                                - (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.scrollTopParent[0].scrollTop) * mod      // The offsetParent's scroll position, not if the element is fixed 
    141150                                + (this.cssPosition == "fixed" ? $(document).scrollTop() : 0) * mod 
    142151                                + this.margins.top * mod                                                                                                //Add the margin (you don't want the margin counting in intersection methods) 
     
    146155                                + this.offset.relative.left     * mod                                                                           // Only for relative positioned nodes: Relative offset from element to offset parent 
    147156                                + this.offset.parent.left * mod                                                                                 // The offsetParent's offset without borders (offset + border) 
    148                                 - (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.offsetParent[0].scrollLeft) * mod        // The offsetParent's scroll position, not if the element is fixed 
     157                                - (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.scrollLeftParent[0].scrollLeft) * mod    // The offsetParent's scroll position, not if the element is fixed 
    149158                                + (this.cssPosition == "fixed" ? $(document).scrollLeft() : 0) * mod 
    150159                                + this.margins.left * mod                                                                                               //Add the margin (you don't want the margin counting in intersection methods) 
     
    161170                                - this.offset.relative.top                                                                                              // Only for relative positioned nodes: Relative offset from element to offset parent 
    162171                                - this.offset.parent.top                                                                                                // The offsetParent's offset without borders (offset + border) 
    163                                 + (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.offsetParent[0].scrollTop)       // The offsetParent's scroll position, not if the element is fixed 
     172                                + (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.scrollTopParent[0].scrollTop)    // The offsetParent's scroll position, not if the element is fixed 
    164173                                - (this.cssPosition == "fixed" ? $(document).scrollTop() : 0) 
    165174                        ), 
     
    169178                                - this.offset.relative.left                                                                                             // Only for relative positioned nodes: Relative offset from element to offset parent 
    170179                                - this.offset.parent.left                                                                                               // The offsetParent's offset without borders (offset + border) 
    171                                 + (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.offsetParent[0].scrollLeft)      // The offsetParent's scroll position, not if the element is fixed 
     180                                + (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.scrollLeftParent[0].scrollLeft)  // The offsetParent's scroll position, not if the element is fixed 
    172181                                - (this.cssPosition == "fixed" ? $(document).scrollLeft() : 0) 
    173182                        ) 
     
    332341                o.scrollSpeed           = o.scrollSpeed || 20; 
    333342                 
    334                 i.overflowY = function(el) { 
    335                         do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode); 
    336                         return $(document); 
    337                 }(this); 
    338                 i.overflowX = function(el) { 
    339                         do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return el; el = el.parent(); } while (el[0].parentNode); 
    340                         return $(document); 
    341                 }(this); 
    342                  
    343                 if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') i.overflowYOffset = i.overflowY.offset(); 
    344                 if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') i.overflowXOffset = i.overflowX.offset(); 
     343                if(i.scrollTopParent[0] != document && i.scrollTopParent[0].tagName != 'HTML') i.overflowYOffset = i.scrollTopParent.offset(); 
     344                if(i.scrollLeftParent[0] != document && i.scrollLeftParent[0].tagName != 'HTML') i.overflowXOffset = i.scrollLeftParent.offset(); 
    345345                 
    346346        }, 
     
    349349                var o = ui.options; 
    350350                var i = $(this).data("draggable"); 
    351                  
    352                 if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') { 
    353                         if((i.overflowYOffset.top + i.overflowY[0].offsetHeight) - e.pageY < o.scrollSensitivity) 
    354                                 i.overflowY[0].scrollTop = i.overflowY[0].scrollTop + o.scrollSpeed; 
     351         
     352                if(i.scrollTopParent[0] != document && i.scrollTopParent[0].tagName != 'HTML') { 
     353                        if((i.overflowYOffset.top + i.scrollTopParent[0].offsetHeight) - e.pageY < o.scrollSensitivity) 
     354                                i.scrollTopParent[0].scrollTop = i.scrollTopParent[0].scrollTop + o.scrollSpeed; 
    355355                        if(e.pageY - i.overflowYOffset.top < o.scrollSensitivity) 
    356                                 i.overflowY[0].scrollTop = i.overflowY[0].scrollTop - o.scrollSpeed; 
     356                                i.scrollTopParent[0].scrollTop = i.scrollTopParent[0].scrollTop - o.scrollSpeed; 
    357357                                                         
    358358                } else { 
     
    363363                } 
    364364                 
    365                 if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') { 
    366                         if((i.overflowXOffset.left + i.overflowX[0].offsetWidth) - e.pageX < o.scrollSensitivity) 
    367                                 i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft + o.scrollSpeed; 
     365                if(i.scrollLeftParent[0] != document && i.scrollLeftParent[0].tagName != 'HTML') { 
     366                        if((i.overflowXOffset.left + i.scrollLeftParent[0].offsetWidth) - e.pageX < o.scrollSensitivity) 
     367                                i.scrollLeftParent[0].scrollLeft = i.scrollLeftParent[0].scrollLeft + o.scrollSpeed; 
    368368                        if(e.pageX - i.overflowXOffset.left < o.scrollSensitivity) 
    369                                 i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft - o.scrollSpeed; 
     369                                i.scrollLeftParent[0].scrollLeft = i.scrollLeftParent[0].scrollLeft - o.scrollSpeed; 
    370370                } else { 
    371371                        if(e.pageX - $(document).scrollLeft() < o.scrollSensitivity)