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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Sat, 18 Aug 2007 00:01:45 -0000


albertel		Fri Aug 17 20:01:45 2007 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
    /loncom/homework	lonhomework.pm 
  Log:
  - BUG#1993, editxml text area auto resizes itself to just fit inside the 
              the space available in the window
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.564 loncom/interface/loncommon.pm:1.565
--- loncom/interface/loncommon.pm:1.564	Wed Aug 15 14:03:22 2007
+++ loncom/interface/loncommon.pm	Fri Aug 17 20:01:37 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.564 2007/08/15 18:03:22 albertel Exp $
+# $Id: loncommon.pm,v 1.565 2007/08/18 00:01:37 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1084,6 +1084,63 @@
 
 =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 {
+    return <<"RESIZE";
+    <script type="text/javascript">
+var Geometry = {};
+function init_geometry() {
+    if (Geometry.init) { return };
+    Geometry.init=1;
+    if (window.innerHeight) {
+	Geometry.getViewportHeight = function() { return window.innerHeight; };
+    }
+    else if (document.documentElement && document.documentElement.clientHeight) {
+	Geometry.getViewportHeight = 
+	    function() { return document.documentElement.clientHeight; };
+    }
+    else if (document.body.clientHeight) {
+	Geometry.getViewportHeight = 
+	    function() { return document.body.clientHeight; };
+    }
+}
+
+function resize_textarea(textarea_id,bottom_id) {
+    init_geometry();
+    var textarea        = document.getElementById(textarea_id);
+    //alert(textarea);
+
+    var textarea_top    = textarea.offsetTop;
+    var textarea_height = textarea.offsetHeight;
+    var bottom          = document.getElementById(bottom_id);
+    var bottom_top      = bottom.offsetTop;
+    var bottom_height   = bottom.offsetHeight;
+    var window_height   = Geometry.getViewportHeight();
+    var fudge           = 23; 
+    var new_height      = window_height-fudge-textarea_top-bottom_height;
+    if (new_height < 300) {
+	new_height = 300;
+    }
+    textarea.style.height=new_height+'px';
+}
+</script>
+RESIZE
+
+}
+
+=pod
+
 =back
  
 =head1 Excel and CSV file utility routines
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.268 loncom/homework/lonhomework.pm:1.269
--- loncom/homework/lonhomework.pm:1.268	Mon Jul 23 19:30:47 2007
+++ loncom/homework/lonhomework.pm	Fri Aug 17 20:01:45 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.268 2007/07/23 23:30:47 albertel Exp $
+# $Id: lonhomework.pm,v 1.269 2007/08/18 00:01:45 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -861,10 +861,17 @@
 	if ($cols > 80) { $cols = 80; }
 	if ($cols < 70) { $cols = 70; }
 	if ($rows < 20) { $rows = 20; }
+	my $js =
+	    &Apache::edit::js_change_detection(). 
+	    &Apache::loncommon::resize_textarea_js();
 	my $start_page = 
-	    &Apache::loncommon::start_page(&mt("EditXML [_1]",$file),
-					   &Apache::edit::js_change_detection(),
-					   {'no_auto_mt_title' => 1,});
+	    &Apache::loncommon::start_page(&mt("EditXML [_1]",$file),$js,
+					   {'no_auto_mt_title' => 1,
+					    'only_body'        => 1,
+					    'add_entries'      => {
+						'onresize' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
+						'onload'   => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
+				    }});
 
 	$result.=$start_page.
 	    &renderpage($request,$file,['no_output_web'],1).
@@ -881,10 +888,14 @@
             <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" />
             <hr />
             ' . $xml_help . '
-            <textarea '.&Apache::edit::element_change_detection().' style="width:100%" rows="'.$rows.'" cols="'.$cols.'" name="editxmltext">'.
-	    &HTML::Entities::encode($problem,'<>&"').'</textarea><br />
-            <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes').'" />
-            <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" />
+            <textarea '.&Apache::edit::element_change_detection().
+	              ' rows="'.$rows.'" cols="'.$cols.'" style="width:100%" '.
+		      ' name="editxmltext" id="LC_editxmltext">'.
+		      &HTML::Entities::encode($problem,'<>&"').'</textarea>
+            <div id="LC_aftertextarea">
+                <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes').'" />
+                <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" />
+            </div>
             </form>'.&Apache::loncommon::end_page();
 	&Apache::lonxml::add_messages(\$result);
 	$request->print($result);