Author: nbelaevski
Date: 2008-09-07 16:53:33 -0400 (Sun, 07 Sep 2008)
New Revision: 10337
Modified:
trunk/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js
Log:
Slight tooltip optimization
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 2008-09-07
20:51:42 UTC (rev 10336)
+++
trunk/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js 2008-09-07
20:53:33 UTC (rev 10337)
@@ -404,6 +404,23 @@
this.doDisable(e);
},
+ PX_REGEX: /px$/,
+
+ parseToPx: function(value) {
+ if (value) {
+ var v = value.strip();
+ if (this.PX_REGEX.test(v)) {
+ try {
+ return parseInt(v.replace(this.PX_REGEX, ""), 10);
+ } catch (e) {
+
+ }
+ }
+ }
+
+ return NaN;
+ },
+
/*
* we can pass here not event only, but also object {'clientX':XXX,
'clientY':XXX}
*/
@@ -415,15 +432,27 @@
var elementDim = Richfaces.Position.getOffsetDimensions(this.toolTip);
+ var tooltipStyle = this.toolTip.style;
+
// RF-1485, fix for FF
- var _display = this.toolTip.style.display;
- var _visibility = this.toolTip.style.visibility;
- this.toolTip.style.visibility = "hidden";
- this.toolTip.style.display = "block";
+ var _display = tooltipStyle.display;
+ var _visibility = tooltipStyle.visibility;
- this.toolTip.style.top = "0px";
- this.toolTip.style.left = "0px";
+ tooltipStyle.visibility = "hidden";
+ tooltipStyle.display = "block";
+ var oldLeft = this.parseToPx(tooltipStyle.left);
+ if (isNaN(oldLeft)) {
+ oldLeft = 0;
+ tooltipStyle.left = '0px';
+ }
+
+ var oldTop = this.parseToPx(tooltipStyle.top);
+ if (isNaN(oldTop)) {
+ oldTop = 0;
+ tooltipStyle.top = '0px';
+ }
+
var event = jQuery.event.fix(e);
var offsetWidth = this.toolTip.offsetWidth;
@@ -440,10 +469,8 @@
var offsets = jQuery(this.toolTip).offset();
- var event = jQuery.event.fix(e);
-
- var x = coords.x - offsets.left + (event.pageX - event.clientX);
- var y = coords.y - offsets.top + (event.pageY - event.clientY);
+ var x = coords.x - offsets.left + (event.pageX - event.clientX) + oldLeft;
+ var y = coords.y - offsets.top + (event.pageY - event.clientY) + oldTop;
Element.setStyle(this.toolTip, {"left": x + "px",
"top": y + "px"});
if(this.iframe)
@@ -455,8 +482,8 @@
this.iframe.style.height = offsetHeight + 'px';
}
- this.toolTip.style.visibility = _visibility;
- this.toolTip.style.display = _display;
+ tooltipStyle.visibility = _visibility;
+ tooltipStyle.display = _display;
this.eventCopy = A4J.AJAX.CloneObject(e, false);
},