Subversion Repositories wimsdev

Rev

Rev 2876 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2876 Rev 2989
Line 1... Line 1...
1
/* Jmol 11.7 script library Jmol.js  12:17 AM 4/20/2009 Bob Hanson
1
/* Jmol 11.9 script library Jmol.js  6:56 AM 1/20/2010 Bob Hanson
2
 
2
 
3
 checkbox heirarchy -- see http://chemapps.stolaf.edu/jmol/docs/examples-11/check.htm
3
 checkbox heirarchy -- see http://chemapps.stolaf.edu/jmol/docs/examples-11/check.htm
4
 
4
 
5
    based on:
5
    based on:
6
 *
6
 *
Line 66... Line 66...
66
// bh 12/2008 -- jmolLoadInline, jmolLoadInlineArray, jmolLoadInlineScript, jmolAppendInlineScript, jmolAppendInlineArray all return error message or null (Jmol 11.7.16)
66
// bh 12/2008 -- jmolLoadInline, jmolLoadInlineArray, jmolLoadInlineScript, jmolAppendInlineScript, jmolAppendInlineArray all return error message or null (Jmol 11.7.16)
67
// bh 12/2008 -- jmolScriptWaitOutput() -- waits for script to complete and delivers output normally sent to console
67
// bh 12/2008 -- jmolScriptWaitOutput() -- waits for script to complete and delivers output normally sent to console
68
 
68
 
69
// bh 5/2009  -- Support for XHTML using jmolSetXHTML(id)
69
// bh 5/2009  -- Support for XHTML using jmolSetXHTML(id)
70
// ah & bh 6/2009 -- New jmolResizeApplet() more flexible, similar to jmolApplet() size syntax
70
// ah & bh 6/2009 -- New jmolResizeApplet() more flexible, similar to jmolApplet() size syntax
-
 
71
// bh 11/2009 -- care in accessing top.document
-
 
72
// bh 12/2009 -- added jmolSetParameter(name, value)
-
 
73
// bh 12/2009 -- added PARAMS=name:value;name:value;name:value... for command line
-
 
74
// bh 12/2009 -- overhaul of target checking
-
 
75
// bh 1/2010  -- all _xxxx() methods ALWAYS have complete argument list
-
 
76
// bh 1/2010  -- adds option to run a JavaScript function from any Jmol control. 
-
 
77
//               This is accomplished by passing an array rather than a script:
-
 
78
//               jmolHref([myfunc,"my param 1", "my param 2"], "testing")
-
 
79
//               function myfunc(jmolControlObject, [myfunc,"my param 1", "my param 2"], target){...}
-
 
80
//               and allows much more flexibility with responding to controls
71
 
81
 
72
var defaultdir = "."
82
var defaultdir = "."
73
var defaultjar = "JmolApplet.jar"
83
var defaultjar = "JmolApplet.jar"
74
 
84
 
75
 
85
 
Line 87... Line 97...
87
// The default action, if the user just presses "OK" is to NOT allow the change. 
97
// The default action, if the user just presses "OK" is to NOT allow the change. 
88
// The user must type the word "yes" in the prompt box for the change to be approved.
98
// The user must type the word "yes" in the prompt box for the change to be approved.
89
 
99
 
90
// If you don't want people to be able to switch in their own JAR file on your page,
100
// If you don't want people to be able to switch in their own JAR file on your page,
91
// simply set this next line to read "var allowJMOLJAR = false".
101
// simply set this next line to read "var allowJMOLJAR = false".
92
 
-
 
93
 
-
 
94
var allowJMOLJAR = true  
-
 
95
 
102
 
96
 
103
 
97
var undefined; // for IE 5 ... wherein undefined is undefined
104
var undefined; // for IE 5 ... wherein undefined is undefined
98
 
105
 
99
////////////////////////////////////////////////////////////////
106
////////////////////////////////////////////////////////////////
Line 102... Line 109...
102
 
109
 
103
function jmolInitialize(codebaseDirectory, fileNameOrUseSignedApplet) {
110
function jmolInitialize(codebaseDirectory, fileNameOrUseSignedApplet) {
104
  if (_jmol.initialized)
111
  if (_jmol.initialized)
105
    return;
112
    return;
106
  _jmol.initialized = true;
113
  _jmol.initialized = true;
107
  if(allowJMOLJAR && document.location.search.indexOf("JMOLJAR=")>=0) {
114
  if(_jmol.jmoljar) {
108
    var f = document.location.search.split("JMOLJAR=")[1].split("&")[0];
115
    var f = _jmol.jmoljar;
109
    if (f.indexOf("/") >= 0) {
116
    if (f.indexOf("/") >= 0) {
110
      alert ("This web page URL is requesting that the applet used be " + f + ". This is a possible security risk, particularly if the applet is signed, because signed applets can read and write files on your local machine or network.")
117
      alert ("This web page URL is requesting that the applet used be " + f + ". This is a possible security risk, particularly if the applet is signed, because signed applets can read and write files on your local machine or network.")
111
      var ok = prompt("Do you want to use applet " + f + "? ","yes or no")
118
      var ok = prompt("Do you want to use applet " + f + "? ","yes or no")
112
      if (ok == "yes") {
119
      if (ok == "yes") {
113
        codebaseDirectory = f.substring(0, f.lastIndexOf("/"));
120
        codebaseDirectory = f.substring(0, f.lastIndexOf("/"));
Line 121... Line 128...
121
    }
128
    }
122
  }
129
  }
123
  _jmolSetCodebase(codebaseDirectory);
130
  _jmolSetCodebase(codebaseDirectory);
124
  _jmolGetJarFilename(fileNameOrUseSignedApplet);
131
  _jmolGetJarFilename(fileNameOrUseSignedApplet);
125
  _jmolOnloadResetForms();
132
  _jmolOnloadResetForms();
126
}
133
}
127
 
134
 
128
function jmolSetTranslation(TF) {
135
function jmolSetTranslation(TF) {
129
  _jmol.params.doTranslate = ''+TF;
136
  _jmol.params.doTranslate = ''+TF;
130
}
137
}
131
 
138
 
132
function _jmolGetJarFilename(fileNameOrFlag) {
139
function _jmolGetJarFilename(fileNameOrFlag) {
133
  _jmol.archivePath =
140
  _jmol.archivePath =
134
    (typeof(fileNameOrFlag) == "string"  ? fileNameOrFlag : (fileNameOrFlag ?  "JmolAppletSigned" : "JmolApplet") + "0.jar");
141
    (typeof(fileNameOrFlag) == "string"  ? fileNameOrFlag : (fileNameOrFlag ?  "JmolAppletSigned" : "JmolApplet") + "0.jar");
135
}
142
}
136
 
143
 
137
function jmolSetDocument(doc) {
144
function jmolSetDocument(doc) {
138
  _jmol.currentDocument = doc;
145
  _jmol.currentDocument = doc;
139
}
146
}
140
 
147
 
141
function jmolSetAppletColor(boxbgcolor, boxfgcolor, progresscolor) {
148
function jmolSetAppletColor(boxbgcolor, boxfgcolor, progresscolor) {
142
  _jmolInitCheck();
149
  _jmolInitCheck();
143
  _jmol.params.boxbgcolor = boxbgcolor;
150
  _jmol.params.boxbgcolor = boxbgcolor;
144
  if (boxfgcolor)
151
  if (boxfgcolor)
145
    _jmol.params.boxfgcolor = boxfgcolor
152
    _jmol.params.boxfgcolor = boxfgcolor
Line 160... Line 167...
160
}
167
}
161
 
168
 
162
function jmolApplet(size, script, nameSuffix) {
169
function jmolApplet(size, script, nameSuffix) {
163
  _jmolInitCheck();
170
  _jmolInitCheck();
164
  return _jmolApplet(size, null, script, nameSuffix);
171
  return _jmolApplet(size, null, script, nameSuffix);
165
}
172
}
166
 
173
 
167
////////////////////////////////////////////////////////////////
174
////////////////////////////////////////////////////////////////
168
// Basic controls
175
// Basic controls
169
////////////////////////////////////////////////////////////////
176
////////////////////////////////////////////////////////////////
-
 
177
 
-
 
178
// undefined means it wasn't there; null means it was explicitly listed as null (so as to skip it)
170
 
179
 
171
function jmolButton(script, label, id, title) {
180
function jmolButton(script, label, id, title) {
172
  _jmolInitCheck();
181
  _jmolInitCheck();
173
  if (id == undefined || id == null)
-
 
174
    id = "jmolButton" + _jmol.buttonCount;
182
  id != undefined && id != null || (id = "jmolButton" + _jmol.buttonCount);
175
  if (label == undefined || label == null)
-
 
176
    label = script.substring(0, 32);
183
  label != undefined && label != null || (label = script.substring(0, 32));
177
  ++_jmol.buttonCount;
184
  ++_jmol.buttonCount;
178
  var scriptIndex = _jmolAddScript(script);
185
  var scriptIndex = _jmolAddScript(script);
179
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input type='button' name='" + id + "' id='" + id +
186
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input type='button' name='" + id + "' id='" + id +
180
          "' value='" + label +
187
          "' value='" + label +
181
          "' onclick='_jmolClick(" + scriptIndex + _jmol.targetText +
188
          "' onclick='_jmolClick(this," + scriptIndex + _jmol.targetText +
182
          ")' onmouseover='_jmolMouseOver(" + scriptIndex +
189
          ")' onmouseover='_jmolMouseOver(" + scriptIndex +
183
          ");return true' onmouseout='_jmolMouseOut()' " +
190
          ");return true' onmouseout='_jmolMouseOut()' " +
184
          _jmol.buttonCssText + " /></span>";
191
          _jmol.buttonCssText + " /></span>";
185
  if (_jmol.debugAlert)
192
  if (_jmol.debugAlert)
186
    alert(t);
193
    alert(t);
Line 188... Line 195...
188
}
195
}
189
 
196
 
190
function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked,
197
function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked,
191
                      labelHtml, isChecked, id, title) {
198
                      labelHtml, isChecked, id, title) {
192
  _jmolInitCheck();
199
  _jmolInitCheck();
193
  if (id == undefined || id == null)
-
 
194
    id = "jmolCheckbox" + _jmol.checkboxCount;
200
  id != undefined && id != null || (id = "jmolCheckbox" + _jmol.checkboxCount);
195
  ++_jmol.checkboxCount;
201
  ++_jmol.checkboxCount;
196
  if (scriptWhenChecked == undefined || scriptWhenChecked == null ||
202
  if (scriptWhenChecked == undefined || scriptWhenChecked == null ||
197
      scriptWhenUnchecked == undefined || scriptWhenUnchecked == null) {
203
      scriptWhenUnchecked == undefined || scriptWhenUnchecked == null) {
198
    alert("jmolCheckbox requires two scripts");
204
    alert("jmolCheckbox requires two scripts");
199
    return;
205
    return;
Line 210... Line 216...
210
          indexChecked + "," + indexUnchecked + _jmol.targetText +
216
          indexChecked + "," + indexUnchecked + _jmol.targetText +
211
          ")' onmouseover='_jmolCbOver(this," + indexChecked + "," +
217
          ")' onmouseover='_jmolCbOver(this," + indexChecked + "," +
212
          indexUnchecked +
218
          indexUnchecked +
213
          ");return true' onmouseout='_jmolMouseOut()' " +
219
          ");return true' onmouseout='_jmolMouseOut()' " +
214
          (isChecked ? "checked='true' " : "")+ _jmol.checkboxCssText + " />"
220
          (isChecked ? "checked='true' " : "")+ _jmol.checkboxCssText + " />"
215
  if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
221
  if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
216
        t += eospan
222
        t += eospan
217
        eospan = "";
223
        eospan = "";
218
  }
224
  }
219
  t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan;
225
  t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan;
220
  if (_jmol.debugAlert)
226
  if (_jmol.debugAlert)
221
    alert(t);
227
    alert(t);
222
  return _jmolDocumentWrite(t);
228
  return _jmolDocumentWrite(t);
223
}
229
}
224
 
230
 
225
function jmolStartNewRadioGroup() {
231
function jmolStartNewRadioGroup() {
226
  ++_jmol.radioGroupCount;
232
  ++_jmol.radioGroupCount;
227
}
233
}
228
 
234
 
229
function jmolRadioGroup(arrayOfRadioButtons, separatorHtml, groupName, id, title) {
235
function jmolRadioGroup(arrayOfRadioButtons, separatorHtml, groupName, id, title) {
230
  /*
236
  /*
231
 
237
 
232
    array: [radio1,radio2,radio3...]
238
    array: [radio1,radio2,radio3...]
Line 238... Line 244...
238
  var type = typeof arrayOfRadioButtons;
244
  var type = typeof arrayOfRadioButtons;
239
  if (type != "object" || type == null || ! arrayOfRadioButtons.length) {
245
  if (type != "object" || type == null || ! arrayOfRadioButtons.length) {
240
    alert("invalid arrayOfRadioButtons");
246
    alert("invalid arrayOfRadioButtons");
241
    return;
247
    return;
242
  }
248
  }
243
  if (separatorHtml == undefined || separatorHtml == null)
249
  separatorHtml != undefined && separatorHtml != null || (separatorHtml = "&nbsp; ");
244
    separatorHtml = "&nbsp; ";
-
 
245
  var len = arrayOfRadioButtons.length;
250
  var len = arrayOfRadioButtons.length;
246
  jmolStartNewRadioGroup();
251
  jmolStartNewRadioGroup();
247
  if (!groupName)
-
 
248
    groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1);
252
  groupName || (groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1));
249
  var t = "<span id='"+(id ? id : groupName)+"'>";
253
  var t = "<span id='"+(id ? id : groupName)+"'>";
250
  for (var i = 0; i < len; ++i) {
254
  for (var i = 0; i < len; ++i) {
251
    if (i == len - 1)
255
    if (i == len - 1)
252
      separatorHtml = "";
256
      separatorHtml = "";
253
    var radio = arrayOfRadioButtons[i];
257
    var radio = arrayOfRadioButtons[i];
Line 257... Line 261...
257
    } else {
261
    } else {
258
      t += _jmolRadio(radio, null, null, separatorHtml, groupName, (id ? id : groupName)+"_"+i, title);
262
      t += _jmolRadio(radio, null, null, separatorHtml, groupName, (id ? id : groupName)+"_"+i, title);
259
    }
263
    }
260
  }
264
  }
261
  t+="</span>"
265
  t+="</span>"
262
  if (_jmol.debugAlert)
266
  if (_jmol.debugAlert)
263
    alert(t);
267
    alert(t);
264
  return _jmolDocumentWrite(t);
268
  return _jmolDocumentWrite(t);
265
}
269
}
266
 
270
 
267
 
271
 
268
function jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
272
function jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
269
  _jmolInitCheck();
273
  _jmolInitCheck();
270
  if (_jmol.radioGroupCount == 0)
274
  if (_jmol.radioGroupCount == 0)
271
    ++_jmol.radioGroupCount;
275
    ++_jmol.radioGroupCount;
272
  var t = _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, (id ? id : groupName + "_" + _jmol.radioCount), title ? title : 0);
276
  var t = _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, (id ? id : groupName + "_" + _jmol.radioCount), title ? title : 0);
273
  if (_jmol.debugAlert)
277
  if (_jmol.debugAlert)
274
    alert(t);
278
    alert(t);
275
  return _jmolDocumentWrite(t);
279
  return _jmolDocumentWrite(t);
276
}
280
}
277
 
281
 
278
function jmolLink(script, label, id, title) {
282
function jmolLink(script, label, id, title) {
279
  _jmolInitCheck();
283
  _jmolInitCheck();
280
  if (id == undefined || id == null)
-
 
281
    id = "jmolLink" + _jmol.linkCount;
284
  id != undefined && id != null || (id = "jmolLink" + _jmol.linkCount);
282
  if (label == undefined || label == null)
-
 
283
    label = script.substring(0, 32);
285
  label != undefined && label != null || (label = script.substring(0, 32));
284
  ++_jmol.linkCount;
286
  ++_jmol.linkCount;
285
  var scriptIndex = _jmolAddScript(script);
287
  var scriptIndex = _jmolAddScript(script);
286
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><a name='" + id + "' id='" + id +
288
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><a name='" + id + "' id='" + id +
287
          "' href='javascript:_jmolClick(" + scriptIndex + _jmol.targetText + ");' onmouseover='_jmolMouseOver(" + scriptIndex +
289
          "' href='javascript:_jmolClick(this," + scriptIndex + _jmol.targetText + ");' onmouseover='_jmolMouseOver(" + scriptIndex +
288
          ");return true;' onmouseout='_jmolMouseOut()' " +
290
          ");return true;' onmouseout='_jmolMouseOut()' " +
289
          _jmol.linkCssText + ">" + label + "</a></span>";
291
          _jmol.linkCssText + ">" + label + "</a></span>";
290
  if (_jmol.debugAlert)
292
  if (_jmol.debugAlert)
291
    alert(t);
293
    alert(t);
292
  return _jmolDocumentWrite(t);
294
  return _jmolDocumentWrite(t);
293
}
295
}
294
 
296
 
295
function jmolCommandInput(label, size, id, title) {
297
function jmolCommandInput(label, size, id, title) {
296
  _jmolInitCheck();
298
  _jmolInitCheck();
297
  if (id == undefined || id == null)
-
 
298
    id = "jmolCmd" + _jmol.cmdCount;
299
  id != undefined && id != null || (id = "jmolCmd" + _jmol.cmdCount);
299
  if (label == undefined || label == null)
300
  label != undefined && label != null || (label = "Execute");
300
    label = "Execute";
-
 
301
  if (size == undefined || isNaN(size))
301
  size != undefined && !isNaN(size) || (size = 60);
302
    size = 60;
-
 
303
  ++_jmol.cmdCount;
302
  ++_jmol.cmdCount;
304
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='" + id + "' id='" + id +
303
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='" + id + "' id='" + id +
305
          "' size='"+size+"' onkeypress='_jmolCommandKeyPress(event,\""+id+"\"" + _jmol.targetText + ")'><input type=button value = '"+label+"' onclick='jmolScript(document.getElementById(\""+id+"\").value" + _jmol.targetText + ")' /></span>";
304
          "' size='"+size+"' onkeypress='_jmolCommandKeyPress(event,\""+id+"\"" + _jmol.targetText + ")'><input type=button value = '"+label+"' onclick='jmolScript(document.getElementById(\""+id+"\").value" + _jmol.targetText + ")' /></span>";
306
  if (_jmol.debugAlert)
305
  if (_jmol.debugAlert)
307
    alert(t);
306
    alert(t);
Line 309... Line 308...
309
}
308
}
310
 
309
 
311
function _jmolCommandKeyPress(e, id, target) {
310
function _jmolCommandKeyPress(e, id, target) {
312
        var keycode = (window.event ? window.event.keyCode : e ? e.which : 0);
311
        var keycode = (window.event ? window.event.keyCode : e ? e.which : 0);
313
        if (keycode == 13) {
312
        if (keycode == 13) {
-
 
313
                var inputBox = document.getElementById(id)
314
                jmolScript(document.getElementById(id).value, target)
314
                _jmolScriptExecute(inputBox, inputBox.value, target)
315
        }
315
        }
316
}
316
}
317
 
317
 
-
 
318
function _jmolScriptExecute(element,script,target) {
-
 
319
        if (typeof(script) == "object")
-
 
320
                script[0](element, script, target)
-
 
321
        else
-
 
322
                jmolScript(script, target)
318
 
323
}
319
 
324
 
320
function jmolMenu(arrayOfMenuItems, size, id, title) {
325
function jmolMenu(arrayOfMenuItems, size, id, title) {
321
  _jmolInitCheck();
326
  _jmolInitCheck();
322
  if (id == undefined || id == null)
-
 
323
    id = "jmolMenu" + _jmol.menuCount;
327
  id != undefined && id != null || (id = "jmolMenu" + _jmol.menuCount);
324
  ++_jmol.menuCount;
328
  ++_jmol.menuCount;
325
  var type = typeof arrayOfMenuItems;
329
  var type = typeof arrayOfMenuItems;
326
  if (type != null && type == "object" && arrayOfMenuItems.length) {
330
  if (type != null && type == "object" && arrayOfMenuItems.length) {
327
    var len = arrayOfMenuItems.length;
331
    var len = arrayOfMenuItems.length;
328
    if (typeof size != "number" || size == 1)
332
    if (typeof size != "number" || size == 1)
Line 343... Line 347...
343
        text = menuItem[1];
347
        text = menuItem[1];
344
        isSelected = menuItem[2];
348
        isSelected = menuItem[2];
345
      } else {
349
      } else {
346
        script = text = menuItem;
350
        script = text = menuItem;
347
      }
351
      }
348
      if (text == undefined || text == null)
352
      text != undefined && text != null || (text = script);            
349
        text = script;         
-
 
350
          if (script=="#optgroup") {
353
      if (script=="#optgroup") {
351
        t += "<optgroup label='" + text + "'>";  
354
        t += "<optgroup label='" + text + "'>";  
352
          } else if (script=="#optgroupEnd") {
355
          } else if (script=="#optgroupEnd") {
353
        t += "</optgroup>";      
356
        t += "</optgroup>";      
354
          } else {             
357
          } else {             
355
        var scriptIndex = _jmolAddScript(script);
358
        var scriptIndex = _jmolAddScript(script);
356
        var selectedText = isSelected ? "' selected='true'>" : "'>";
359
        var selectedText = isSelected ? "' selected='true'>" : "'>";
357
        t += "<option value='" + scriptIndex + selectedText + text + "</option>";
360
        t += "<option value='" + scriptIndex + selectedText + text + "</option>";
358
          }
361
      }
359
    }
362
    }
360
    t += "</select></span>";
363
    t += "</select></span>";
361
    if (_jmol.debugAlert)
364
    if (_jmol.debugAlert)
362
      alert(t);
365
      alert(t);
363
    return _jmolDocumentWrite(t);
366
    return _jmolDocumentWrite(t);
Line 386... Line 389...
386
                     script, nameSuffix);
389
                     script, nameSuffix);
387
}
390
}
388
 
391
 
389
function jmolSetTarget(targetSuffix) {
392
function jmolSetTarget(targetSuffix) {
390
  _jmol.targetSuffix = targetSuffix;
393
  _jmol.targetSuffix = targetSuffix;
391
  _jmol.targetText = targetSuffix ? ",\"" + targetSuffix + "\"" : "";
394
  _jmol.targetText = targetSuffix ? ",\"" + targetSuffix + "\"" : ",0";
392
}
395
}
393
 
396
 
394
function jmolScript(script, targetSuffix) {
397
function jmolScript(script, targetSuffix) {
395
  if (script) {
398
  if (script) {
396
    _jmolCheckBrowser();
399
    _jmolCheckBrowser();
Line 427... Line 430...
427
}
430
}
428
 
431
 
429
 
432
 
430
function jmolLoadInlineArray(ModelArray, script, targetSuffix) {
433
function jmolLoadInlineArray(ModelArray, script, targetSuffix) {
431
  if (!model)return "ERROR: NO MODEL"
434
  if (!model)return "ERROR: NO MODEL"
432
  if (!script)script=""
435
  script || (script="")
433
  var applet=_jmolGetApplet(targetSuffix);
436
  var applet=_jmolGetApplet(targetSuffix);
434
  if (!applet)return "ERROR: NO APPLET"
437
  if (!applet)return "ERROR: NO APPLET"
435
  try {
438
  try {
436
    return applet.loadInlineArray(ModelArray, script, false);
439
    return applet.loadInlineArray(ModelArray, script, false);
437
  } catch (err) {
440
  } catch (err) {
Line 440... Line 443...
440
  }
443
  }
441
}
444
}
442
 
445
 
443
function jmolAppendInlineArray(ModelArray, script, targetSuffix) {
446
function jmolAppendInlineArray(ModelArray, script, targetSuffix) {
444
  if (!model)return "ERROR: NO MODEL"
447
  if (!model)return "ERROR: NO MODEL"
445
  if (!script)script=""
448
  script || (script="")
446
  var applet=_jmolGetApplet(targetSuffix);
449
  var applet=_jmolGetApplet(targetSuffix);
447
  if (!applet)return "ERROR: NO APPLET"
450
  if (!applet)return "ERROR: NO APPLET"
448
  try {
451
  try {
449
    return applet.loadInlineArray(ModelArray, script, true);
452
    return applet.loadInlineArray(ModelArray, script, true);
450
  } catch (err) {
453
  } catch (err) {
Line 461... Line 464...
461
}
464
}
462
 
465
 
463
function jmolCheckBrowser(action, urlOrMessage, nowOrLater) {
466
function jmolCheckBrowser(action, urlOrMessage, nowOrLater) {
464
  if (typeof action == "string") {
467
  if (typeof action == "string") {
465
    action = action.toLowerCase();
468
    action = action.toLowerCase();
466
    if (action != "alert" && action != "redirect" && action != "popup")
469
    action == "alert" || action == "redirect" || action == "popup" || (action = null);
467
      action = null;
-
 
468
  }
470
  }
469
  if (typeof action != "string")
471
  if (typeof action != "string")
470
    alert("jmolCheckBrowser(action, urlOrMessage, nowOrLater)\n\n" +
472
    alert("jmolCheckBrowser(action, urlOrMessage, nowOrLater)\n\n" +
471
          "action must be 'alert', 'redirect', or 'popup'");
473
          "action must be 'alert', 'redirect', or 'popup'");
472
  else {
474
  else {
Line 568... Line 570...
568
  linkCssText: "",
570
  linkCssText: "",
569
  menuCssClass: null,
571
  menuCssClass: null,
570
  menuCssText: "",
572
  menuCssText: "",
571
 
573
 
572
  targetSuffix: 0,
574
  targetSuffix: 0,
573
  targetText: "",
575
  targetText: ",0",
574
  scripts: [""],
576
  scripts: [""],
575
  params: {
577
  params: {
576
        syncId: ("" + Math.random()).substring(3),
578
        syncId: ("" + Math.random()).substring(3),
577
        progressbar: "true",
579
        progressbar: "true",
578
        progresscolor: "blue",
580
        progresscolor: "blue",
Line 609... Line 611...
609
  checkBrowserUrlOrMessage: null,
611
  checkBrowserUrlOrMessage: null,
610
 
612
 
611
  archivePath: null, // JmolApplet0.jar OR JmolAppletSigned0.jar
613
  archivePath: null, // JmolApplet0.jar OR JmolAppletSigned0.jar
612
 
614
 
613
  previousOnloadHandler: null,
615
  previousOnloadHandler: null,
-
 
616
 
-
 
617
  jmoljar: null,  
-
 
618
  useNoApplet: false,
-
 
619
 
614
  ready: {}
620
  ready: {}
615
}
621
}
616
 
622
 
617
with (_jmol) {
623
with (_jmol) {
618
  function _jmolTestUA(candidate) {
624
  function _jmolTestUA(candidate) {
Line 646... Line 652...
646
  _jmolTestOS("mac") ||
652
  _jmolTestOS("mac") ||
647
  _jmolTestOS("win");
653
  _jmolTestOS("win");
648
 
654
 
649
  isNetscape47Win = (os == "win" && browser == "mozilla" &&
655
  isNetscape47Win = (os == "win" && browser == "mozilla" &&
650
                     browserVersion >= 4.78 && browserVersion <= 4.8);
656
                     browserVersion >= 4.78 && browserVersion <= 4.8);
651
 
657
 
652
  if (os == "win") {
658
  if (os == "win") {
653
    isBrowserCompliant = hasGetElementById;
659
    isBrowserCompliant = hasGetElementById;
654
  } else if (os == "mac") { // mac is the problem child :-(
660
  } else if (os == "mac") { // mac is the problem child :-(
655
    if (browser == "mozilla" && browserVersion >= 5) {
661
    if (browser == "mozilla" && browserVersion >= 5) {
656
      // miguel 2004 11 17
662
      // miguel 2004 11 17
Line 676... Line 682...
676
    isBrowserCompliant = hasGetElementById;
682
    isBrowserCompliant = hasGetElementById;
677
  }
683
  }
678
 
684
 
679
  // possibly more checks in the future for this
685
  // possibly more checks in the future for this
680
  isJavaCompliant = isJavaEnabled;
686
  isJavaCompliant = isJavaEnabled;
681
 
687
 
682
  isFullyCompliant = isBrowserCompliant && isJavaCompliant;
688
  isFullyCompliant = isBrowserCompliant && isJavaCompliant;
683
 
689
 
684
  // IE5.5 works just fine ... but let's push them to Sun Java
690
  // IE5.5 works just fine ... but let's push them to Sun Java
685
  isIEWin = (os == "win" && browser == "msie" && browserVersion >= 5.5);
691
  isIEWin = (os == "win" && browser == "msie" && browserVersion >= 5.5);
686
  useIEObject = isIEWin;
692
  useIEObject = isIEWin;
687
  useHtml4Object =
693
  useHtml4Object =
688
   (os != "mac" && browser == "mozilla" && browserVersion >= 5) ||
694
   (os != "mac" && browser == "mozilla" && browserVersion >= 5) ||
689
   (os == "win" && browser == "opera" && browserVersion >= 8) ||
695
   (os == "win" && browser == "opera" && browserVersion >= 8) ||
690
   (os == "mac" && browser == "safari" && browserVersion >= 412.2);
696
   (os == "mac" && browser == "safari" && browserVersion >= 412.2);
-
 
697
 try {
-
 
698
  if (top.location.search.indexOf("JMOLJAR=")>=0)
-
 
699
    jmoljar = top.location.search.split("JMOLJAR=")[1].split("&")[0];
-
 
700
 } catch(e) {
-
 
701
  // can't access top.location
691
 
702
 }
-
 
703
 try {
-
 
704
  useNoApplet = (top.location.search.indexOf("NOAPPLET")>=0);
692
 doTranslate = true;
705
 } catch(e) {
693
 haveSetTranslate = false;
706
  // can't access top.document
-
 
707
 }
694
}
708
}
695
 
709
 
-
 
710
function jmolSetParameter(name,value) {
-
 
711
  _jmol.params[name] = value
-
 
712
}
696
 
713
 
697
function jmolSetCallback(callbackName,funcName) {
714
function jmolSetCallback(callbackName,funcName) {
698
  _jmol.params[callbackName] = funcName
715
  _jmol.params[callbackName] = funcName
699
}
716
}
-
 
717
 
-
 
718
 try {
-
 
719
// note this is done FIRST, so it cannot override a setting done by the developer
-
 
720
  if (top.location.search.indexOf("PARAMS=")>=0) {
-
 
721
    var pars = unescape(top.location.search.split("PARAMS=")[1].split("&")[0]).split(";");
-
 
722
    for (var i = 0; i < pars.length; i++) {
-
 
723
      var p = pars[i].split(":");
-
 
724
      jmolSetParameter(p[0],p[1]);
-
 
725
    }
-
 
726
  }
-
 
727
 } catch(e) {
-
 
728
  // can't access top.location
-
 
729
 }
700
 
730
 
701
function jmolSetSyncId(n) {
731
function jmolSetSyncId(n) {
702
  return _jmol.params["syncId"] = n
732
  return _jmol.params["syncId"] = n
703
}
733
}
704
 
734
 
Line 724... Line 754...
724
        "installed for applet support.<br />\n" +
754
        "installed for applet support.<br />\n" +
725
        "Visit <a href='http://www.java.com'>www.java.com</a>";
755
        "Visit <a href='http://www.java.com'>www.java.com</a>";
726
function _jmolApplet(size, inlineModel, script, nameSuffix) {
756
function _jmolApplet(size, inlineModel, script, nameSuffix) {
727
        /*  AngelH, mar2007
757
        /*  AngelH, mar2007
728
                Fixed percent / pixel business, to avoid browser errors:
758
                Fixed percent / pixel business, to avoid browser errors:
729
                put "px" where needed, avoid where not.        
759
                put "px" where needed, avoid where not.
-
 
760
 
-
 
761
            Bob Hanson, 1/2010
-
 
762
                Fixed inline escape changing returns to |              
730
        */
763
        */
731
  with (_jmol) {
764
  with (_jmol) {
732
    if (! nameSuffix)
-
 
733
      nameSuffix = appletCount;
765
    nameSuffix == undefined && (nameSuffix = appletCount);
734
    appletSuffixes.push(nameSuffix);
766
    appletSuffixes.push(nameSuffix);
735
    ++appletCount;
767
    ++appletCount;
736
    if (! script)
-
 
737
      script = "select *";
768
    script || (script = "select *");
738
    var sz = _jmolGetAppletSize(size);
769
    var sz = _jmolGetAppletSize(size);
739
    var widthAndHeight = " width='" + sz[0] + "' height='" + sz[1] + "' ";
770
    var widthAndHeight = " width='" + sz[0] + "' height='" + sz[1] + "' ";
740
    var tHeader, tFooter;
771
    var tHeader, tFooter;
741
    if (!codebase)
-
 
742
        jmolInitialize(".");
772
    codebase || jmolInitialize(".");
743
    if (useIEObject || useHtml4Object) {
773
    if (useIEObject || useHtml4Object) {
744
      params.name = 'jmolApplet' + nameSuffix;
774
      params.name = 'jmolApplet' + nameSuffix;
745
      params.archive = archivePath;
775
      params.archive = archivePath;
746
      params.mayscript = 'true';
776
      params.mayscript = 'true';
747
      params.codebase = codebase;
777
      params.codebase = codebase;
Line 753... Line 783...
753
        "<object name='jmolApplet" + nameSuffix +
783
        "<object name='jmolApplet" + nameSuffix +
754
        "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +
784
        "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +
755
        " classid='" + windowsClassId + "'\n" + winCodebase + widthAndHeight + ">\n";
785
        " classid='" + windowsClassId + "'\n" + winCodebase + widthAndHeight + ">\n";
756
      tFooter = "</object>";
786
      tFooter = "</object>";
757
    } else if (useHtml4Object) { // use HTML4 object tag
787
    } else if (useHtml4Object) { // use HTML4 object tag
758
      tHeader =
788
      tHeader =
759
        "<object name='jmolApplet" + nameSuffix +
789
        "<object name='jmolApplet" + nameSuffix +
760
        "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +
790
        "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +
761
        " classid='java:JmolApplet'\n" +
791
        " classid='java:JmolApplet'\n" +
762
        " type='application/x-java-applet'\n" +
792
        " type='application/x-java-applet'\n" +
763
        widthAndHeight + ">\n";
793
        widthAndHeight + ">\n";
Line 808... Line 838...
808
 var t = "";
838
 var t = "";
809
 for (var i in _jmol.params)
839
 for (var i in _jmol.params)
810
        if(_jmol.params[i]!="")
840
        if(_jmol.params[i]!="")
811
                 t+="  <param name='"+i+"' value='"+_jmol.params[i]+"' />\n";
841
                 t+="  <param name='"+i+"' value='"+_jmol.params[i]+"' />\n";
812
 return t
842
 return t
813
}
843
}
814
 
844
 
815
function _jmolInitCheck() {
845
function _jmolInitCheck() {
816
  if (_jmol.initChecked)
846
  if (_jmol.initChecked)
817
    return;
847
    return;
818
  _jmol.initChecked = true;
848
  _jmol.initChecked = true;
819
  jmolInitialize(defaultdir, defaultjar)
849
  jmolInitialize(defaultdir, defaultjar)
Line 893... Line 923...
893
        Ptr[0] = data.length
923
        Ptr[0] = data.length
894
        return e
924
        return e
895
 
925
 
896
//unnecessary?
926
//unnecessary?
897
 
927
 
898
        if (!closetag)closetag = ""
928
        closetag || (closetag = "")
899
        if (!lvel) lvel = 0
929
        lvel || (lvel = 0)
900
        var pt0 = Ptr[0]
930
        var pt0 = Ptr[0]
901
        var pt = pt0
931
        var pt = pt0
902
        while (pt < data.length && data.charAt(pt) != "<") pt++
932
        while (pt < data.length && data.charAt(pt) != "<") pt++
903
        if (pt != pt0) {
933
        if (pt != pt0) {
904
                var text = data.substring(pt0, pt)
934
                var text = data.substring(pt0, pt)
Line 960... Line 990...
960
    alert(name + " is ready");
990
    alert(name + " is ready");
961
  _jmol.ready["" + name] = true;
991
  _jmol.ready["" + name] = true;
962
}
992
}
963
 
993
 
964
function _jmolSterilizeScript(script) {
994
function _jmolSterilizeScript(script) {
965
  var inlineScript = script.replace(/'/g, "&#39;");
995
  script = script.replace(/'/g, "&#39;");
966
  if (_jmol.debugAlert)
996
  if (_jmol.debugAlert)
967
    alert("script:\n" + inlineScript);
997
    alert("script:\n" + script);
968
  return inlineScript;
998
  return script;
969
}
999
}
970
 
1000
 
971
function _jmolSterilizeInline(model) {
1001
function _jmolSterilizeInline(model) {
972
  var inlineModel =
-
 
973
    model.replace(/\r|\n|\r\n/g, "|").replace(/'/g, "&#39;");
1002
  model = model.replace(/\r|\n|\r\n/g, (model.indexOf("|") >= 0 ? "\\/n" : "|")).replace(/'/g, "&#39;");
974
  if (_jmol.debugAlert)
1003
  if (_jmol.debugAlert)
975
    alert("inline model:\n" + inlineModel);
1004
    alert("inline model:\n" + model);
976
  return inlineModel;
1005
  return model;
977
}
1006
}
978
 
1007
 
979
function _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
1008
function _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
980
  ++_jmol.radioCount;
1009
  ++_jmol.radioCount;
981
  if (groupName == undefined || groupName == null)
-
 
982
    groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1);
1010
  groupName != undefined && groupName != null || (groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1));
983
  if (!script)
1011
  if (!script)
984
    return "";
1012
    return "";
985
  if (labelHtml == undefined || labelHtml == null)
1013
  labelHtml != undefined && labelHtml != null || (labelHtml = script.substring(0, 32));
986
    labelHtml = script.substring(0, 32);
-
 
987
  if (! separatorHtml)
-
 
988
    separatorHtml = "";
1014
  separatorHtml || (separatorHtml = "")
989
  var scriptIndex = _jmolAddScript(script);
1015
  var scriptIndex = _jmolAddScript(script);
990
  var eospan = "</span>"
1016
  var eospan = "</span>"
991
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='"
1017
  var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='"
992
        + groupName + "' id='"+id+"' type='radio' onclick='_jmolClick(" +
1018
        + groupName + "' id='"+id+"' type='radio' onclick='_jmolClick(this," +
993
         scriptIndex + _jmol.targetText + ");return true;' onmouseover='_jmolMouseOver(" +
1019
         scriptIndex + _jmol.targetText + ");return true;' onmouseover='_jmolMouseOver(" +
994
         scriptIndex + ");return true;' onmouseout='_jmolMouseOut()' " +
1020
         scriptIndex + ");return true;' onmouseout='_jmolMouseOut()' " +
995
         (isChecked ? "checked='true' " : "") + _jmol.radioCssText + " />"
1021
         (isChecked ? "checked='true' " : "") + _jmol.radioCssText + " />"
996
  if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
1022
  if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
997
        t += eospan
1023
        t += eospan
Line 1016... Line 1042...
1016
 
1042
 
1017
function _jmolGetApplet(targetSuffix){
1043
function _jmolGetApplet(targetSuffix){
1018
 var target = "jmolApplet" + (targetSuffix ? targetSuffix : "0");
1044
 var target = "jmolApplet" + (targetSuffix ? targetSuffix : "0");
1019
 var applet = _jmolFindApplet(target);
1045
 var applet = _jmolFindApplet(target);
1020
 if (applet) return applet
1046
 if (applet) return applet
1021
 if(!_jmol.alerted)alert("could not find applet " + target);
1047
 _jmol.alerted || alert("could not find applet " + target);
1022
 _jmol.alerted = true;
1048
 _jmol.alerted = true;
1023
 return null
1049
 return null
1024
}
1050
}
1025
 
1051
 
1026
function _jmolSearchFrames(win, target) {
1052
function _jmolSearchFrames(win, target) {
Line 1051... Line 1077...
1051
    else
1077
    else
1052
      return doc[target];
1078
      return doc[target];
1053
}
1079
}
1054
 
1080
 
1055
function _jmolAddScript(script) {
1081
function _jmolAddScript(script) {
1056
  if (! script)
1082
  if (!script)
1057
    return 0;
1083
    return 0;
1058
  var index = _jmol.scripts.length;
1084
  var index = _jmol.scripts.length;
1059
  _jmol.scripts[index] = script;
1085
  _jmol.scripts[index] = script;
1060
  return index;
1086
  return index;
1061
}
1087
}
1062
 
1088
 
1063
function _jmolClick(scriptIndex, targetSuffix, elementClicked) {
1089
function _jmolClick(elementClicked, scriptIndex, targetSuffix) {
1064
  _jmol.element = elementClicked;
1090
  _jmol.element = elementClicked;
1065
  jmolScript(_jmol.scripts[scriptIndex], targetSuffix);
1091
  _jmolScriptExecute(elementClicked, _jmol.scripts[scriptIndex], targetSuffix);
1066
}
1092
}
1067
 
1093
 
1068
function _jmolMenuSelected(menuObject, targetSuffix) {
1094
function _jmolMenuSelected(menuObject, targetSuffix) {
1069
  var scriptIndex = menuObject.value;
1095
  var scriptIndex = menuObject.value;
1070
  if (scriptIndex != undefined) {
1096
  if (scriptIndex != undefined) {
1071
    jmolScript(_jmol.scripts[scriptIndex], targetSuffix);
1097
    _jmolScriptExecute(menuObject, _jmol.scripts[scriptIndex], targetSuffix);
1072
    return;
1098
    return;
1073
  }
1099
  }
1074
  var len = menuObject.length;
1100
  var len = menuObject.length;
1075
  if (typeof len == "number") {
1101
  if (typeof len == "number") {
1076
    for (var i = 0; i < len; ++i) {
1102
    for (var i = 0; i < len; ++i) {
1077
      if (menuObject[i].selected) {
1103
      if (menuObject[i].selected) {
1078
        _jmolClick(menuObject[i].value, targetSuffix);
1104
        _jmolClick(menuObject[i], menuObject[i].value, targetSuffix);
1079
        return;
1105
        return;
1080
      }
1106
      }
1081
    }
1107
    }
1082
  }
1108
  }
1083
  alert("?Que? menu selected bug #8734");
1109
  alert("?Que? menu selected bug #8734");
Line 1131... Line 1157...
1131
        }
1157
        }
1132
}
1158
}
1133
 
1159
 
1134
function _jmolCbClick(ckbox, whenChecked, whenUnchecked, targetSuffix) {
1160
function _jmolCbClick(ckbox, whenChecked, whenUnchecked, targetSuffix) {
1135
  _jmol.control = ckbox
1161
  _jmol.control = ckbox
1136
  _jmolClick(ckbox.checked ? whenChecked : whenUnchecked, targetSuffix);
1162
  _jmolClick(ckbox, ckbox.checked ? whenChecked : whenUnchecked, targetSuffix);
1137
  if(_jmol.checkboxMasters[ckbox.id])
1163
  if(_jmol.checkboxMasters[ckbox.id])
1138
        _jmolNotifyGroup(_jmol.checkboxMasters[ckbox.id], ckbox.checked)
1164
        _jmolNotifyGroup(_jmol.checkboxMasters[ckbox.id], ckbox.checked)
1139
  if(_jmol.checkboxItems[ckbox.id])
1165
  if(_jmol.checkboxItems[ckbox.id])
1140
        _jmolNotifyMaster(_jmol.checkboxItems[ckbox.id])
1166
        _jmolNotifyMaster(_jmol.checkboxItems[ckbox.id])
1141
}
1167
}
Line 1278... Line 1304...
1278
 
1304
 
1279
function _jmolLoadModel(targetSuffix,remoteURL,array,isError,errorMessage){
1305
function _jmolLoadModel(targetSuffix,remoteURL,array,isError,errorMessage){
1280
 //called by server, but in client
1306
 //called by server, but in client
1281
 //overload this function to customize return
1307
 //overload this function to customize return
1282
 _jmol.remoteURL=remoteURL
1308
 _jmol.remoteURL=remoteURL
1283
 if(isError)alert(errorMessage)
1309
 isError && alert(errorMessage)
1284
 jmolLoadInlineScript(array.join("\n"),_jmol.optionalscript,targetSuffix)
1310
 jmolLoadInlineScript(array.join("\n"),_jmol.optionalscript,targetSuffix)
1285
}
1311
}
1286
 
1312
 
1287
//////////user property/status functions/////////
1313
//////////user property/status functions/////////
1288
 
1314
 
Line 1294... Line 1320...
1294
 return _jmolEvalJSON(jmolGetPropertyAsJSON(sKey,sValue,targetSuffix),sKey)
1320
 return _jmolEvalJSON(jmolGetPropertyAsJSON(sKey,sValue,targetSuffix),sKey)
1295
}
1321
}
1296
 
1322
 
1297
function jmolGetPropertyAsString(sKey,sValue,targetSuffix) {
1323
function jmolGetPropertyAsString(sKey,sValue,targetSuffix) {
1298
 var applet = _jmolGetApplet(targetSuffix);
1324
 var applet = _jmolGetApplet(targetSuffix);
1299
 if(!sValue)sValue=""
1325
 sValue == undefined && (sValue="");
1300
 return (applet ? applet.getPropertyAsString(sKey,sValue) + "" : "")
1326
 return (applet ? applet.getPropertyAsString(sKey,sValue) + "" : "")
1301
}
1327
}
1302
 
1328
 
1303
function jmolGetPropertyAsJSON(sKey,sValue,targetSuffix) {
1329
function jmolGetPropertyAsJSON(sKey,sValue,targetSuffix) {
1304
 if(!sValue)sValue = ""
1330
 sValue == undefined && (sValue = "")
1305
 var applet = _jmolGetApplet(targetSuffix);
1331
 var applet = _jmolGetApplet(targetSuffix);
1306
 try {
1332
 try {
1307
  return (applet ? applet.getPropertyAsJSON(sKey,sValue) + "" : "")
1333
  return (applet ? applet.getPropertyAsJSON(sKey,sValue) + "" : "")
1308
 } catch(e) {
1334
 } catch(e) {
1309
  return ""
1335
  return ""
1310
 }
1336
 }
1311
}
1337
}
1312
 
1338
 
1313
function jmolGetPropertyAsJavaObject(sKey,sValue,targetSuffix) {
1339
function jmolGetPropertyAsJavaObject(sKey,sValue,targetSuffix) {
1314
 if(!sValue)sValue = ""
1340
 sValue == undefined && (sValue = "")
1315
 var applet = _jmolGetApplet(targetSuffix);
1341
 var applet = _jmolGetApplet(targetSuffix);
1316
 return (applet ? applet.getProperty(sKey,sValue) : null)
1342
 return (applet ? applet.getProperty(sKey,sValue) : null)
1317
}
1343
}
1318
 
1344
 
1319
 
1345
 
Line 1323... Line 1349...
1323
 
1349
 
1324
 
1350
 
1325
///////// synchronous scripting ////////
1351
///////// synchronous scripting ////////
1326
 
1352
 
1327
function jmolScriptWait(script, targetSuffix) {
1353
function jmolScriptWait(script, targetSuffix) {
1328
  if(!targetSuffix)targetSuffix="0"
1354
  targetSuffix == undefined && (targetSuffix="0")
1329
  var Ret=jmolScriptWaitAsArray(script, targetSuffix)
1355
  var Ret=jmolScriptWaitAsArray(script, targetSuffix)
1330
  var s = ""
1356
  var s = ""
1331
  for(var i=Ret.length;--i>=0;)
1357
  for(var i=Ret.length;--i>=0;)
1332
  for(var j=0;j< Ret[i].length;j++)
1358
  for(var j=0;j< Ret[i].length;j++)
1333
        s+=Ret[i][j]+"\n"
1359
        s+=Ret[i][j]+"\n"
1334
  return s
1360
  return s
1335
}
1361
}
1336
 
1362
 
1337
function jmolScriptWaitOutput(script, targetSuffix) {
1363
function jmolScriptWaitOutput(script, targetSuffix) {
1338
  if(!targetSuffix)targetSuffix="0"
1364
  targetSuffix == undefined && (targetSuffix="0")
1339
  var ret = ""
1365
  var ret = ""
1340
  try{
1366
  try{
1341
   if (script) {
1367
   if (script) {
1342
    _jmolCheckBrowser();
1368
    _jmolCheckBrowser();
1343
    var applet=_jmolGetApplet(targetSuffix);
1369
    var applet=_jmolGetApplet(targetSuffix);
Line 1350... Line 1376...
1350
 
1376
 
1351
function jmolEvaluate(molecularMath, targetSuffix) {
1377
function jmolEvaluate(molecularMath, targetSuffix) {
1352
 
1378
 
1353
  //carries out molecular math on a model
1379
  //carries out molecular math on a model
1354
 
1380
 
1355
  if(!targetSuffix)targetSuffix="0"
1381
  targetSuffix == undefined && (targetSuffix="0")
1356
  var result = "" + jmolGetPropertyAsJavaObject("evaluate", molecularMath, targetSuffix);
1382
  var result = "" + jmolGetPropertyAsJavaObject("evaluate", molecularMath, targetSuffix);
1357
  var s = result.replace(/\-*\d+/,"")
1383
  var s = result.replace(/\-*\d+/,"")
1358
  if (s == "" && !isNaN(parseInt(result)))return parseInt(result);
1384
  if (s == "" && !isNaN(parseInt(result)))return parseInt(result);
1359
  var s = result.replace(/\-*\d*\.\d*/,"")
1385
  var s = result.replace(/\-*\d*\.\d*/,"")
1360
  if (s == "" && !isNaN(parseFloat(result)))return parseFloat(result);
1386
  if (s == "" && !isNaN(parseFloat(result)))return parseFloat(result);
1361
  return result;
1387
  return result;
1362
}
1388
}
1363
 
1389
 
1364
function jmolScriptEcho(script, targetSuffix) {
1390
function jmolScriptEcho(script, targetSuffix) {
1365
  // returns a newline-separated list of all echos from a script
1391
  // returns a newline-separated list of all echos from a script
1366
  if(!targetSuffix)targetSuffix="0"
1392
  targetSuffix == undefined && (targetSuffix="0")
1367
  var Ret=jmolScriptWaitAsArray(script, targetSuffix)
1393
  var Ret=jmolScriptWaitAsArray(script, targetSuffix)
1368
  var s = ""
1394
  var s = ""
1369
  for(var i=Ret.length;--i>=0;)
1395
  for(var i=Ret.length;--i>=0;)
1370
  for(var j=Ret[i].length;--j>=0;)
1396
  for(var j=Ret[i].length;--j>=0;)
1371
        if (Ret[i][j][1] == "scriptEcho")s+=Ret[i][j][3]+"\n"
1397
        if (Ret[i][j][1] == "scriptEcho")s+=Ret[i][j][3]+"\n"
Line 1373... Line 1399...
1373
}
1399
}
1374
 
1400
 
1375
 
1401
 
1376
function jmolScriptMessage(script, targetSuffix) {
1402
function jmolScriptMessage(script, targetSuffix) {
1377
  // returns a newline-separated list of all messages from a script, ending with "script completed\n"
1403
  // returns a newline-separated list of all messages from a script, ending with "script completed\n"
1378
  if(!targetSuffix)targetSuffix="0"
1404
  targetSuffix == undefined && (targetSuffix="0")
1379
  var Ret=jmolScriptWaitAsArray(script, targetSuffix)
1405
  var Ret=jmolScriptWaitAsArray(script, targetSuffix)
1380
  var s = ""
1406
  var s = ""
1381
  for(var i=Ret.length;--i>=0;)
1407
  for(var i=Ret.length;--i>=0;)
1382
  for(var j=Ret[i].length;--j>=0;)
1408
  for(var j=Ret[i].length;--j>=0;)
1383
        if (Ret[i][j][1] == "scriptStatus")s+=Ret[i][j][3]+"\n"
1409
        if (Ret[i][j][1] == "scriptStatus")s+=Ret[i][j][3]+"\n"
Line 1405... Line 1431...
1405
 
1431
 
1406
 
1432
 
1407
////////////   save/restore orientation   /////////////
1433
////////////   save/restore orientation   /////////////
1408
 
1434
 
1409
function jmolSaveOrientation(id, targetSuffix) {  
1435
function jmolSaveOrientation(id, targetSuffix) {  
1410
 if(!targetSuffix)targetSuffix="0"
1436
 targetSuffix == undefined && (targetSuffix="0")
1411
  return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo
1437
 return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo
1412
}
1438
}
1413
 
1439
 
1414
function jmolRestoreOrientation(id, targetSuffix) {
1440
function jmolRestoreOrientation(id, targetSuffix) {
1415
 if(!targetSuffix)targetSuffix="0"
1441
 targetSuffix == undefined && (targetSuffix="0")
1416
 var s=_jmol["savedOrientation"+id]
1442
 var s=_jmol["savedOrientation"+id]
1417
 if (!s || s == "")return
1443
 if (!s || s == "")return
1418
 s=s.replace(/1\.0/,"0")
1444
 s=s.replace(/1\.0/,"0")
1419
 return jmolScriptWait(s,targetSuffix)
1445
 return jmolScriptWait(s,targetSuffix)
1420
}
1446
}
1421
 
1447
 
1422
function jmolRestoreOrientationDelayed(id, delay, targetSuffix) {
1448
function jmolRestoreOrientationDelayed(id, delay, targetSuffix) {
1423
 if(arguments.length < 2)delay=1;
1449
 arguments.length < 2 && (delay=1)
1424
 if(!targetSuffix)targetSuffix="0"
1450
 targetSuffix == undefined && (targetSuffix="0")
1425
 var s=_jmol["savedOrientation"+id]
1451
 var s=_jmol["savedOrientation"+id]
1426
 if (!s || s == "")return
1452
 if (!s || s == "")return
1427
 s=s.replace(/1\.0/,delay)
1453
 s=s.replace(/1\.0/,delay)
1428
 return jmolScriptWait(s,targetSuffix)
1454
 return jmolScriptWait(s,targetSuffix)
1429
}
1455
}
Line 1439... Line 1465...
1439
   jmolSetDocument(document) // if you want to then write buttons and such normally
1465
   jmolSetDocument(document) // if you want to then write buttons and such normally
1440
 
1466
 
1441
 */
1467
 */
1442
 
1468
 
1443
function jmolAppletAddParam(appletCode,name,value){
1469
function jmolAppletAddParam(appletCode,name,value){
1444
  if(value == "")return appletCode
-
 
1445
  return appletCode.replace(/\<param/,"\n<param name='"+name+"' value='"+value+"' />\n<param")
1470
  return (value == "" ? appletCode : appletCode.replace(/\<param/,"\n<param name='"+name+"' value='"+value+"' />\n<param"))
1446
}
1471
}
1447
 
1472
 
1448
///////////////auto load Research Consortium for Structural Biology (RCSB) data ///////////
1473
///////////////auto load Research Consortium for Structural Biology (RCSB) data ///////////
1449
 
1474
 
1450
function jmolLoadAjax_STOLAF_RCSB(fileformat,pdbid,optionalscript,targetSuffix){
1475
function jmolLoadAjax_STOLAF_RCSB(fileformat,pdbid,optionalscript,targetSuffix){
1451
 
1476
 
1452
 if(!_jmol.thismodel)_jmol.thismodel = "1crn"
1477
 _jmol.thismodel || (_jmol.thismodel = "1crn")
1453
 if(!_jmol.serverURL)_jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"
1478
 _jmol.serverURL || (_jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm")
1454
 if(!_jmol.RCSBserver)_jmol.RCSBserver="http://www.rcsb.org"
1479
 _jmol.RCSBserver || (_jmol.RCSBserver="http://www.rcsb.org")
1455
 if(!_jmol.defaultURL_RCSB)_jmol.defaultURL_RCSB=_jmol.RCSBserver+"/pdb/files/1CRN.CIF"
1480
 _jmol.defaultURL_RCSB || (_jmol.defaultURL_RCSB=_jmol.RCSBserver+"/pdb/files/1CRN.CIF")
1456
 if(!fileformat)fileformat="PDB"
1481
 fileformat || (fileformat="PDB")
1457
 if(!pdbid)pdbid=prompt("Enter a 4-digit PDB ID:",_jmol.thismodel)
1482
 pdbid || (pdbid=prompt("Enter a 4-digit PDB ID:",_jmol.thismodel))
1458
 if(!pdbid || pdbid.length != 4)return ""
1483
 if(!pdbid || pdbid.length != 4)return ""
1459
 if(!targetSuffix)targetSuffix="0"
1484
 targetSuffix || (targetSuffix="0")
1460
 if(!optionalscript)optionalscript=""
1485
 optionalscript || (optionalscript="")
1461
 var url=_jmol.defaultURL_RCSB.replace(/1CRN/g,pdbid.toUpperCase())
1486
 var url=_jmol.defaultURL_RCSB.replace(/1CRN/g,pdbid.toUpperCase())
1462
 if(fileformat!="CIF")url=url.replace(/CIF/,fileformat)
1487
 fileformat=="CIF" || (url=url.replace(/CIF/,fileformat))
1463
 _jmol.optionalscript=optionalscript
1488
 _jmol.optionalscript=optionalscript
1464
 _jmol.thismodel=pdbid
1489
 _jmol.thismodel=pdbid
1465
 _jmol.thistargetsuffix=targetSuffix
1490
 _jmol.thistargetsuffix=targetSuffix
1466
 _jmol.thisurl=url
1491
 _jmol.thisurl=url
1467
 _jmol.modelArray = []
1492
 _jmol.modelArray = []
Line 1472... Line 1497...
1472
 
1497
 
1473
/////////////// St. Olaf College AJAX server -- ANY URL ///////////
1498
/////////////// St. Olaf College AJAX server -- ANY URL ///////////
1474
 
1499
 
1475
function jmolLoadAjax_STOLAF_ANY(url, userid, optionalscript,targetSuffix){
1500
function jmolLoadAjax_STOLAF_ANY(url, userid, optionalscript,targetSuffix){
1476
 _jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"
1501
 _jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"
1477
 if(!_jmol.thisurlANY)_jmol.thisurlANY = "http://www.stolaf.edu/depts/chemistry/mo/struc/data/ycp3-1.mol"
1502
 _jmol.thisurlANY || (_jmol.thisurlANY = "http://www.stolaf.edu/depts/chemistry/mo/struc/data/ycp3-1.mol")
1478
 if(!url)url=prompt("Enter any (uncompressed file) URL:", _jmol.thisurlANY)
1503
 url || (url=prompt("Enter any (uncompressed file) URL:", _jmol.thisurlANY))
1479
 if(!userid)userid="0"
1504
 userid || (userid="0")
1480
 if(!targetSuffix)targetSuffix="0"
1505
 targetSuffix || (targetSuffix="0")
1481
 if(!optionalscript)optionalscript=""
1506
 optionalscript || (optionalscript="")
1482
 _jmol.optionalscript=optionalscript
1507
 _jmol.optionalscript=optionalscript
1483
 _jmol.thistargetsuffix=targetSuffix
1508
 _jmol.thistargetsuffix=targetSuffix
1484
 _jmol.modelArray = []
1509
 _jmol.modelArray = []
1485
 _jmol.thisurl = url
1510
 _jmol.thisurl = url
1486
 url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)
1511
 url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)
Line 1490... Line 1515...
1490
 
1515
 
1491
/////////////// Mineralogical Society of America (MSA) data /////////
1516
/////////////// Mineralogical Society of America (MSA) data /////////
1492
 
1517
 
1493
function jmolLoadAjax_MSA(key,value,optionalscript,targetSuffix){
1518
function jmolLoadAjax_MSA(key,value,optionalscript,targetSuffix){
1494
 
1519
 
1495
 if(!_jmol.thiskeyMSA)_jmol.thiskeyMSA = "mineral"
1520
 _jmol.thiskeyMSA || (_jmol.thiskeyMSA = "mineral")
1496
 if(!_jmol.thismodelMSA)_jmol.thismodelMSA = "quartz"
1521
 _jmol.thismodelMSA || (_jmol.thismodelMSA = "quartz")
1497
 if(!_jmol.ajaxURL_MSA)_jmol.ajaxURL_MSA="http://rruff.geo.arizona.edu/AMS/result.php?mineral=quartz&viewing=ajaxjs"
1522
 _jmol.ajaxURL_MSA || (_jmol.ajaxURL_MSA="http://rruff.geo.arizona.edu/AMS/result.php?mineral=quartz&viewing=ajaxjs")
1498
 if(!key)key=prompt("Enter a field:", _jmol.thiskeyMSA)
1523
 key || (key=prompt("Enter a field:", _jmol.thiskeyMSA))
1499
 if(!key)return ""
1524
 if(!key)return ""
1500
 if(!value)value=prompt("Enter a "+key+":", _jmol.thismodelMSA)
1525
 value || (value=prompt("Enter a "+key+":", _jmol.thismodelMSA))
1501
 if(!value)return ""
1526
 if(!value)return ""
1502
 if(!targetSuffix)targetSuffix="0"
1527
 targetSuffix || (targetSuffix="0")
1503
 if(!optionalscript)optionalscript=""
1528
 optionalscript || (optionalscript="")
1504
 if(optionalscript == 1)optionalscript='load "" {1 1 1}'
1529
 optionalscript == 1 && (optionalscript='load "" {1 1 1}')
1505
 var url=_jmol.ajaxURL_MSA.replace(/mineral/g,key).replace(/quartz/g,value)
1530
 var url=_jmol.ajaxURL_MSA.replace(/mineral/g,key).replace(/quartz/g,value)
1506
 _jmol.optionalscript=optionalscript
1531
 _jmol.optionalscript=optionalscript
1507
 _jmol.thiskeyMSA=key
1532
 _jmol.thiskeyMSA=key
1508
 _jmol.thismodelMSA=value
1533
 _jmol.thismodelMSA=value
1509
 _jmol.thistargetsuffix=targetSuffix
1534
 _jmol.thistargetsuffix=targetSuffix
Line 1515... Line 1540...
1515
}
1540
}
1516
 
1541
 
1517
 
1542
 
1518
 
1543
 
1519
function jmolLoadAjaxJS(url, userid, optionalscript,targetSuffix){
1544
function jmolLoadAjaxJS(url, userid, optionalscript,targetSuffix){
1520
 if(!userid)userid="0"
1545
 userid || (userid="0")
1521
 if(!targetSuffix)targetSuffix="0"
1546
 targetSuffix || (targetSuffix="0")
1522
 if(!optionalscript)optionalscript=""
1547
 optionalscript || (optionalscript="")
1523
 _jmol.optionalscript=optionalscript
1548
 _jmol.optionalscript=optionalscript
1524
 _jmol.thismodel=userid
1549
 _jmol.thismodel=userid
1525
 _jmol.thistargetsuffix=targetSuffix
1550
 _jmol.thistargetsuffix=targetSuffix
1526
 _jmol.modelArray = []
1551
 _jmol.modelArray = []
1527
 _jmol.thisurl = url
1552
 _jmol.thisurl = url
Line 1552... Line 1577...
1552
 
1577
 
1553
 
1578
 
1554
///////////////applet fake for testing buttons/////////////
1579
///////////////applet fake for testing buttons/////////////
1555
 
1580
 
1556
 
1581
 
1557
if(document.location.search.indexOf("NOAPPLET")>=0){
1582
if(_jmol.useNoApplet){
1558
        jmolApplet = function(w){
1583
        jmolApplet = function(w){
1559
                var s="<table style='background-color:black' width="+w+"><tr height="+w+">"
1584
                var s="<table style='background-color:black' width="+w+"><tr height="+w+">"
1560
                +"<td align=center valign=center style='background-color:white'>"
1585
                +"<td align=center valign=center style='background-color:white'>"
1561
                +"Applet would be here"
1586
                +"Applet would be here"
1562
                +"<p><textarea id=fakeApplet rows=5 cols=50></textarea>"
1587
                +"<p><textarea id=fakeApplet rows=5 cols=50></textarea>"