[LON-CAPA-cvs] cvs: rat / lonpage.pm loncom/homework response.pm loncom/homework/caparesponse caparesponse.pm

raeburn raeburn at source.lon-capa.org
Tue Dec 30 15:03:19 EST 2014


raeburn		Tue Dec 30 20:03:19 2014 EDT

  Modified files:              
    /loncom/homework	response.pm 
    /loncom/homework/caparesponse	caparesponse.pm 
    /rat	lonpage.pm 
  Log:
  - Changes in args passed to &edit_mathresponse_button() to support use of
    id attributes by LON-CAPA Math editor.
  - DragMath implementation now also uses id attributes.
  - Support math editor in formularesponse and mathresponse items in 
    composite pages (.page).
  
  
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.237 loncom/homework/response.pm:1.238
--- loncom/homework/response.pm:1.237	Wed Sep 24 18:14:27 2014
+++ loncom/homework/response.pm	Tue Dec 30 20:03:10 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.237 2014/09/24 18:14:27 damieng Exp $
+# $Id: response.pm,v 1.238 2014/12/30 20:03:10 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -56,6 +56,7 @@
 use Apache::inputtags();
 use Apache::lonmaxima();
 use Apache::lonr();
+use Apache::lontexconvert();
 
 BEGIN {
     &Apache::lonxml::register('Apache::response',('responseparam','parameter','dataresponse','customresponse','mathresponse'));
@@ -577,7 +578,8 @@
 }
 
 sub edit_mathresponse_button {
-    my ($id,$field)=@_;
+    my ($partid,$id)=@_;
+    my $field = 'HWVAL_'.$partid.'_'.$id;
     my $btype = $env{'browser.type'};
     my $bversion = $env{'browser.version'};
     if (($btype eq 'explorer' && $bversion < 9) || ($btype eq 'safari' && $bversion < 3) ||
@@ -588,23 +590,36 @@
       my $iconpath=$Apache::lonnet::perlvar{'lonIconsURL'};
       return(<<ENDFORMULABUTTON);
 <script type="text/javascript" language="JavaScript">
-function edit_${id}_${field} (textarea) {
-    thenumber = textarea;
-    thedata = document.forms['lonhomework'].elements[textarea].value;
+function LC_mathedit_${field} (LCtextline) {
+    thenumber = LCtextline;
+    var thedata = '';
+    if (document.getElementById(LCtextline)) {
+        thedata = document.getElementById(LCtextline).value;
+    }
     newwin = window.open("/adm/dragmath/MaximaPopup.html","","width=565,height=400,resizable");
 }
 </script>
-<a href="javascript:edit_${id}_${field}('${field}');void(0);"><img class="stift" src="$iconpath/stift.gif" alt="$button" title="$button" /></a>
+<a href="javascript:LC_mathedit_${field}('${field}');void(0);"><img class="stift" src="$iconpath/stift.gif" alt="$button" title="$button" /></a>
 ENDFORMULABUTTON
       
     } else {
-      # LON-CAPA math equation editor
-      return(<<EQ_EDITOR_SCRIPT);
+        # LON-CAPA math equation editor
+        my $mathjaxjs;
+        unless (lc(&Apache::lontexconvert::tex_engine()) eq 'mathjax') {
+            $mathjaxjs = <<"MATHJAX_SCRIPT";
+var mathjaxscript = document.createElement("script");
+    mathjaxscript.type = "text/javascript";
+    mathjaxscript.src = "/adm/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
+    document.body.appendChild(mathjaxscript);
+MATHJAX_SCRIPT
+        }
+        return(<<EQ_EDITOR_SCRIPT);
 <script type="text/javascript">
-  var field = document.getElementById('${field}');
-  field.className += ' math'; // note the space
+  var LCmathField = document.getElementById('${field}');
+  LCmathField.className += ' math'; // note the space
   var LCMATH_started;
   if (typeof LCMATH_started === 'undefined') {
+    $mathjaxjs
     LCMATH_started = true;
     var script = document.createElement("script");
     script.type = "text/javascript";
@@ -679,7 +694,7 @@
         my $id = $Apache::inputtags::response[-1];
         if (($Apache::inputtags::status['-1'] eq 'CAN_ANSWER')
            && (&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffeditor') ne 'yes')) {
-            $result.=&edit_mathresponse_button($id,"HWVAL_$id");
+            $result.=&edit_mathresponse_button($partid,$id);
         }
     }
 
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.254 loncom/homework/caparesponse/caparesponse.pm:1.255
--- loncom/homework/caparesponse/caparesponse.pm:1.254	Mon Jan 21 06:04:07 2013
+++ loncom/homework/caparesponse/caparesponse.pm	Tue Dec 30 20:03:15 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.254 2013/01/21 06:04:07 raeburn Exp $
+# $Id: caparesponse.pm,v 1.255 2014/12/30 20:03:15 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -645,7 +645,7 @@
         if (($target eq 'web') && ($tag eq 'formularesponse')
             && ($Apache::lonhomework::type ne 'exam') && ($Apache::inputtags::status['-1'] eq 'CAN_ANSWER')
 	    && (&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffeditor') ne 'yes')) {
-            $result.=&Apache::response::edit_mathresponse_button($id,"HWVAL_$id");
+            $result.=&Apache::response::edit_mathresponse_button($partid,$id);
         }
             
 	&Apache::response::setup_prior_tries_hash(\&format_prior_response_numerical);
Index: rat/lonpage.pm
diff -u rat/lonpage.pm:1.106 rat/lonpage.pm:1.107
--- rat/lonpage.pm:1.106	Tue Sep 16 13:28:34 2014
+++ rat/lonpage.pm	Tue Dec 30 20:03:19 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Page Handler
 #
-# $Id: lonpage.pm,v 1.106 2014/09/16 13:28:34 raeburn Exp $
+# $Id: lonpage.pm,v 1.107 2014/12/30 20:03:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -307,6 +307,12 @@
                                   #some additional cleanup necessary for LateX (due to limitations of table environment 
 				  $output =~ s/(\\vskip\s*\d+mm)\s*(\\\\)+/$1/g;
 			      }
+                              my $matheditor;
+                              if ($output =~ /\Qjavascript:LC_mathedit_HWVAL_\E/) {
+                                  $matheditor = 'dragmath';
+                              } elsif ($output =~ /LCmathField/) {
+                                  $matheditor = 'lcmath';
+                              }
                               my $parser=HTML::TokeParser->new(\$output);
                               my $token;
                               my $thisdir=$src;
@@ -373,6 +379,15 @@
 				      s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
                                   $output=~
                                       s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
+                                  if ($matheditor eq 'dragmath') {
+                                      $output=~
+                                          s/(\Qjavascript:LC_mathedit_\E)(HWVAL_)([^'"]+?)(\(['"]*)(\QHWVAL_\E\3['"]\)\;void\(0\)\;)/$1$idprefix$2$3$4$idprefix$5/g;
+                                      $output=~
+                                          s/(function\s+LC_mathedit_)(HWVAL_)([^'"]+?)(\s+\(LCtextline\))/$1$idprefix$2$3$4/g;
+                                  } elsif ($matheditor eq 'lcmath') {
+                                      $output=~
+                                          s/(var\s+LCmathField\s+=\s+document\.getElementById\(['"])([^'"]+?)(['"]\)\;)/$1$idprefix$2$3/g;
+                                  }
                                   $output=~
                                       s/(\Q<div id="msg_\E)(\Qsubmit_\E)([^"]*)(\Q" style="display:none">\E)/<input type="hidden" name="$prefix$2$3_pressed" id="$idprefix$2$3_pressed" value="" \/>$1$idprefix$2$3$4/g;
                                   $output=~




More information about the LON-CAPA-cvs mailing list