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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Thu, 27 Sep 2007 15:36:25 -0000


This is a MIME encoded message

--raeburn1190907385
Content-Type: text/plain

raeburn		Thu Sep 27 11:36:25 2007 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonhtmlcommon.pm domainprefs.pm 
  Log:
  loncommon.pm
  - extend Javascript init_geometry() function to report viewport width
  - creation of init_geometry() js function and Geometry js object moved out of resize_textarea_js() to separate utility routine
  - added sub routine to set form elements based on viewport width and height
  - fix CSS typo
  
  lonhtmlcommon.pm
  - eliminated javascript used for viewport dimensions in favor of loncommon::viewport_geometry_js()
  
  domainprefs.pm
  - calls to viewport js functions changed.
  
  
--raeburn1190907385
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070927113625.txt"

Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.589 loncom/interface/loncommon.pm:1.590
--- loncom/interface/loncommon.pm:1.589	Wed Sep 26 08:34:19 2007
+++ loncom/interface/loncommon.pm	Thu Sep 27 11:36:23 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.589 2007/09/26 12:34:19 raeburn Exp $
+# $Id: loncommon.pm,v 1.590 2007/09/27 15:36:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1074,48 +1074,95 @@
 
 =pod
 
-=item * resize_textarea_js
-
-emits the needed javascript to resize a textarea to be as big as possible
-
-creates a function resize_textrea that takes two IDs first should be
-the id of the element to resize, second should be the id of a div that
-surrounds everything that comes after the textarea, this routine needs
-to be attached to the <body> for the onload and onresize events.
+=item * viewport_geometry_js {
 
+Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
 
 =cut
 
-sub resize_textarea_js {
-    return <<"RESIZE";
-    <script type="text/javascript">
+
+sub viewport_geometry_js { 
+    return <<"GEOMETRY";
 var Geometry = {};
 function init_geometry() {
     if (Geometry.init) { return };
     Geometry.init=1;
     if (window.innerHeight) {
-	Geometry.getViewportHeight   = function() { return window.innerHeight; };
-	Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
-	Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
+        Geometry.getViewportHeight   = function() { return window.innerHeight; };
+        Geometry.getViewportWidth   = function() { return window.innerWidth; };
+        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; };
+        Geometry.getViewportHeight =
+            function() { return document.documentElement.clientHeight; };
+        Geometry.getViewportWidth =
+            function() { return document.documentElement.clientWidth; };
+
+        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; };
+        Geometry.getViewportHeight =
+            function() { return document.body.clientHeight; };
+        Geometry.getViewportWidth =
+            function() { return document.body.clientWidth; };
+        Geometry.getHorizontalScroll =
+            function() { return document.body.scrollLeft; };
+        Geometry.getVerticalScroll =
+            function() { return document.body.scrollTop; };
     }
 }
 
+GEOMETRY
+}
+
+=pod
+
+=item * viewport_size_js {
+
+Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window. 
+
+=cut
+
+sub viewport_size_js {
+    my $geometry = &viewport_geometry_js();
+    return <<"DIMS";
+
+$geometry
+
+function getViewportDims(width,height) {
+    init_geometry();
+    width.value = Geometry.getViewportWidth();
+    height.value = Geometry.getViewportHeight();
+    return;
+}
+
+DIMS
+}
+
+=pod
+
+=item * resize_textarea_js
+
+emits the needed javascript to resize a textarea to be as big as possible
+
+creates a function resize_textrea that takes two IDs first should be
+the id of the element to resize, second should be the id of a div that
+surrounds everything that comes after the textarea, this routine needs
+to be attached to the <body> for the onload and onresize events.
+
+
+=cut
+
+sub resize_textarea_js {
+    my $geometry = &viewport_geometry_js();
+    return <<"RESIZE";
+    <script type="text/javascript">
+$geometry
+
 function getX(element) {
     var x = 0;
     while (element) {
@@ -4921,7 +4968,7 @@
 }
 
 table.LC_double_column tr td.LC_left_col {
-  top: 2x;
+  top: 2px;
   left: 2px;
   width: 47%;
   vertical-align: top;
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.163 loncom/interface/lonhtmlcommon.pm:1.164
--- loncom/interface/lonhtmlcommon.pm:1.163	Wed Sep 26 08:42:32 2007
+++ loncom/interface/lonhtmlcommon.pm	Thu Sep 27 11:36:23 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.163 2007/09/26 12:42:32 raeburn Exp $
+# $Id: lonhtmlcommon.pm,v 1.164 2007/09/27 15:36:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1879,52 +1879,6 @@
     return $scripttag;
 }
 
-##############################################
-##############################################
-
-# javascript_window_dims
-#
-# Generates javascript to get the dimensions of the user's browser window.
-
-sub javascript_window_dims {
-    my $scripttag .= <<'END';
-function getDimensions(width,height) {
-    width.value = getWindowWidth();
-    height.value = getWindowHeight();
-    return;
-}
- 
-function getWindowWidth() {
-  var width = 0;
-  if( document.documentElement && document.documentElement.clientWidth ) {
-    width = document.documentElement.clientWidth;
-  }
-  else if( document.body && document.body.clientWidth ) {
-    width = document.body.clientWidth;
-  }
-  else if( window.innerWidth ) {
-    width = window.innerWidth - 18;
-  }
-  return width;
-}
-
-function getWindowHeight() {
-  var height = 0;
-  if( document.documentElement && document.documentElement.clientHeight ) {
-    height = document.documentElement.clientHeight;
-  }
-  else if( document.body && document.body.clientHeight ) {
-    height = document.body.clientHeight;
-  }
-  else if( window.innerHeight ) {
-    height = window.innerHeight - 18;
-  }
-  return height;
-}
-
-END
-    return $scripttag;
-}
 1;
 
 __END__
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.30 loncom/interface/domainprefs.pm:1.31
--- loncom/interface/domainprefs.pm:1.30	Wed Sep 26 08:42:32 2007
+++ loncom/interface/domainprefs.pm	Thu Sep 27 11:36:23 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.30 2007/09/26 12:42:32 raeburn Exp $
+# $Id: domainprefs.pm,v 1.31 2007/09/27 15:36:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -460,18 +460,18 @@
     } elsif ($phase eq 'display') {
         $js .= &color_pick_js()."\n";
     }
-    $js .= &Apache::lonhtmlcommon::javascript_window_dims().'
+    $js .= &Apache::loncommon::viewport_size_js().'
 </script>
 ';
     my $additem;
     if ($phase eq 'pickactions') {
         my %loaditems = (
-                    'onload' => "javascript:;getDimensions(document.$phase.width,document.$phase.height);setDisplayColumns();setFormElements(document.pickactions);",
+                    'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);setDisplayColumns();setFormElements(document.pickactions);",
                         );
         $additem = {'add_entries' => \%loaditems,};
     } else {
         my %loaditems = (
-                    'onload' => "javascript:getDimensions(document.$phase.width,document.$phase.height)",
+                    'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);",
                         );
         $additem = {'add_entries' => \%loaditems,};
     }

--raeburn1190907385--