Author: nbelaevski
Date: 2009-04-08 09:17:26 -0400 (Wed, 08 Apr 2009)
New Revision: 13431
Added:
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.utils.js
Modified:
trunk/framework/impl/pom.xml
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js
trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx
trunk/ui/contextMenu/src/main/java/org/richfaces/renderkit/html/ContextMenuRendererBase.java
trunk/ui/contextMenu/src/test/java/org/richfaces/component/ContextMenuComponentTest.java
trunk/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js
Log:
https://jira.jboss.org/jira/browse/RF-6467
Modified: trunk/framework/impl/pom.xml
===================================================================
--- trunk/framework/impl/pom.xml 2009-04-08 12:48:31 UTC (rev 13430)
+++ trunk/framework/impl/pom.xml 2009-04-08 13:17:26 UTC (rev 13431)
@@ -74,6 +74,7 @@
<include>${project.build.directory}/compressed/org/ajax4jsf/javascript/scripts/AJAX-min.js</include>
<include>${project.build.directory}/compressed/org/richfaces/renderkit/html/scripts/scriptaculous/scriptaculous-min.js</include>
<include>${project.build.directory}/compressed/org/richfaces/renderkit/html/scripts/jquery/jquery-min.js</include>
+ <include>${project.build.directory}/compressed/org/richfaces/renderkit/html/scripts/jquery.utils-min.js</include>
<include>${project.build.directory}/compressed/org/ajax4jsf/javascript/scripts/dnd-min.js</include>
<include>**/*-min.js</include>
</includes>
Added:
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.utils.js
===================================================================
---
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.utils.js
(rev 0)
+++
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/jquery.utils.js 2009-04-08
13:17:26 UTC (rev 13431)
@@ -0,0 +1,83 @@
+if (!window.Richfaces) {
+ window.Richfaces = {};
+}
+
+Richfaces.jQuery = {};
+
+(function(_r$, jQuery) {
+ var PX_REGEX = /^\s*[^\s]*px\s*$/;
+
+ var parseToPx = function(value) {
+ if (value) {
+ if (PX_REGEX.test(value)) {
+ try {
+ return parseInt(value.replace(PX_REGEX, ""), 10);
+ } catch (e) { }
+ }
+ }
+
+ return NaN;
+ };
+
+ _r$.position = function(rect, element) {
+ var jqe = jQuery(element);
+ var width = jqe.width();
+ var height = jqe.height();
+
+ var left = parseToPx(jqe.css('left'));
+ if (isNaN(left)) {
+ left = 0;
+ jqe.css('left', '0px');
+ }
+
+ var top = parseToPx(jqe.css('top'));
+ if (isNaN(top)) {
+ top = 0;
+ jqe.css('top', '0px');
+ }
+
+ var elementOffset = jqe.offset();
+
+ var jqw = jQuery(window);
+
+ var winWidth = jqw.width();
+ var winLeft = jqw.scrollLeft();
+
+ var winHeight = jqw.height();
+ var winTop = jqw.scrollTop();
+
+ var newLeft;
+ if (rect.left + width > winLeft + winWidth && rect.left + rect.width - width
>= winLeft) {
+ newLeft = rect.left + rect.width - width;
+ } else {
+ newLeft = rect.left;
+ }
+
+ var newTop;
+ if (rect.top + rect.height + height > winTop + winHeight && rect.top -
height >= winTop) {
+ newTop = rect.top - height;
+ } else {
+ newTop = rect.top + rect.height;
+ }
+
+ left += newLeft - elementOffset.left;
+ top += newTop - elementOffset.top;
+
+ jqe.css('left', (left + 'px')).css('top', (top +
'px'));
+ };
+
+ _r$.getPointerRectangle = function(event) {
+ var e = jQuery.event.fix(event);
+
+ return {width: 0, height: 0, left: e.pageX, top: e.pageY};
+ };
+
+ _r$.getElementRectangle = function(element) {
+ var jqe = jQuery(element);
+ var offset = jqe.offset();
+
+ return {width: jqe.width(), height: jqe.height(), left: offset.left, top: offset.top};
+ };
+
+}(Richfaces.jQuery, jQuery));
+
Modified:
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js
===================================================================
---
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js 2009-04-08
12:48:31 UTC (rev 13430)
+++
trunk/ui/colorPicker/src/main/resources/org/richfaces/renderkit/html/scripts/ui.colorpicker.js 2009-04-08
13:17:26 UTC (rev 13431)
@@ -320,34 +320,13 @@
var top = 0;
var left = 0;
- this.picker.css({visibility: 'hidden'}).css({left: '0px', top:
'0px', display: 'block'});
-
- var win = $(window);
- var winWidth = win.width();
- var winHeight = win.height();
+ this.picker.css('visibility', 'hidden').css('display',
'block');
- var spanOffsets = this.element.offset();
- var pickerOffsets = this.picker.offset();
+ var elementRect = Richfaces.jQuery.getElementRectangle(this.element);
+ Richfaces.jQuery.position(elementRect, this.picker);
- left = spanOffsets.left - pickerOffsets.left;
- top = spanOffsets.top - pickerOffsets.top;
+ this.picker.css('visibility', 'visible');
- var relLeft = spanOffsets.left - win.scrollLeft();
- var relTop = spanOffsets.top - win.scrollTop();
-
- if (relTop + this.picker.height() + this.element.height() > winHeight &&
relTop - this.picker.height() > 0) {
- top -= this.picker.height();
- } else {
- top += this.element.height();
- }
-
- if (relLeft + this.picker.width() > winWidth && relLeft +
this.element.width() - this.picker.width() > 0) {
- left += -this.picker.width() + this.element.width();
- } else {
- //left is ok
- }
-
- this.picker.css({left: left + 'px', top: top + 'px'}).css({visibility:
'visible'});
if (this._trigger("show", e, { options: this.options, hsb: this.color, hex:
this._HSBToHex(this.color), rgb: this._HSBToRGB(this.color) }) != false) {
this.picker.show();
}
Modified: trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx
===================================================================
--- trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx 2009-04-08
12:48:31 UTC (rev 13430)
+++ trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx 2009-04-08
13:17:26 UTC (rev 13431)
@@ -11,7 +11,7 @@
component="org.richfaces.component.UIColorPicker"
<f:clientid var="clientId"/>
- <h:scripts>/org/richfaces/renderkit/html/scripts/jquery/jquery.js,
/org/richfaces/renderkit/html/scripts/pngFix.js,
/org/richfaces/renderkit/html/scripts/ui.core.js,
/org/richfaces/renderkit/html/scripts/ui.colorpicker.js</h:scripts>
+ <h:scripts>/org/richfaces/renderkit/html/scripts/jquery/jquery.js,
/org/richfaces/renderkit/html/scripts/jquery.utils.js,
/org/richfaces/renderkit/html/scripts/pngFix.js,
/org/richfaces/renderkit/html/scripts/ui.core.js,
/org/richfaces/renderkit/html/scripts/ui.colorpicker.js</h:scripts>
<h:styles>/org/richfaces/renderkit/html/css/colorPicker.xcss</h:styles>
<f:resource name="/org/richfaces/renderkit/html/images/arrow.gif"
var="arrow" />
<f:resource name="/org/richfaces/renderkit/html/images/rainbow.png"
var="rainbow" />
Modified:
trunk/ui/contextMenu/src/main/java/org/richfaces/renderkit/html/ContextMenuRendererBase.java
===================================================================
---
trunk/ui/contextMenu/src/main/java/org/richfaces/renderkit/html/ContextMenuRendererBase.java 2009-04-08
12:48:31 UTC (rev 13430)
+++
trunk/ui/contextMenu/src/main/java/org/richfaces/renderkit/html/ContextMenuRendererBase.java 2009-04-08
13:17:26 UTC (rev 13431)
@@ -78,7 +78,8 @@
new org.ajax4jsf.javascript.PrototypeScript(),
new org.ajax4jsf.javascript.AjaxScript(),
getResource("/org/richfaces/renderkit/html/scripts/available.js"),
- getResource("/org/richfaces/renderkit/html/scripts/jquery/jquery.js")
+ getResource("/org/richfaces/renderkit/html/scripts/jquery/jquery.js"),
+ getResource("/org/richfaces/renderkit/html/scripts/jquery.utils.js")
};
Modified:
trunk/ui/contextMenu/src/test/java/org/richfaces/component/ContextMenuComponentTest.java
===================================================================
---
trunk/ui/contextMenu/src/test/java/org/richfaces/component/ContextMenuComponentTest.java 2009-04-08
12:48:31 UTC (rev 13430)
+++
trunk/ui/contextMenu/src/test/java/org/richfaces/component/ContextMenuComponentTest.java 2009-04-08
13:17:26 UTC (rev 13431)
@@ -68,6 +68,7 @@
javaScripts.add("org/richfaces/renderkit/html/scripts/menu.js");
javaScripts.add("org/richfaces/renderkit/html/scripts/available.js");
javaScripts.add("org/richfaces/renderkit/html/scripts/jquery/jquery.js");
+ javaScripts.add("/org/richfaces/renderkit/html/scripts/jquery.utils.js");
}
/**
Modified:
trunk/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js
===================================================================
---
trunk/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js 2009-04-08
12:48:31 UTC (rev 13430)
+++
trunk/ui/menu-components/src/main/resources/org/richfaces/renderkit/html/scripts/menu.js 2009-04-08
13:17:26 UTC (rev 13431)
@@ -391,82 +391,16 @@
this.layer = $(layer);
this.show = function() {
RichFaces.Menu.Layers.shutdown();
- var body = RichFaces.Menu.getPageDimensions();
- var win = RichFaces.Menu.getWindowDimensions();
- var bodyHeight = body.height;
- var bodyWidth = body.width;
-
+
var layer_display = this.layer.style.display;
- if (layer_display=='none')
- {
+ if (layer_display=='none') {
this.layer.style.visibility='hidden';
this.layer.style.display='';
}
- var clientX = this.event.clientX;
- var clientY = this.event.clientY;
-
- var e = this.event;
- var x = Event.pointerX(e);
- var y = Event.pointerY(e);
- var elementDim = Richfaces.Position.getOffsetDimensions(this.layer);
-
- var offsets = Position.cumulativeOffset(this.layer);
-
- offsets[0] -= this.layer.offsetLeft || 0;
- offsets[1] -= this.layer.offsetTop || 0;
-
- var toolTipX = x - offsets[0];
- var toolTipY = y - offsets[1];
-
- var scrollOffsets = Position.realOffset(this.layer);
- toolTipX = toolTipX + scrollOffsets[0];
- toolTipY = toolTipY + scrollOffsets[1];
- var dx = window.pageXOffset || document.documentElement.scrollLeft ||
document.body.scrollLeft || 0;
- var dy = window.pageYOffset || document.documentElement.scrollTop ||
document.body.scrollTop || 0;
- toolTipX -= dx;
- toolTipY -= dy;
-
- var layerdim = Element.getDimensions(this.layer);
- var layerLeft = toolTipX;
-
- if (clientX + layerdim.width > win.width) {
- layerLeft -= (layerdim.width - RichFaces.Menu.Layers.shadowWidth -
RichFaces.Menu.Layers.CornerRadius);
- }
-
- if (layerLeft < 0) {
- layerLeft = 0;
- }
-
- /*
- if (layerLeft + layerdim.width > bodyWidth) {
- layerLeft = bodyWidth - layerdim.width;
- }
-
- if (layerLeft < 0) {
- layerLeft = 0;
- }
- */
- var layerTop = toolTipY;
- /*if (layertop + layerdim.height > bodyHeight) {
- layertop = bodyHeight - layerdim.height;
- }
-
- if (layertop < 0) {
- layertop = 0;
- }
- */
- if (clientY + layerdim.height > win.height) {
- layerTop -= (layerdim.height - RichFaces.Menu.Layers.shadowWidth -
RichFaces.Menu.Layers.CornerRadius);
- }
-
- if (layerTop < 0) {
- layerTop = 0;
- }
-
- this.layer.style.left = layerLeft + "px";
- this.layer.style.top = layerTop + "px";
-
+ var cursorRect = Richfaces.jQuery.getPointerRectangle(this.event);
+ Richfaces.jQuery.position(cursorRect, this.layer);
+
this.layer.style.display=layer_display;
this.layer.style.visibility='';