Author: dbiatenia
Date: 2007-07-25 10:05:40 -0400 (Wed, 25 Jul 2007)
New Revision: 1843
Modified:
trunk/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js
Log:
smart-positioning bugfix
Modified:
trunk/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js
===================================================================
---
trunk/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js 2007-07-25
13:17:15 UTC (rev 1842)
+++
trunk/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js 2007-07-25
14:05:40 UTC (rev 1843)
@@ -181,124 +181,63 @@
toolTipX = x - offsets[0];
toolTipY = y - offsets[1];
- Element.setStyle(this.toolTip, {"left": toolTipX + "px",
"top": toolTipY + "px"});
- //alert(this.toolTipW + 'x' + this.toolTipY);
-/*
- var p = Element.getStyle(this.toolTip.parentNode, 'position');
-
- if (p == 'relative'){
- toolTipX = cursorX - offsets[0];
- toolTipY = cursorY - offsets[1];
- //Element.setStyle(this.toolTip, {"left": - offsets[0] + cursorX +
"px", "top": - offsets[1] + cursorY + "px"});
- } else {
- if(IE){
-
- var cumOffset = this.cumCumOffset(this.toolTip.parentNode);
- //Element.setStyle(this.toolTip, {"left": - cumOffset[0] + cursorX +
"px", "top": - cumOffset[1] + cursorY + "px"});
- toolTipX = cursorX - cumOffset[0];
- toolTipY = cursorY - cumOffset[1];
-
-
- //Element.setStyle(this.toolTip, {"left": Event.pointerX(e) +
"px", "top": Event.pointerY(e) + "px"});
- //Element.setStyle(this.toolTip, {"left": - offsets[0] + Event.pointerX(e)
+ "px", "top": - offsets[1] + Event.pointerY(e) + "px"});
- } else {
- toolTipX = cursorX;
- toolTipY = cursorY;
-
-// this.toolTip.style.top = cursorY;
-// this.toolTip.style.left = cursorX;
- }
- }
-*/
- //Element.setStyle(this.toolTip, {"left": toolTipX + "px",
"top": toolTipY + "px"});
-
-//
- //Element.setStyle(this.toolTip, {"left": offsets[0] + "px",
"top": offsets[1] + "px"});
-
-/*
- this.toolTip.style.top = cursorY;
- this.toolTip.style.left = cursorX;
-
- cursorX -= offsets[0];
- cursorY -= offsets[1];
-
- this.toolTip.style.top = cursorY;
- this.toolTip.style.left = cursorX;
-
-
- cursorX += this.parent.offsetLeft;
- cursorY += this.parent.offsetTop;
-
- this.toolTip.style.top = cursorY;
- this.toolTip.style.left = cursorX;
-*/
-
-
+ var windowDim = this.windowSize();
if(this.direction == "top-left"){
- toolTipY = toolTipY - this.verticalOffset - this.toolTipH;
- toolTipX = toolTipX - this.horizontalOffset - this.toolTipW;
- /*
- if(cursorY - this.verticalOffset - this.toolTipH < 0){
- this.toolTip.style.top = cursorY + this.verticalOffset - this.toolTipH;
+
+ if(e.clientY - this.verticalOffset - this.toolTipH < 0){
+ toolTipY = toolTipY + this.verticalOffset;
} else {
- this.toolTip.style.top = cursorY - this.verticalOffset - this.toolTipH;
+ toolTipY = toolTipY - this.verticalOffset - this.toolTipH;
}
- if(cursorX - this.horizontalOffset - this.toolTipW < 0){
- this.toolTip.style.left = cursorX + this.horizontalOffset;
+
+ if(e.clientX - this.horizontalOffset - this.toolTipW < 0){
+ toolTipX = toolTipX + this.horizontalOffset;
} else {
- this.toolTip.style.left = cursorX - this.horizontalOffset - this.toolTipW;
+ toolTipX = toolTipX - this.horizontalOffset - this.toolTipW;
}
- */
+
} else if(this.direction == "bottom-left"){
- toolTipY = toolTipY + this.verticalOffset;
- toolTipX = toolTipX - this.horizontalOffset - this.toolTipW;
- /*
- if(cursorY + this.verticalOffset + this.toolTipH > windowDim[1]){
- this.toolTip.style.top = cursorY - this.verticalOffset - this.toolTipH;
+
+ if(e.clientY + this.verticalOffset + this.toolTipH > windowDim[1]){
+ toolTipY = toolTipY - this.verticalOffset - this.toolTipH;
} else {
- this.toolTip.style.top = cursorY + this.verticalOffset;
+ toolTipY = toolTipY + this.verticalOffset;
}
- if(cursorX - this.horizontalOffset - this.toolTipW < 0){
- this.toolTip.style.left = cursorX + this.horizontalOffset ;
+
+ if(e.clientX - this.horizontalOffset - this.toolTipW < 0){
+ toolTipX = toolTipX + this.horizontalOffset;
} else {
- this.toolTip.style.left = cursorX - this.horizontalOffset - this.toolTipW;
+ toolTipX = toolTipX - this.horizontalOffset - this.toolTipW;
}
- */
+
} else if(this.direction == "top-right"){
- toolTipY = toolTipY - this.verticalOffset - this.toolTipH;
- toolTipX = toolTipX + this.horizontalOffset;
- /*
- if(cursorY - this.verticalOffset - this.toolTipH < 0){
- this.toolTip.style.top = cursorY + this.verticalOffset;
+
+ if(e.clientY - this.verticalOffset - this.toolTipH < 0){
+ toolTipY = toolTipY + this.verticalOffset;
} else {
- this.toolTip.style.top = cursorY - this.verticalOffset - this.toolTipH;
+ toolTipY = toolTipY - this.verticalOffset - this.toolTipH;
}
- if(cursorX + this.horizontalOffset + this.toolTipW > windowDim[0]){
- this.toolTip.style.left = cursorX - this.horizontalOffset - this.toolTipW;
+ if(e.clientX + this.horizontalOffset + this.toolTipW > windowDim[0]){
+ toolTipX = toolTipX - this.horizontalOffset - this.toolTipW;
} else {
- this.toolTip.style.left = cursorX + this.horizontalOffset;
+ toolTipX = toolTipX + this.horizontalOffset;
}
- */
+
} else {
- // bottom-right is default
- toolTipY = toolTipY + this.verticalOffset;
- toolTipX = toolTipX + this.horizontalOffset;
- /*
- if(cursorY + this.verticalOffset - this.toolTip.clientHeight > windowDim[1]){
- this.toolTip.style.top = cursorY - this.verticalOffset - this.toolTipH;
+
+ if(e.clientY + this.verticalOffset + this.toolTipH > windowDim[1]){
+ toolTipY = toolTipY - this.verticalOffset - this.toolTipH;
} else {
- this.toolTip.style.top = cursorY + this.verticalOffset;
+ toolTipY = toolTipY + this.verticalOffset;
}
- if(cursorX + this.horizontalOffset + this.toolTip.clientWidth > windowDim[0]){
- this.toolTip.style.left = cursorX - this.horizontalOffset - this.toolTipW;
+
+ if(e.clientX + this.horizontalOffset + this.toolTipW > windowDim[0]){
+ toolTipX = toolTipX - this.horizontalOffset - this.toolTipW;
} else {
- this.toolTip.style.left = cursorX + this.horizontalOffset;
+ toolTipX = toolTipX + this.horizontalOffset;
}
- */
}
Element.setStyle(this.toolTip, {"left": toolTipX + "px",
"top": toolTipY + "px"});
-
-
},
windowSize: function() {
@@ -331,17 +270,5 @@
eval(this.oncomplete);
}
}
- },
- cumCumOffset: function(element) {
- var valueT = 0, valueL = 0;
- do {
- var p = Element.getStyle(element, 'position');
- if (p == 'relative'){
- valueT += element.offsetTop || 0;
- valueL += element.offsetLeft || 0;
- }
- element = element.offsetParent;
- } while (element);
- return [valueL, valueT];
- }
+ }
}
\ No newline at end of file
Show replies by date