Annotation of loncom/html/res/adm/pages/reactionresponse/reaction_editor.html, revision 1.4
1.1 albertel 1: <!-- Chemical reaction editor developed by Guy Ashkenazi, guy@fh.huji.ac.il-->
2:
3: <!--
1.4 ! albertel 4: $Id: reaction_editor.html,v 1.3 2003/07/01 21:06:37 albertel Exp $
1.1 albertel 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;
1.3 albertel 33: var id;
1.4 ! albertel 34: var reaction;
1.3 albertel 35: var field
1.1 albertel 36: </script>
37: <!-- parsed by LON-CAPA to get the correct symbol for the arrow -->
38: <display>
39: return '<script type="text/javascript">
40: var rightarrow=\''.&xmlparse('<m>$\rightarrow$</m>').'\';
1.4 ! albertel 41: var reaction=\''.&EXT('query.reaction').'\';
1.3 albertel 42: var field=\''.&EXT('query.field').'\';
43: var id=\''.&EXT('query.id').'\';
1.1 albertel 44: </script>';
45: </display>
46: <script language="JavaScript">
47:
48: var level;
49: var reactants;
50: var products;
51:
52:
53: function parse_reaction(string) {
54: var reaction_array = string.split('->');
55: var i;
56: reactants = new Array(0);
57: products = new Array(0);
58:
59: if (reaction_array.length > 0)
60: reactants = reaction_array[0].split(' +');
61: if (reaction_array.length > 1)
62: products = reaction_array[1].split(' +');
63: }
64:
65: function to_capa(string) {
66: var reaction = "";
67: var i;
68:
69: parse_reaction(string);
70:
71: for (i = 0; i < reactants.length; i++)
72: reactants[i] = capa_component(reactants[i]);
73: for (i = 0; i < products.length; i++)
74: products[i] = capa_component(products[i]);
75:
76: reactants.sort();
77: products.sort();
78:
79: for (i = 0; i < reactants.length-1; i++) {
80: reaction += reactants[i];
81: reaction += " + ";
82: }
83: if (i < reactants.length)
84: reaction += reactants[i];
85: if (products.length > 0) {
86: reaction += " -> ";
87: for (i = 0; i < products.length-1; i++) {
88: reaction += products[i];
89: reaction += " + ";
90: }
91: if (i < products.length)
92: reaction += products[i];
93: }
94:
95: return reaction;
96: }
97:
98: function capa_component(string) {
99: var reactant = "";
100: var i = 0;
101: level = 0;
102:
103: for (;string.substring(i,i+1) == ' ';i++)
104: ;
105: for (;isDigit(string.substring(i,i+1));i++)
106: reactant += string.substring(i,i+1);
107: for (;i < string.length;i++)
108: reactant += capa_char(string.substring(i,i+1));
109:
110: return reactant;
111: }
112:
113: function capa_char(chr) {
114: if (level == 0) { // baseline
115: if (chr == '^')
116: level = 1;
117: if (chr == ' ')
118: return "";
119: return chr;
120: }
121: if (level == 1) { // superscript
122: if (isDigit(chr))
123: return chr;
124: level = 0;
125: return chr;
126: }
127: }
128:
129: function to_html(string) {
130: var reaction = "";
131: var i;
132:
133: parse_reaction(string);
134: for (i = 0; i < reactants.length-1; i++) {
135: reaction += html_component(reactants[i]);
136: reaction += " + ";
137: }
138: if (i < reactants.length)
139: reaction += html_component(reactants[i]);
140:
141: if (products.length > 0) {
142: reaction += rightarrow;
143: for (i = 0; i < products.length-1; i++) {
144: reaction += html_component(products[i]);
145: reaction += " + ";
146: }
147: if (i < products.length)
148: reaction += html_component(products[i]);
149: }
150:
151: return reaction;
152: }
153:
154: function html_component(string) {
155: var reactant = "";
156: var i = 0;
157: level = 0;
158:
159: for (;string.substring(i,i+1) == ' ';i++)
160: ;
161: for (;isDigit(string.substring(i,i+1));i++)
162: reactant += string.substring(i,i+1);
163: for (;i < string.length;i++)
164: reactant += html_char(string.substring(i,i+1));
165:
166: return reactant;
167: }
168:
169: function html_char(chr) {
170: if (level == 0) { // baseline
171: if (isDigit(chr))
172: return chr.sub();
173: if (chr == '^') {
174: level = 1;
175: return "";
176: }
177: if (chr == '+') // baseline or superscript
178: return "?";
179: if (chr == ' ')
180: return "";
181: return chr;
182: }
183: if (level == 1) { // superscript
184: if (isDigit(chr))
185: return chr.sup();
186: if (chr == '+' || chr == '-') {
187: level = 0;
188: return chr.sup();
189: }
190: if (chr == ' ') {
191: level = 0;
192: return "";
193: }
194: level = 0;
195: return chr;
196: }
197: }
198:
199: function isDigit(string) {
200: if (string >= '0' && string <='9')
201: return 1;
202: else
203: return 0;
204: }
205:
206: function openHelpWindow() {
207: window.open("reaction_help.html","","scrollbars=yes,resizable=yes,width=550,height=600")
208: }
209:
210: function submitReaction() {
211: reaction = to_capa(document.form.text.value);
212: if (reaction == "") {
213: alert("Nothing to submit");
214: }
215: else {
1.3 albertel 216: name = field;
1.1 albertel 217: i = 0;
218: while (parent.opener.document.lonhomework.elements[i].name != name)
219: i++;
220: parent.opener.document.lonhomework.elements[i].value = reaction;
1.2 albertel 221: // parent.opener.document.lonhomework.submit();
222: parent.window.close();
1.1 albertel 223: }
224: }
225:
1.3 albertel 226: function setup() {
1.4 ! albertel 227: document.form.text.value=reaction;
1.3 albertel 228: if (id != '') {
229: document.form.submit.value='Insert reaction for Part ' + id;
230: parent.document.title='LON-CAPA Part '+id+' - Reaction Editor';
231: } else {
232: document.form.submit.value='Insert reaction';
233: parent.document.title='LON-CAPA - Reaction Editor';
234: }
235: }
236:
1.1 albertel 237: function getCookie(document,name) {
238: var dc = document.cookie;
239: var prefix = name + "=";
240: var begin = dc.indexOf("; " + prefix);
241: if (begin == -1) {
242: begin = dc.indexOf(prefix);
243: if (begin != 0) return null;
244: } else
245: begin += 2;
246: var end = document.cookie.indexOf(";", begin);
247: if (end == -1)
248: end = dc.length;
249: return unescape(dc.substring(begin + prefix.length, end));
250: }
251:
252:
253: </script>
254: </head>
255:
1.3 albertel 256: <body bgcolor="#ffffff" onLoad = "javascript:setup();">
1.1 albertel 257: <center>
258: <hr />
259: <form name="form">
260: <input type="text" size=50 name="text" />
261: <input type="button" value="Check" onClick = "parent.viewer.document.writeln('<center><br>'+to_html(document.form.text.value)+'</center>');parent.viewer.document.close()" /><br />
262: <br />
263: <input type="button" name="submit" value="Insert reaction for part #?" onClick = "submitReaction();" />
264: <br />
265: <input type="button" value=" Close " onClick = "parent.window.close()" />
266:
267: <input type="button" value=" Help " onClick = "openHelpWindow()" />
268: </form>
269: </center>
270: </body>
271: </html>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>