Annotation of loncom/html/res/adm/pages/reactionresponse/reaction_editor.html, revision 1.1
1.1 ! albertel 1: <!-- Chemical reaction editor developed by Guy Ashkenazi, guy@fh.huji.ac.il-->
! 2:
! 3: <!--
! 4: $Id: gplheader.js,v 1.1 2001/11/29 19:06:47 www Exp $
! 5:
! 6: Copyright Michigan State University Board of Trustees
! 7:
! 8: This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 9:
! 10: LON-CAPA is free software; you can redistribute it and/or modify
! 11: it under the terms of the GNU General Public License as published by
! 12: the Free Software Foundation; either version 2 of the License, or
! 13: (at your option) any later version.
! 14:
! 15: LON-CAPA is distributed in the hope that it will be useful,
! 16: but WITHOUT ANY WARRANTY; without even the implied warranty of
! 17: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 18: GNU General Public License for more details.
! 19:
! 20: You should have received a copy of the GNU General Public License
! 21: along with LON-CAPA; if not, write to the Free Software
! 22: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 23:
! 24: /home/httpd/html/adm/gpl.txt
! 25:
! 26: http://www.lon-capa.org/
! 27: -->
! 28:
! 29: <html>
! 30: <head>
! 31: <script type="text/javascript">
! 32: var rightarrow;
! 33: </script>
! 34: <!-- parsed by LON-CAPA to get the correct symbol for the arrow -->
! 35: <display>
! 36: return '<script type="text/javascript">
! 37: var rightarrow=\''.&xmlparse('<m>$\rightarrow$</m>').'\';
! 38: </script>';
! 39: </display>
! 40: <script language="JavaScript">
! 41:
! 42: var level;
! 43: var reactants;
! 44: var products;
! 45:
! 46:
! 47: function parse_reaction(string) {
! 48: var reaction_array = string.split('->');
! 49: var i;
! 50: reactants = new Array(0);
! 51: products = new Array(0);
! 52:
! 53: if (reaction_array.length > 0)
! 54: reactants = reaction_array[0].split(' +');
! 55: if (reaction_array.length > 1)
! 56: products = reaction_array[1].split(' +');
! 57: }
! 58:
! 59: function to_capa(string) {
! 60: var reaction = "";
! 61: var i;
! 62:
! 63: parse_reaction(string);
! 64:
! 65: for (i = 0; i < reactants.length; i++)
! 66: reactants[i] = capa_component(reactants[i]);
! 67: for (i = 0; i < products.length; i++)
! 68: products[i] = capa_component(products[i]);
! 69:
! 70: reactants.sort();
! 71: products.sort();
! 72:
! 73: for (i = 0; i < reactants.length-1; i++) {
! 74: reaction += reactants[i];
! 75: reaction += " + ";
! 76: }
! 77: if (i < reactants.length)
! 78: reaction += reactants[i];
! 79: if (products.length > 0) {
! 80: reaction += " -> ";
! 81: for (i = 0; i < products.length-1; i++) {
! 82: reaction += products[i];
! 83: reaction += " + ";
! 84: }
! 85: if (i < products.length)
! 86: reaction += products[i];
! 87: }
! 88:
! 89: return reaction;
! 90: }
! 91:
! 92: function capa_component(string) {
! 93: var reactant = "";
! 94: var i = 0;
! 95: level = 0;
! 96:
! 97: for (;string.substring(i,i+1) == ' ';i++)
! 98: ;
! 99: for (;isDigit(string.substring(i,i+1));i++)
! 100: reactant += string.substring(i,i+1);
! 101: for (;i < string.length;i++)
! 102: reactant += capa_char(string.substring(i,i+1));
! 103:
! 104: return reactant;
! 105: }
! 106:
! 107: function capa_char(chr) {
! 108: if (level == 0) { // baseline
! 109: if (chr == '^')
! 110: level = 1;
! 111: if (chr == ' ')
! 112: return "";
! 113: return chr;
! 114: }
! 115: if (level == 1) { // superscript
! 116: if (isDigit(chr))
! 117: return chr;
! 118: level = 0;
! 119: return chr;
! 120: }
! 121: }
! 122:
! 123: function to_html(string) {
! 124: var reaction = "";
! 125: var i;
! 126:
! 127: parse_reaction(string);
! 128: for (i = 0; i < reactants.length-1; i++) {
! 129: reaction += html_component(reactants[i]);
! 130: reaction += " + ";
! 131: }
! 132: if (i < reactants.length)
! 133: reaction += html_component(reactants[i]);
! 134:
! 135: if (products.length > 0) {
! 136: reaction += rightarrow;
! 137: for (i = 0; i < products.length-1; i++) {
! 138: reaction += html_component(products[i]);
! 139: reaction += " + ";
! 140: }
! 141: if (i < products.length)
! 142: reaction += html_component(products[i]);
! 143: }
! 144:
! 145: return reaction;
! 146: }
! 147:
! 148: function html_component(string) {
! 149: var reactant = "";
! 150: var i = 0;
! 151: level = 0;
! 152:
! 153: for (;string.substring(i,i+1) == ' ';i++)
! 154: ;
! 155: for (;isDigit(string.substring(i,i+1));i++)
! 156: reactant += string.substring(i,i+1);
! 157: for (;i < string.length;i++)
! 158: reactant += html_char(string.substring(i,i+1));
! 159:
! 160: return reactant;
! 161: }
! 162:
! 163: function html_char(chr) {
! 164: if (level == 0) { // baseline
! 165: if (isDigit(chr))
! 166: return chr.sub();
! 167: if (chr == '^') {
! 168: level = 1;
! 169: return "";
! 170: }
! 171: if (chr == '+') // baseline or superscript
! 172: return "?";
! 173: if (chr == ' ')
! 174: return "";
! 175: return chr;
! 176: }
! 177: if (level == 1) { // superscript
! 178: if (isDigit(chr))
! 179: return chr.sup();
! 180: if (chr == '+' || chr == '-') {
! 181: level = 0;
! 182: return chr.sup();
! 183: }
! 184: if (chr == ' ') {
! 185: level = 0;
! 186: return "";
! 187: }
! 188: level = 0;
! 189: return chr;
! 190: }
! 191: }
! 192:
! 193: function isDigit(string) {
! 194: if (string >= '0' && string <='9')
! 195: return 1;
! 196: else
! 197: return 0;
! 198: }
! 199:
! 200: function openHelpWindow() {
! 201: window.open("reaction_help.html","","scrollbars=yes,resizable=yes,width=550,height=600")
! 202: }
! 203:
! 204: function submitReaction() {
! 205: reaction = to_capa(document.form.text.value);
! 206: if (reaction == "") {
! 207: alert("Nothing to submit");
! 208: }
! 209: else {
! 210: name = "HWVAL_" + problem;
! 211: i = 0;
! 212: while (parent.opener.document.lonhomework.elements[i].name != name)
! 213: i++;
! 214: parent.opener.document.lonhomework.elements[i].value = reaction;
! 215: parent.opener.document.lonhomework.submit();
! 216: }
! 217: }
! 218:
! 219: function getCookie(document,name) {
! 220: var dc = document.cookie;
! 221: var prefix = name + "=";
! 222: var begin = dc.indexOf("; " + prefix);
! 223: if (begin == -1) {
! 224: begin = dc.indexOf(prefix);
! 225: if (begin != 0) return null;
! 226: } else
! 227: begin += 2;
! 228: var end = document.cookie.indexOf(";", begin);
! 229: if (end == -1)
! 230: end = dc.length;
! 231: return unescape(dc.substring(begin + prefix.length, end));
! 232: }
! 233:
! 234:
! 235: </script>
! 236: </head>
! 237:
! 238: <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';">
! 239: <center>
! 240: <hr />
! 241: <form name="form">
! 242: <input type="text" size=50 name="text" />
! 243: <input type="button" value="Check" onClick = "parent.viewer.document.writeln('<center><br>'+to_html(document.form.text.value)+'</center>');parent.viewer.document.close()" /><br />
! 244: <br />
! 245: <input type="button" name="submit" value="Insert reaction for part #?" onClick = "submitReaction();" />
! 246: <br />
! 247: <input type="button" value=" Close " onClick = "parent.window.close()" />
! 248:
! 249: <input type="button" value=" Help " onClick = "openHelpWindow()" />
! 250: </form>
! 251: </center>
! 252: </body>
! 253: </html>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>