Skip to main content

Search and Top Navigation

Ticket #4631: draggable-4631.diff
File draggable-4631.diff, 4.5 KB (added by alexch, September 26, 2009 12:05AM UTC)

revised patch for draggable.js

--- /Users/chaffee/downloads/jquery-ui-1/development-bundle/ui/ui.draggable.js	2009-06-04 05:15:36.000000000 -0700
+++ ui.draggable.js	2009-09-25 17:03:19.000000000 -0700
@@ -292,20 +292,20 @@
 
 		if(!pos) pos = this.position;
 		var mod = d == "absolute" ? 1 : -1;
-		var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
+		var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent;
 
 		return {
 			top: (
 				pos.top																	// The absolute mouse position
 				+ this.offset.relative.top * mod										// Only for relative positioned nodes: Relative offset from element to offset parent
 				+ this.offset.parent.top * mod											// The offsetParent's offset without borders (offset + border)
-				- ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
+				- (this._extraY(scroll) * mod)
 			),
 			left: (
 				pos.left																// The absolute mouse position
 				+ this.offset.relative.left * mod										// Only for relative positioned nodes: Relative offset from element to offset parent
 				+ this.offset.parent.left * mod											// The offsetParent's offset without borders (offset + border)
-				- ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
+				- (this._extraX(scroll) * mod)
 			)
 		};
 
@@ -313,7 +313,7 @@
 
 	_generatePosition: function(event) {
 
-		var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
+		var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent;
 
 		// This is another very weird special case that only happens for relative elements:
 		// 1. If the css position is relative
@@ -356,19 +356,47 @@
 				- this.offset.click.top													// Click offset (relative to the element)
 				- this.offset.relative.top												// Only for relative positioned nodes: Relative offset from element to offset parent
 				- this.offset.parent.top												// The offsetParent's offset without borders (offset + border)
-				+ ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
+				+ this._extraY(scroll)
 			),
 			left: (
 				pageX																// The absolute mouse position
 				- this.offset.click.left												// Click offset (relative to the element)
 				- this.offset.relative.left												// Only for relative positioned nodes: Relative offset from element to offset parent
 				- this.offset.parent.left												// The offsetParent's offset without borders (offset + border)
-				+ ($.browser.safari && this.cssPosition == 'fixed' ? 0 : ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
+				+ this._extraX(scroll)
 			)
 		};
 
 	},
 
+	_extraY: function(scroll) {
+	  scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
+	  if (this._needsSafariFixedWorkaround())
+	    return 0;
+	  else if (this.cssPosition == 'fixed')
+	    return -this.scrollParent.scrollTop();
+	  else if (scrollIsRootNode)
+	    return 0;
+	  else
+	    return scroll.scrollTop();
+	},
+	
+	_extraX: function(scroll) {
+	  scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
+    if (this._needsSafariFixedWorkaround())
+      return 0;
+    else if (this.cssPosition == 'fixed')
+      return -this.scrollParent.scrollLeft();
+    else if (scrollIsRootNode)
+      return 0;
+    else 
+      return scroll.scrollLeft();
+	},
+	
+	_needsSafariFixedWorkaround: function() {
+	  return $.browser.safari && $.browser.version < 526 && this.cssPosition == 'fixed';
+	},
+	
 	_clear: function() {
 		this.helper.removeClass("ui-draggable-dragging");
 		if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove();

Download in other formats:

Original Format