Side navigation
Ticket #2171: containment-window-fixed.patch
File containment-window-fixed.patch, 2.5 KB (added by scottgonzalez, February 01, 2008 09:06PM UTC)
with fixed position support
Index: ui.draggable.ext.js
===================================================================
--- ui.draggable.ext.js (revision 4585)
+++ ui.draggable.ext.js (working copy)
@@ -90,6 +90,15 @@
$(document).width(),
($(document).height() || document.body.parentNode.scrollHeight)
];
+ } else if(o._containment == 'window' || o._containment == window) {
+ var leftAdjust = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
+ var topAdjust = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
+ o.containment = [
+ leftAdjust,
+ topAdjust,
+ $(window).width() + leftAdjust,
+ $(window).height() + topAdjust
+ ];
} else { //I'm a node, so compute top/left/right/bottom
var ce = $(o._containment)[0];
@@ -112,10 +121,10 @@
var self = ui.instance;
if(c.constructor == Array) {
- if((ui.absolutePosition.left < c[0])) self.position.left = c[0] - (self.offset.left - self.clickOffset.left);
- if((ui.absolutePosition.top < c[1])) self.position.top = c[1] - (self.offset.top - self.clickOffset.top);
- if(ui.absolutePosition.left - c[2] + self.helperProportions.width >= 0) self.position.left = c[2] - (self.offset.left - self.clickOffset.left) - self.helperProportions.width;
- if(ui.absolutePosition.top - c[3] + self.helperProportions.height >= 0) self.position.top = c[3] - (self.offset.top - self.clickOffset.top) - self.helperProportions.height;
+ if((ui.absolutePosition.left < c[0])) self.position.left = c[0] - (self.offset.left - self.clickOffset.left) - ( self.helperFixed ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : 0 );
+ if((ui.absolutePosition.top < c[1])) self.position.top = c[1] - (self.offset.top - self.clickOffset.top) - ( self.helperFixed ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : 0 );
+ if(ui.absolutePosition.left - c[2] + self.helperProportions.width >= 0) self.position.left = c[2] - (self.offset.left - self.clickOffset.left) - self.helperProportions.width - ( self.helperFixed ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : 0 );
+ if(ui.absolutePosition.top - c[3] + self.helperProportions.height >= 0) self.position.top = c[3] - (self.offset.top - self.clickOffset.top) - self.helperProportions.height - ( self.helperFixed ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : 0 );
} else {
if((ui.position.left < c.left)) self.position.left = c.left;
if((ui.position.top < c.top)) self.position.top = c.top;
Download in other formats:
Original Format
File containment-window-fixed.patch, 2.5 KB (added by scottgonzalez, February 01, 2008 09:06PM UTC)
with fixed position support
Index: ui.draggable.ext.js
===================================================================
--- ui.draggable.ext.js (revision 4585)
+++ ui.draggable.ext.js (working copy)
@@ -90,6 +90,15 @@
$(document).width(),
($(document).height() || document.body.parentNode.scrollHeight)
];
+ } else if(o._containment == 'window' || o._containment == window) {
+ var leftAdjust = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
+ var topAdjust = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
+ o.containment = [
+ leftAdjust,
+ topAdjust,
+ $(window).width() + leftAdjust,
+ $(window).height() + topAdjust
+ ];
} else { //I'm a node, so compute top/left/right/bottom
var ce = $(o._containment)[0];
@@ -112,10 +121,10 @@
var self = ui.instance;
if(c.constructor == Array) {
- if((ui.absolutePosition.left < c[0])) self.position.left = c[0] - (self.offset.left - self.clickOffset.left);
- if((ui.absolutePosition.top < c[1])) self.position.top = c[1] - (self.offset.top - self.clickOffset.top);
- if(ui.absolutePosition.left - c[2] + self.helperProportions.width >= 0) self.position.left = c[2] - (self.offset.left - self.clickOffset.left) - self.helperProportions.width;
- if(ui.absolutePosition.top - c[3] + self.helperProportions.height >= 0) self.position.top = c[3] - (self.offset.top - self.clickOffset.top) - self.helperProportions.height;
+ if((ui.absolutePosition.left < c[0])) self.position.left = c[0] - (self.offset.left - self.clickOffset.left) - ( self.helperFixed ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : 0 );
+ if((ui.absolutePosition.top < c[1])) self.position.top = c[1] - (self.offset.top - self.clickOffset.top) - ( self.helperFixed ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : 0 );
+ if(ui.absolutePosition.left - c[2] + self.helperProportions.width >= 0) self.position.left = c[2] - (self.offset.left - self.clickOffset.left) - self.helperProportions.width - ( self.helperFixed ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : 0 );
+ if(ui.absolutePosition.top - c[3] + self.helperProportions.height >= 0) self.position.top = c[3] - (self.offset.top - self.clickOffset.top) - self.helperProportions.height - ( self.helperFixed ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : 0 );
} else {
if((ui.position.left < c.left)) self.position.left = c.left;
if((ui.position.top < c.top)) self.position.top = c.top;