draggable: fixed IE scrolling but with overflowing containers and appendTo being used

This commit is contained in:
Paul Bakaus 2008-07-29 01:32:46 +00:00
parent 1bf23b38fd
commit 36d96a9e82

View File

@ -71,11 +71,11 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {
this.scrollTopParent = function(el) { this.scrollTopParent = function(el) {
do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode); do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode);
return $(document); return $(document);
}(this.element); }(this.helper);
this.scrollLeftParent = function(el) { this.scrollLeftParent = function(el) {
do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return el; el = el.parent(); } while (el[0].parentNode); do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return el; el = el.parent(); } while (el[0].parentNode);
return $(document); return $(document);
}(this.element); }(this.helper);
this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset(); //Get the offsetParent and cache its position this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset(); //Get the offsetParent and cache its position
if(this.offsetParent[0] == document.body && $.browser.mozilla) po = { top: 0, left: 0 }; //Ugly FF3 fix if(this.offsetParent[0] == document.body && $.browser.mozilla) po = { top: 0, left: 0 }; //Ugly FF3 fix
@ -333,6 +333,8 @@ $.ui.plugin.add("draggable", "iframeFix", {
} }
}); });
$.ui.plugin.add("draggable", "scroll", { $.ui.plugin.add("draggable", "scroll", {
start: function(e, ui) { start: function(e, ui) {
var o = ui.options; var o = ui.options;
@ -340,21 +342,29 @@ $.ui.plugin.add("draggable", "scroll", {
o.scrollSensitivity = o.scrollSensitivity || 20; o.scrollSensitivity = o.scrollSensitivity || 20;
o.scrollSpeed = o.scrollSpeed || 20; o.scrollSpeed = o.scrollSpeed || 20;
if(i.scrollTopParent[0] != document && i.scrollTopParent[0].tagName != 'HTML') i.overflowYOffset = i.scrollTopParent.offset(); i.overflowY = function(el) {
if(i.scrollLeftParent[0] != document && i.scrollLeftParent[0].tagName != 'HTML') i.overflowXOffset = i.scrollLeftParent.offset(); do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode);
return $(document);
}(this);
i.overflowX = function(el) {
do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return el; el = el.parent(); } while (el[0].parentNode);
return $(document);
}(this);
if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') i.overflowYOffset = i.overflowY.offset();
if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') i.overflowXOffset = i.overflowX.offset();
}, },
drag: function(e, ui) { drag: function(e, ui) {
var o = ui.options; var o = ui.options, scrolled = false;
var i = $(this).data("draggable"); var i = $(this).data("draggable");
var scrolled = false;
if(i.scrollTopParent[0] != document && i.scrollTopParent[0].tagName != 'HTML') { if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') {
if((i.overflowYOffset.top + i.scrollTopParent[0].offsetHeight) - e.pageY < o.scrollSensitivity) if((i.overflowYOffset.top + i.overflowY[0].offsetHeight) - e.pageY < o.scrollSensitivity)
i.scrollTopParent[0].scrollTop = scrolled = i.scrollTopParent[0].scrollTop + o.scrollSpeed; i.overflowY[0].scrollTop = scrolled = i.overflowY[0].scrollTop + o.scrollSpeed;
if(e.pageY - i.overflowYOffset.top < o.scrollSensitivity) if(e.pageY - i.overflowYOffset.top < o.scrollSensitivity)
i.scrollTopParent[0].scrollTop = scrolled = i.scrollTopParent[0].scrollTop - o.scrollSpeed; i.overflowY[0].scrollTop = scrolled = i.overflowY[0].scrollTop - o.scrollSpeed;
} else { } else {
if(e.pageY - $(document).scrollTop() < o.scrollSensitivity) if(e.pageY - $(document).scrollTop() < o.scrollSensitivity)
@ -363,11 +373,11 @@ $.ui.plugin.add("draggable", "scroll", {
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
} }
if(i.scrollLeftParent[0] != document && i.scrollLeftParent[0].tagName != 'HTML') { if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') {
if((i.overflowXOffset.left + i.scrollLeftParent[0].offsetWidth) - e.pageX < o.scrollSensitivity) if((i.overflowXOffset.left + i.overflowX[0].offsetWidth) - e.pageX < o.scrollSensitivity)
scrolled = i.scrollLeftParent[0].scrollLeft = i.scrollLeftParent[0].scrollLeft + o.scrollSpeed; i.overflowX[0].scrollLeft = scrolled = i.overflowX[0].scrollLeft + o.scrollSpeed;
if(e.pageX - i.overflowXOffset.left < o.scrollSensitivity) if(e.pageX - i.overflowXOffset.left < o.scrollSensitivity)
scrolled = i.scrollLeftParent[0].scrollLeft = i.scrollLeftParent[0].scrollLeft - o.scrollSpeed; i.overflowX[0].scrollLeft = scrolled = i.overflowX[0].scrollLeft - o.scrollSpeed;
} else { } else {
if(e.pageX - $(document).scrollLeft() < o.scrollSensitivity) if(e.pageX - $(document).scrollLeft() < o.scrollSensitivity)
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
@ -381,6 +391,7 @@ $.ui.plugin.add("draggable", "scroll", {
} }
}); });
$.ui.plugin.add("draggable", "snap", { $.ui.plugin.add("draggable", "snap", {
start: function(e, ui) { start: function(e, ui) {