[LON-CAPA-cvs] cvs: loncom /homework lonhomework.pm structuretags.pm /html/adm/help/tex Authoring_Math_Editor.tex /interface lonhtmlcommon.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Mon, 28 Jul 2008 05:26:03 -0000


raeburn		Mon Jul 28 01:26:03 2008 EDT

  Added files:                 
    /loncom/html/adm/help/tex	Authoring_Math_Editor.tex 

  Modified files:              
    /loncom/interface	lonhtmlcommon.pm 
    /loncom/homework	lonhomework.pm structuretags.pm 
  Log:
  - Separate code used to create button and code used to generate javascript
    fired by button click.
  - Rename routines as &dragmath_button() and &dragmath_js().
  - Only include javascript used to launch DragMath pop-up once in Colorful editor screen.
  - Do not include Edit Math button when WYSIWYG is on ("Render Latex" button in pop-up was not writing to textarea in this case) - need to integrate Drag Math into FCKedit for this situation. 
  - Add contextual help for Edit Math button
  - Move "Edit Math" button in "EditXML" mode.
  
  
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.176 loncom/interface/lonhtmlcommon.pm:1.177
--- loncom/interface/lonhtmlcommon.pm:1.176	Mon Jul  7 07:02:05 2008
+++ loncom/interface/lonhtmlcommon.pm	Mon Jul 28 01:25:59 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.176 2008/07/07 11:02:05 foxr Exp $
+# $Id: lonhtmlcommon.pm,v 1.177 2008/07/28 05:25:59 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -68,33 +68,49 @@
 
 =pod
 
-=item dragmath
+=item dragmath_button
 
-Creates a button that will allow dragmath to edit an equation into 
-a specified textbox.
+Creates a button that launches a dragmath popup-window, in which an 
+expression can be edited and pasted as LaTeX into a specified textarea. 
+
+  textarea - Name of the textarea to edit.
+  helpicon - If true, show a help icon to the right of the button.
 
-  textarea - Name of the text area to edit.
 =cut
 
-##############################################
-# TODO: Figure out a way to only emit the mathedit function once.
-#       per html output document.
-#
+sub dragmath_button {
+    my ($textarea,$helpicon) = @_;
+    my $help_text; 
+    if ($helpicon) {
+        $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor');
+    }
+    return <<ENDDRAGMATH;
+                <input type="button" value="Edit Math", onclick="javascript:mathedit('$textarea',document)" />$help_text
+ENDDRAGMATH
+}
+
 ##############################################
 
-sub dragmath {
-    my ($textarea) = @_;
+=pod
 
-    return <<ENDDRAGMATH;
-                <script language="JavaScript">
+=item dragmath_js
+
+Javascript used to open pop-up window containing dragmath applet which 
+can be used to paste LaTeX into a textarea.
+ 
+=cut
+
+sub dragmath_js {
+    return <<ENDDRAGMATHJS;
+                <script type="text/javascript">
                   function mathedit(textarea, doc) {
                      targetEntry = textarea;
-		     targetDoc   = doc;
+                     targetDoc   = doc;
                      newwin  = window.open("/adm/dragmath/applet/EditMathPopup.html","","width=565,height=500,resizable");
                   }
                 </script>
-                <input type="button" value="Edit Math", onclick="javascript:mathedit('$textarea',document)" />
-ENDDRAGMATH
+
+ENDDRAGMATHJS
 }
 
 ##############################################
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.295 loncom/homework/lonhomework.pm:1.296
--- loncom/homework/lonhomework.pm:1.295	Mon Jul  7 07:02:25 2008
+++ loncom/homework/lonhomework.pm	Mon Jul 28 01:26:00 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.295 2008/07/07 11:02:25 foxr Exp $
+# $Id: lonhomework.pm,v 1.296 2008/07/28 05:26:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -935,9 +935,11 @@
 	my $js =
 	    &Apache::edit::js_change_detection(). 
 	    &Apache::loncommon::resize_textarea_js().
-            &Apache::structuretags::setmode_javascript();
+            &Apache::structuretags::setmode_javascript().
+            &Apache::lonhtmlcommon::dragmath_js();
 	my $only_body =  ($env{'environment.remote'} eq 'off')? 0 : 1;
-	my $dragmath = &Apache::lonhtmlcommon::dragmath("LC_editxmltext");
+	my $dragmath_button = 
+            &Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1);
 	my $start_page = 
 	    &Apache::loncommon::start_page(&mt("EditXML [_1]",$file),$js,
 					   {'no_auto_mt_title' => 1,
@@ -965,11 +967,11 @@
                 'onclick="javascript:setmode(this.form,'."'discard'".')" />
                 <input type="button" '.&Apache::edit::submit_ask_anyway('setmode(this.form,'."'edit'".')').'name="submitmode" accesskey="e" value="'.&mt('Edit').'" />
                 <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />
+                '.$dragmath_button.'
               </div>
               <div class="LC_edit_problem_saves">
                 <input type="submit" name="submitbutton" accesskey="s" value="'.&mt('Save').'"  />
-                <input type="submit" name="submitbutton" accesskey="v" value="'.&mt('Save and View').'" />'
-		.$dragmath.'
+                <input type="submit" name="submitbutton" accesskey="v" value="'.&mt('Save and View').'" />
               </div>
               <hr class="LC_edit_problem_divide" />
 	      '.&Apache::lonxml::message_location().'
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.424 loncom/homework/structuretags.pm:1.425
--- loncom/homework/structuretags.pm:1.424	Tue Jul  8 05:54:30 2008
+++ loncom/homework/structuretags.pm	Mon Jul 28 01:26:00 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.424 2008/07/08 09:54:30 foxr Exp $
+# $Id: structuretags.pm,v 1.425 2008/07/28 05:26:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -148,6 +148,10 @@
 
     $extra_head .= &homework_js();
 
+    unless ($env{'environment.wysiwygeditor'} eq 'on') {
+        $extra_head .= &Apache::lonhtmlcommon::dragmath_js();
+    }
+
     my %body_args;
     if (defined($found{'html'})) {
 	$body_args{'skip_phases'}{'head'}=1;
@@ -1878,9 +1882,13 @@
 		 ."</td>
 <td>".
                  &Apache::edit::insertlist($target,$token).
-		 '</td><td>'.
-		 &Apache::lonhtmlcommon::dragmath($areaid).'</td>'.
-		 '<td align="right" valign="top">' .
+		 '</td>';
+        unless ($env{'environment.wysiwygeditor'} eq 'on') {
+            $result.='<td align="left">'
+                     .&Apache::lonhtmlcommon::dragmath_button($areaid,1)
+                     .'</td>';
+        }
+	$result.='<td align="right" valign="top">' .
 		 &Apache::loncommon::helpLatexCheatsheet().
 		 &Apache::edit::end_row().
                  &Apache::edit::start_spanning_row()."\n".

Index: loncom/html/adm/help/tex/Authoring_Math_Editor.tex
+++ loncom/html/adm/help/tex/Authoring_Math_Editor.tex
You can use the \char`\"{}Edit Math\char`\"{} button to open a pop-up
window containing the Drag Math editor. Use the editor to compose
a math expression you wish to include in the text of a LON-CAPA resource,
click the {}``Render Latex'' button and the expression will be 
inserted at your current edit point in the main window - either in
the large editor area, if in EditXML mode, or in the current text block
you are modifying, if in template-based Edit mode. 

The {}``Edit Math'' button is not currently available when WYSIWYG
mode has been enabled in your User Preferences.