Author: nbelaevski
Date: 2008-08-12 15:20:42 -0400 (Tue, 12 Aug 2008)
New Revision: 10058
Modified:
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js
Log:
Positioning code added to utils
Modified:
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js
===================================================================
---
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js 2008-08-12
17:56:00 UTC (rev 10057)
+++
trunk/framework/impl/src/main/resources/org/richfaces/renderkit/html/scripts/utils.js 2008-08-12
19:20:42 UTC (rev 10058)
@@ -5,13 +5,21 @@
Richfaces.getComputedStyle = function(eltId, propertyName) {
var elt = $(eltId);
+ if (elt.nodeType != Node.ELEMENT_NODE) {
+ return "";
+ }
+
if (elt.currentStyle) {
return elt.currentStyle[propertyName];
}
- if (document.defaultView && document.defaultView.getComputedStyle &&
- document.defaultView.getComputedStyle(elt, null)) {
- return document.defaultView.getComputedStyle(elt,
null).getPropertyValue(propertyName);
+ if (document.defaultView && document.defaultView.getComputedStyle) {
+
+ var styles = document.defaultView.getComputedStyle(elt, null);
+ if (styles) {
+ return styles.getPropertyValue(propertyName);
+ }
+
}
return "";
@@ -393,4 +401,94 @@
parentNode.removeChild(node);
}
}
-}
+};
+
+//patched for 'fixed' positioning & 9.5 opera version of prototype.js
+//viewportOffset()
+//FIXME: seem to not work well when starting elements have margins
+Richfaces.getViewPortOffset = function(forElement) {
+ var valueT = 0, valueL = 0;
+
+ var startElement = forElement;
+
+ if (Richfaces.getComputedStyle(startElement, 'position') == 'absolute')
{
+ startElement = Element.getOffsetParent(startElement);
+ }
+
+ var element = startElement;
+
+ do {
+ valueT += (element.offsetTop || 0);
+ valueL += (element.offsetLeft || 0);
+
+ var position = Richfaces.getComputedStyle(element, 'position');
+
+ if (element != forElement || position != 'relative') {
+ valueT += (element.clientTop || 0);
+ valueL += (element.clientLeft || 0);
+ }
+
+ if (position == 'fixed') {
+ break;
+ }
+
+ // Safari fix
+ if (element.offsetParent == document.body &&
+ position == 'absolute') {
+ break;
+ }
+
+ } while (element = element.offsetParent);
+
+ element = startElement;
+ do {
+ valueT -= element.scrollTop || 0;
+ valueL -= element.scrollLeft || 0;
+
+ if (Richfaces.getComputedStyle(element, 'position') == 'fixed') {
+ break;
+ }
+
+ } while (element = element.parentNode);
+
+ return [valueL, valueT];
+};
+
+Richfaces.clonePosition = function(element, source, opts) {
+ var options = Object.extend({
+ setLeft: true,
+ setTop: true,
+ setWidth: true,
+ setHeight: true,
+ offsetTop: 0,
+ offsetLeft: 0
+ }, opts || { });
+
+ // find page position of source
+ source = $(source);
+ var p = Richfaces.getViewPortOffset(source);
+
+ // find coordinate system to use
+ element = $(element);
+ var delta = [0, 0];
+ var parent = null;
+ // delta [0,0] will do fine with position: fixed elements,
+ // position:absolute needs offsetParent deltas
+ if (Richfaces.getComputedStyle(element, 'position') == 'absolute') {
+ parent = element.getOffsetParent();
+ delta = Richfaces.getViewPortOffset(parent);
+ }
+
+ // correct by body offsets (fixes Safari)
+ if (parent == document.body) {
+ delta[0] -= document.body.offsetLeft;
+ delta[1] -= document.body.offsetTop;
+ }
+
+ // set position
+ if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) +
'px';
+ if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) +
'px';
+ if (options.setWidth) element.style.width = source.offsetWidth + 'px';
+ if (options.setHeight) element.style.height = source.offsetHeight + 'px';
+ return element;
+};