Author: nbelaevski
Date: 2008-08-13 20:11:26 -0400 (Wed, 13 Aug 2008)
New Revision: 10080
Modified:
trunk/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java
trunk/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js
trunk/ui/tooltip/src/test/java/org/richfaces/component/TooltipComponentTest.java
Log:
https://jira.jboss.org/jira/browse/RF-4087
Modified:
trunk/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java
===================================================================
---
trunk/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java 2008-08-14
00:11:20 UTC (rev 10079)
+++
trunk/ui/tooltip/src/main/java/org/richfaces/renderkit/html/ToolTipRenderer.java 2008-08-14
00:11:26 UTC (rev 10080)
@@ -74,13 +74,11 @@
return stylesAll;
}
private final InternetResource[] scripts = {
- new org.ajax4jsf.javascript.PrototypeScript()
- ,
- new org.ajax4jsf.javascript.AjaxScript()
- ,
- getResource("/org/richfaces/renderkit/html/scripts/utils.js")
- ,
- getResource("/org/richfaces/renderkit/html/scripts/tooltip.js")
+ new org.ajax4jsf.javascript.PrototypeScript(),
+ new org.ajax4jsf.javascript.AjaxScript(),
+ getResource("/org/richfaces/renderkit/html/scripts/jquery/jquery.js"),
+ getResource("/org/richfaces/renderkit/html/scripts/utils.js"),
+ getResource("/org/richfaces/renderkit/html/scripts/tooltip.js")
};
private InternetResource[] scriptsAll = null;
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-08-14
00:11:20 UTC (rev 10079)
+++
trunk/ui/tooltip/src/main/resources/org/richfaces/renderkit/html/scripts/tooltip.js 2008-08-14
00:11:26 UTC (rev 10080)
@@ -4,25 +4,6 @@
Richfaces.ToolTip = {};
-Richfaces.ToolTip.cumulativeOffset = function(element)
-{
- var valueT = 0, valueL = 0;
- do {
- if (window.opera && Richfaces.getComputedStyle(element, 'position')
== 'fixed')
- {
- valueT += Richfaces.getComputedStyleSize(element,"top");
- valueL += Richfaces.getComputedStyleSize(element,"left");
- }
- else
- {
- valueT += element.offsetTop || 0;
- valueL += element.offsetLeft || 0;
- }
- element = element.offsetParent;
- } while (element);
- return Element._returnOffset(valueL, valueT);
-};
-
ToolTip = Class.create();
ToolTip.prototype = {
@@ -233,8 +214,6 @@
}
if (this.activationTimerHandle) return;
- this.setScrollDelta();
-
var obj;
if (!e) var e = window.event;
@@ -326,8 +305,6 @@
this.onhide(e);
}
-
- this.scrollDelta = undefined;
},
doHide: function(e){
@@ -427,33 +404,10 @@
this.doDisable(e);
},
- setScrollDelta: function() {
- if (!this.scrollDelta) {
- this.scrollDelta = [0, 0];
- }
- var parentNode = this.parent;
- while (parentNode && !/^body$/i.test(parentNode.tagName)) {
- if (/^absolute$/i.test(Richfaces.getComputedStyle(parentNode, "position")))
{
- if (parentNode.scrollLeft) {
- this.scrollDelta[0] = parentNode.scrollLeft;
- }
- if (parentNode.scrollTop) {
- this.scrollDelta[1] = parentNode.scrollTop;
- }
- }
- parentNode = parentNode.parentNode;
- }
- },
-
/*
* we can pass here not event only, but also object {'clientX':XXX,
'clientY':XXX}
*/
setToolTipPosition: function(e){
- var toolTipX=0;
- var toolTipY=0;
-
- var x = Event.pointerX(e);
- var y = Event.pointerY(e);
//
// var toolTipDim = Element.getDimensions(this.toolTip);
// this.toolTipW = toolTipDim.width;
@@ -466,60 +420,55 @@
var _visibility = this.toolTip.style.visibility;
this.toolTip.style.visibility = "hidden";
this.toolTip.style.display = "block";
+
this.toolTip.style.top = "0px";
this.toolTip.style.left = "0px";
- var offsets = Richfaces.ToolTip.cumulativeOffset(this.toolTip);
+ var event = jQuery.event.fix(e);
var offsetWidth = this.toolTip.offsetWidth;
var offsetHeight = this.toolTip.offsetHeight;
- this.toolTip.style.visibility = _visibility;
- this.toolTip.style.display = _display;
-
- offsets[0] -= this.toolTip.offsetLeft || 0;
- offsets[1] -= this.toolTip.offsetTop || 0;
-
- toolTipX = x - offsets[0];
- toolTipY = y - offsets[1];
-
-// var windowDim = this.windowSize();
-
var regExpression = /^(top|bottom)-(left|right)$/;
var match = this.direction.match(regExpression);
var horizontalDirection = match[2];
var verticalDirection = match[1];
+
+ var coords = this.fitToolTip(e.clientX, e.clientY, elementDim, horizontalDirection,
verticalDirection,
+ {'x':this.horizontalOffset, 'y':this.verticalOffset});
- this.prePosition({'x':toolTipX, 'y':toolTipY}, elementDim,
horizontalDirection, verticalDirection, {'x':this.horizontalOffset,
'y':this.verticalOffset});
+ 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 coords = this.fitToolTip(e.clientX, e.clientY, {'x':toolTipX ,
'y':toolTipY},elementDim, horizontalDirection, verticalDirection,
{'x':this.horizontalOffset, 'y':this.verticalOffset});
-
- if (this.scrollDelta) {
- coords.x += this.scrollDelta[0];
- coords.y += this.scrollDelta[1];
- }
-
- Element.setStyle(this.toolTip, {"left": coords.x + "px",
"top": coords.y + "px"});
+ Element.setStyle(this.toolTip, {"left": x + "px",
"top": y + "px"});
if(this.iframe)
{
- this.iframe.style.top = (coords.y - this.toolTipBorderHeight) + 'px';
- this.iframe.style.left = (coords.x - this.toolTipBorderWidth) + 'px';
+ this.iframe.style.top = (y - this.toolTipBorderHeight) + 'px';
+ this.iframe.style.left = (x - this.toolTipBorderWidth) + 'px';
this.iframe.style.width = offsetWidth + 'px';
this.iframe.style.height = offsetHeight + 'px';
}
+
+ this.toolTip.style.visibility = _visibility;
+ this.toolTip.style.display = _display;
+
this.eventCopy = A4J.AJAX.CloneObject(e, false);
},
- prePosition: function(basePoint, elementDim, horizontalDirection, verticalDirection,
offset){
+ prePosition: function(x, y, elementDim, horizontalDirection, verticalDirection,
offset){
var returnX, returnY;
- returnX = horizontalDirection=='left' ? basePoint.x - elementDim.width -
offset.x : basePoint.x += offset.x;
- returnY = verticalDirection == 'top' ? basePoint.y - elementDim.height -
offset.y : basePoint.y + offset.y;
+ returnX = horizontalDirection=='left' ? x - elementDim.width - offset.x : x +
offset.x;
+ returnY = verticalDirection == 'top' ? y - elementDim.height - offset.y : y +
offset.y;
return {'x':returnX, 'y':returnY};
},
- fitToolTip: function(clientX, clientY,basePoint,elementDim, horizontalDirection,
verticalDirection, offset){
+ fitToolTip: function(clientX, clientY, elementDim, horizontalDirection,
verticalDirection, offset){
var winDim = Richfaces.Position.getWindowDimensions();
var deltaLeft = clientX - offset.x - elementDim.width;
var deltaRight = winDim.width - (clientX + offset.x + elementDim.width);
@@ -528,7 +477,6 @@
if(deltaLeft < 0){
// in this case new direction will be right
- this.prePosition({'x':basePoint.x , 'y':basePoint.y},elementDim,
'right', verticalDirection, offset);
var newDeltaRight = winDim.width - (clientX + offset.x + elementDim.width);
if(newDeltaRight > 0){
horizontalDirection = 'right';
@@ -539,7 +487,6 @@
}
} else if(deltaRight < 0){
// in this case new direction will be left
- this.prePosition({'x':basePoint.x , 'y':basePoint.y},elementDim,
'left', verticalDirection, offset);
var newDeltaLeft = clientX - offset.x - elementDim.width;
if(newDeltaLeft > 0){
horizontalDirection = 'left';
@@ -552,7 +499,6 @@
if(deltaTop < 0){
// in this case new direction will be right
- this.prePosition({'x':basePoint.x , 'y':basePoint.y},elementDim,
horizontalDirection, 'bottom', offset);
var newDeltaBottom = winDim.height - (clientY + offset.y + elementDim.height);
if(newDeltaBottom > 0){
verticalDirection = 'bottom';
@@ -562,7 +508,6 @@
}
}
} else if(deltaBottom < 0){
- this.prePosition({'x':basePoint.x , 'y':basePoint.y},elementDim,
horizontalDirection, 'top', offset);
var newDeltaTop = clientY - offset.y - elementDim.height;
if(newDeltaTop > 0){
verticalDirection = 'top';
@@ -572,7 +517,7 @@
}
}
}
- var coords = this.prePosition({'x':basePoint.x ,
'y':basePoint.y},elementDim, horizontalDirection, verticalDirection, offset);
+ var coords = this.prePosition(clientX, clientY, elementDim, horizontalDirection,
verticalDirection, offset);
return coords;
},
Modified:
trunk/ui/tooltip/src/test/java/org/richfaces/component/TooltipComponentTest.java
===================================================================
---
trunk/ui/tooltip/src/test/java/org/richfaces/component/TooltipComponentTest.java 2008-08-14
00:11:20 UTC (rev 10079)
+++
trunk/ui/tooltip/src/test/java/org/richfaces/component/TooltipComponentTest.java 2008-08-14
00:11:26 UTC (rev 10080)
@@ -54,6 +54,7 @@
javaScripts.add("org.ajax4jsf.javascript.AjaxScript");
javaScripts.add("org/richfaces/renderkit/html/scripts/utils.js");
+ javaScripts.add("org/richfaces/renderkit/html/scripts/jquery/jquery.js");
javaScripts.add("org/richfaces/renderkit/html/scripts/tooltip.js");
javaScripts.add("prototype.js");
}