You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by gs...@apache.org on 2007/09/25 19:47:49 UTC
svn commit: r579329 -
/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
Author: gseitz
Date: Tue Sep 25 10:47:45 2007
New Revision: 579329
URL: http://svn.apache.org/viewvc?rev=579329&view=rev
Log:
WICKET-880: automatically position the datepicker so that it isn't rendered off screen on the right side or bottom
Modified:
wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
Modified: wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js?rev=579329&r1=579328&r2=579329&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js (original)
+++ wicket/trunk/jdk-1.4/wicket-datetime/src/main/java/org/apache/wicket/extensions/yui/calendar/wicket-date.js Tue Sep 25 10:47:45 2007
@@ -69,8 +69,27 @@
return (value < 10 ? "0" : "") + value;
}
+/**
+ * Gets the height of the displayed area of the window, as YAHOO.util.Dom.getViewportHeight()
+ * has issues with Firefox.
+ * See http://tech.groups.yahoo.com/group/ydn-javascript/message/5850
+ * Implementation taken from: http://www.quirksmode.org/viewport/compatibility.html#link2
+ */
+Wicket.DateTime.getViewportHeight = function() {
+ if (window.innerHeight) // all browsers except IE
+ viewPortHeight = window.innerHeight;
+ else if (document.documentElement && document.documentElement.clientHeight) // IE 6 strict mode
+ viewPortHeight = document.documentElement.height;
+ else if (document.body) // other IEs
+ viewPortHeight = document.body.clientHeight;
+ return viewPortHeight;
+}
+
/**
- * Position subject relative to target top-left.
+ * Position subject relative to target top-left by default.
+ * If there is too little space on the right side/bottom,
+ * the datepicker's position is corrected so that the right side/bottom
+ * is aligned with the display area's right side/bottom.
* @param subject the dom element to has to be positioned
* @param target id of the dom element to position relative to
*/
@@ -78,8 +97,25 @@
targetPos = YAHOO.util.Dom.getXY(target);
targetHeight = YAHOO.util.Dom.get(target).offsetHeight;
- YAHOO.util.Dom.setX(subject, targetPos[0]);
- YAHOO.util.Dom.setY(subject, targetPos[1] + targetHeight + 1);
+ subjectHeight = YAHOO.util.Dom.get(subject).offsetHeight;
+ subjectWidth = YAHOO.util.Dom.get(subject).offsetWidth;
+
+ viewPortHeight = Wicket.DateTime.getViewportHeight();
+ viewPortWidth = YAHOO.util.Dom.getViewportWidth();
+
+ // correct datepicker's position so that it isn't rendered off screen on the right side or bottom
+ if (targetPos[0] + subjectWidth > viewPortWidth) {
+ // correct horizontal position
+ YAHOO.util.Dom.setX(subject, viewPortWidth - subjectWidth);
+ } else {
+ YAHOO.util.Dom.setX(subject, targetPos[0]);
+ }
+ if (targetPos[1] + targetHeight + 1 + subjectHeight > viewPortHeight) {
+ // correct vertical position
+ YAHOO.util.Dom.setY(subject, viewPortHeight - subjectHeight);
+ } else {
+ YAHOO.util.Dom.setY(subject, targetPos[1] + targetHeight + 1);
+ }
}
/**