[Dojo-checkins] bill - r26938 - dijit/trunk

dojo-checkins-admin at dojotoolkit.org dojo-checkins-admin at dojotoolkit.org
Tue Nov 1 07:45:17 EDT 2011


Author: bill
Date: Tue Nov  1 04:45:17 2011
New Revision: 26938

Modified:
   dijit/trunk/Tooltip.js
   dijit/trunk/place.js
Log:
Fix calculations in Tooltip.orient() for when Tooltip is above/below rather than to the left or the right.   It's suspicious though why we need to measure the size of the connector at all, rather than just measuring the size of the whole tooltip.

Fixes #14122 !strict.

Modified: dijit/trunk/Tooltip.js
==============================================================================
--- dijit/trunk/Tooltip.js	(original)
+++ dijit/trunk/Tooltip.js	Tue Nov  1 04:45:17 2011
@@ -117,10 +117,20 @@
 			//		width to whatever width is available
 			// tags:
 			//		protected
+
 			this.connectorNode.style.top = ""; //reset to default
 
-			//Adjust the spaceAvailable width, without changing the spaceAvailable object
-			var tooltipSpaceAvaliableWidth = spaceAvailable.w - this.connectorNode.offsetWidth;
+			// Adjust for space taking by tooltip connector.
+			// Take care not to modify the original spaceAvailable arg as that confuses the caller (dijit.place).
+			var heightAvailable = spaceAvailable.h,
+				widthAvailable = spaceAvailable.w;
+			if(aroundCorner.charAt(1) != tooltipCorner.charAt(1)){
+				// left/right tooltip
+				widthAvailable -= this.connectorNode.offsetWidth;
+			}else{
+				// above/below tooltip
+				heightAvailable -= this.connectorNode.offsetHeight;
+			}
 
 			node.className = "dijitTooltip " +
 				{
@@ -140,7 +150,7 @@
 			this.domNode.style.width = "auto";
 			var size = domGeometry.getContentBox(this.domNode);
 
-			var width = Math.min((Math.max(tooltipSpaceAvaliableWidth,1)), size.w);
+			var width = Math.min((Math.max(widthAvailable,1)), size.w);
 			var widthWasReduced = width < size.w;
 
 			this.domNode.style.width = width+"px";
@@ -160,9 +170,9 @@
 			if(tooltipCorner.charAt(0) == 'B' && aroundCorner.charAt(0) == 'B'){
 				var mb = domGeometry.getMarginBox(node);
 				var tooltipConnectorHeight = this.connectorNode.offsetHeight;
-				if(mb.h > spaceAvailable.h){
+				if(mb.h > heightAvailable){
 					// The tooltip starts at the top of the page and will extend past the aroundNode
-					var aroundNodePlacement = spaceAvailable.h - ((aroundNodeCoords.h + tooltipConnectorHeight) >> 1);
+					var aroundNodePlacement = heightAvailable - ((aroundNodeCoords.h + tooltipConnectorHeight) >> 1);
 					this.connectorNode.style.top = aroundNodePlacement + "px";
 					this.connectorNode.style.bottom = "";
 				}else{
@@ -180,7 +190,7 @@
 				this.connectorNode.style.bottom = "";
 			}
 
-			return Math.max(0, size.w - tooltipSpaceAvaliableWidth);
+			return Math.max(0, size.w - widthAvailable);
 		},
 
 		_onShow: function(){

Modified: dijit/trunk/place.js
==============================================================================
--- dijit/trunk/place.js	(original)
+++ dijit/trunk/place.js	Tue Nov  1 04:45:17 2011
@@ -62,6 +62,11 @@
 				   }[corner.charAt(0)]
 			};
 
+			// Clear left/right position settings set earlier so they don't interfere with calculations,
+			// specifically when layoutNode() (a.k.a. Tooltip.orient()) measures natural width of Tooltip
+			var s = node.style;
+			s.left = s.right = "auto";
+
 			// configure node to be displayed in given position relative to button
 			// (need to do this in order to get an accurate size for the node, because
 			// a tooltip's size changes based on position, due to triangle)


More information about the Dojo-checkins mailing list