[LON-CAPA-cvs] cvs: loncom /html/res/adm/pages/reactionresponse reaction_editor.html reaction_frame.html reaction_help.html reaction_viewer.html reaction_window.html

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 30 Jun 2003 20:40:00 -0000


This is a MIME encoded message

--albertel1057005600
Content-Type: text/plain

albertel		Mon Jun 30 16:40:00 2003 EDT

  Added files:                 
    /loncom/html/res/adm/pages/reactionresponse	reaction_editor.html 
                                               	reaction_frame.html 
                                               	reaction_help.html 
                                               	reaction_viewer.html 
                                               	reaction_window.html 
  Log:
  - adding helper files for reactionresponse
  
  
--albertel1057005600
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20030630164000.txt"


Index: loncom/html/res/adm/pages/reactionresponse/reaction_editor.html
+++ loncom/html/res/adm/pages/reactionresponse/reaction_editor.html
<!-- Chemical reaction editor developed by Guy Ashkenazi, guy@fh.huji.ac.il-->

<!--
 $Id: reaction_editor.html,v 1.1 2003/06/30 20:39:59 albertel Exp $

 Copyright Michigan State University Board of Trustees

 This file is part of the LearningOnline Network with CAPA (LON-CAPA).

 LON-CAPA is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 LON-CAPA is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with LON-CAPA; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 /home/httpd/html/adm/gpl.txt

 http://www.lon-capa.org/
-->

<html>
<head>
<script type="text/javascript">
var rightarrow;
</script>
<!-- parsed by LON-CAPA to get the correct symbol for the arrow -->
<display>
return '<script type="text/javascript">
          var rightarrow=\''.&xmlparse('<m>$\rightarrow$</m>').'\';
        </script>';
</display>
<script language="JavaScript">

var level;
var reactants;
var products;


function parse_reaction(string) {
  var reaction_array = string.split('->');
  var i;
  reactants = new Array(0);
  products = new Array(0);

  if (reaction_array.length > 0) 
    reactants = reaction_array[0].split(' +');
  if (reaction_array.length > 1) 
    products = reaction_array[1].split(' +');
}

function to_capa(string) {
  var reaction = "";
  var i;

  parse_reaction(string);
 
  for (i = 0; i < reactants.length; i++) 
    reactants[i] = capa_component(reactants[i]);
  for (i = 0; i < products.length; i++) 
    products[i] = capa_component(products[i]);
 
  reactants.sort();
  products.sort();

  for (i = 0; i < reactants.length-1; i++) {
    reaction += reactants[i];
    reaction += " + ";
  }
  if (i < reactants.length)
    reaction += reactants[i];
  if (products.length > 0) {
    reaction += " -> ";
    for (i = 0; i < products.length-1; i++) {
      reaction += products[i];
      reaction += " + ";
    }
    if (i < products.length)
      reaction += products[i];
  }

  return reaction;
}

function capa_component(string) {
  var reactant = "";
  var i = 0;
  level = 0;

  for (;string.substring(i,i+1) == ' ';i++)
    ;
  for (;isDigit(string.substring(i,i+1));i++)
    reactant += string.substring(i,i+1);
  for (;i < string.length;i++)
    reactant +=  capa_char(string.substring(i,i+1));

  return reactant;
}

function capa_char(chr) {
  if (level == 0) { // baseline
    if (chr == '^') 
      level = 1;
    if (chr == ' ')
      return "";
    return chr;
  }
  if (level == 1) { // superscript
    if (isDigit(chr))
      return chr;
    level = 0;
    return chr;
  }
}

function to_html(string) {
  var reaction = "";
  var i;

  parse_reaction(string);
  for (i = 0; i < reactants.length-1; i++) {
    reaction += html_component(reactants[i]);
    reaction += " + ";
  }
  if (i < reactants.length)
    reaction += html_component(reactants[i]);

  if (products.length > 0) {
    reaction += rightarrow;
    for (i = 0; i < products.length-1; i++) {
      reaction += html_component(products[i]);
      reaction += " + ";
    }
    if (i < products.length)
      reaction += html_component(products[i]);
  }

  return reaction;
}

function html_component(string) {
  var reactant = "";
  var i = 0;
  level = 0;

  for (;string.substring(i,i+1) == ' ';i++)
    ;
  for (;isDigit(string.substring(i,i+1));i++)
    reactant += string.substring(i,i+1);
  for (;i < string.length;i++)
    reactant +=  html_char(string.substring(i,i+1));

  return reactant;
}

function html_char(chr) {
  if (level == 0) { // baseline
    if (isDigit(chr))
      return chr.sub();
    if (chr == '^') {
      level = 1;
      return "";
    }
    if (chr == '+') // baseline or superscript
      return "?";
    if (chr == ' ')
      return "";
    return chr;
  }
  if (level == 1) { // superscript
    if (isDigit(chr))
      return chr.sup();
    if (chr == '+' || chr == '-') {
      level = 0;
      return chr.sup();
    }
    if (chr == ' ') {
      level = 0;
      return "";
    }
    level = 0;
    return chr;
  }
}

function isDigit(string) {
  if (string >= '0' && string <='9')
    return 1;
  else
    return 0;
}

function openHelpWindow() {
  window.open("reaction_help.html","","scrollbars=yes,resizable=yes,width=550,height=600")
}

function submitReaction() {
  reaction = to_capa(document.form.text.value);
  if (reaction == "") {
    alert("Nothing to submit");
  }
  else {
    name = "HWVAL_" + problem;
    i = 0;
    while (parent.opener.document.lonhomework.elements[i].name != name) 
      i++;
    parent.opener.document.lonhomework.elements[i].value = reaction;
    parent.opener.document.lonhomework.submit();
  }
}

function getCookie(document,name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}


</script>
</head>

<body bgcolor="#ffffff" onLoad = "problem = getCookie(parent.opener.document,'problem'); document.form.submit.value='Submit reaction for Part #' + problem; parent.document.title='LON-CAPA#'+problem+' - Reaction Editor';">
<center>
<hr />
<form name="form">
<input type="text" size=50 name="text" />
<input type="button" value="Check" onClick = "parent.viewer.document.writeln('<center><br>'+to_html(document.form.text.value)+'</center>');parent.viewer.document.close()" /><br />
<br />
<input type="button" name="submit" value="Insert reaction for part #?" onClick = "submitReaction();" />
<br />
<input type="button" value="  Close  " onClick = "parent.window.close()" />
&nbsp;&nbsp;
<input type="button" value="  Help  " onClick = "openHelpWindow()" />
</form>
</center>
</body>
</html>

Index: loncom/html/res/adm/pages/reactionresponse/reaction_frame.html
+++ loncom/html/res/adm/pages/reactionresponse/reaction_frame.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>LON-CAPA Reaction Editor</title>
</head>
<frameset rows="50,*" border="0>
  <frame name="viewer" scrolling="no" />
  <frame src="reaction_window.html" name="editor" scrolling="no" /> 
</frameset> 
</html>

Index: loncom/html/res/adm/pages/reactionresponse/reaction_help.html
+++ loncom/html/res/adm/pages/reactionresponse/reaction_help.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<!--
$Id: reaction_help.html,v 1.1 2003/06/30 20:39:59 albertel Exp $

Copyright Michigan State University Board of Trustees

This file is part of the LearningOnline Network with CAPA (LON-CAPA).

LON-CAPA is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

LON-CAPA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with LON-CAPA; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

/home/httpd/html/adm/gpl.txt

http://www.lon-capa.org/
-->
<html> <head>
<title>Chemical Reaction Editor Help</title>
</head>

<body>
<h1>Chemical Reaction Editor</h1>
<H3>Description</H3>
<LI>Reactants are separated from products by '->'.
<LI>Individual reactants and products are separated by '&nbsp;&nbsp;+' (leading space is obligatory).
<LI>Numbers preceding the first symbol of a chemical specie are considered to be stoichiometric coefficients.
<LI>Numbers appearing after the first symbol of a chemical specie are considered to be subscripts.
<LI>Superscripts are initialized by '^' and terminated by a space.
<LI>Ionic charges are superscripts composed of a number followed by a sign (i.e. '^2+').
<br><br>
<i>Press the 'Check' button to view your reaction before you submit it!</i>

<H3>Examples</H3>
<LI>Ca(NO<sub>3</sub>)<sub>2</sub> is written as:<br>&nbsp;&nbsp;&nbsp; Ca(NO3)2
<LI>OH<sup>-</sup> + H<sub>3</sub>O<sup>+</sup> <font face=symbol>&reg;</font> 2H<sub>2</sub>O is written as:<br>&nbsp;&nbsp;&nbsp; OH^- + H3O^+ -> 2H2O
<LI>[Co(H<sub>2</sub>O)<sub>6</sub>]<sup>2+</sup> + 4Cl<sup>-</sup> <font face=symbol>&reg;</font> [CoCl<sub>4</sub>]<sup>2-</sup> + 6H<sub>2</sub>O is written as:<br>&nbsp;&nbsp;&nbsp; [Co(H2O)6]^2+ + 4Cl^- -> [CoCl4]^2- + 6H2O
<LI><sup>3</sup><sub>1</sub>H + <sup>2</sup><sub>1</sub>H <font face=symbol>&reg;</font> <sup>4</sup><sub>2</sub>He + <sup>1</sup><sub>0</sub>n is written as:<br>&nbsp;&nbsp;&nbsp; ^3 1H + ^2 1H -> ^4 2He + ^1 0n
<hr>
<center>
<form><input type="button" value="  Close Help  " onClick = "window.close()"></form>
</center>
</body> </html>

Index: loncom/html/res/adm/pages/reactionresponse/reaction_viewer.html
+++ loncom/html/res/adm/pages/reactionresponse/reaction_viewer.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html></html>

Index: loncom/html/res/adm/pages/reactionresponse/reaction_window.html
+++ loncom/html/res/adm/pages/reactionresponse/reaction_window.html
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>LON-CAPA Reaction Editor</title>
</head>
<body>
<frameset rows="30%,*" border="0">
  <frame src="reaction_viewer.html" name="viewer" scrolling="no">
  <frame src="reaction_editor.html" name="editor" scrolling="no"> 
</framset> 
</body>
</html>

--albertel1057005600--