[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Tue, 25 Sep 2007 22:58:48 -0000


albertel		Tue Sep 25 18:58:48 2007 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  - get the absolute correct value for the Y location of an element
  - update Geometry to also have the scroll bar location accessors
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.587 loncom/interface/loncommon.pm:1.588
--- loncom/interface/loncommon.pm:1.587	Mon Sep 24 19:29:53 2007
+++ loncom/interface/loncommon.pm	Tue Sep 25 18:58:48 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.587 2007/09/24 23:29:53 raeburn Exp $
+# $Id: loncommon.pm,v 1.588 2007/09/25 22:58:48 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1094,30 +1094,58 @@
     if (Geometry.init) { return };
     Geometry.init=1;
     if (window.innerHeight) {
-	Geometry.getViewportHeight = function() { return window.innerHeight; };
+	Geometry.getViewportHeight   = function() { return window.innerHeight; };
+	Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
+	Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
     }
     else if (document.documentElement && document.documentElement.clientHeight) {
 	Geometry.getViewportHeight = 
 	    function() { return document.documentElement.clientHeight; };
+	Geometry.getHorizontalScroll = 
+	    function() { return document.documentElement.scrollLeft; };
+	Geometry.getVerticalScroll = 
+	    function() { return document.documentElement.scrollTop; };
     }
     else if (document.body.clientHeight) {
 	Geometry.getViewportHeight = 
 	    function() { return document.body.clientHeight; };
+	Geometry.getHorizontalScroll = 
+	    function() { return document.body.scrollLeft; };
+	Geometry.getVerticalScroll = 
+	    function() { return document.body.scrollTop; };
     }
 }
 
+function getX(element) {
+    var x = 0;
+    while (element) {
+	x += element.offsetLeft;
+	element = element.offsetParent;
+    }
+    return x;
+}
+function getY(element) {
+    var y = 0;
+    while (element) {
+	y += element.offsetTop;
+	element = element.offsetParent;
+    }
+    return y;
+}
+
+
 function resize_textarea(textarea_id,bottom_id) {
     init_geometry();
     var textarea        = document.getElementById(textarea_id);
     //alert(textarea);
 
-    var textarea_top    = textarea.offsetTop;
+    var textarea_top    = getY(textarea);
     var textarea_height = textarea.offsetHeight;
     var bottom          = document.getElementById(bottom_id);
-    var bottom_top      = bottom.offsetTop;
+    var bottom_top      = getY(bottom);
     var bottom_height   = bottom.offsetHeight;
     var window_height   = Geometry.getViewportHeight();
-    var fudge           = 23; 
+    var fudge           = 23;
     var new_height      = window_height-fudge-textarea_top-bottom_height;
     if (new_height < 300) {
 	new_height = 300;
@@ -1332,8 +1360,6 @@
 
 =over 4
 
-=cut
-
 =item * multiple_select_form($name,$value,$size,$hash,$order)
 
 Returns a string containing a <select> element int multiple mode