Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/build/pkgs/jmol/patches/Jmol.js
8821 views
1
/* Jmol 12.0 script library Jmol.js 9:48 PM 1/31/2011 Bob Hanson
2
3
checkbox heirarchy -- see http://chemapps.stolaf.edu/jmol/docs/examples-11/check.htm
4
5
based on:
6
*
7
* Copyright (C) 2004-2005 Miguel, Jmol Development, www.jmol.org
8
*
9
* Contact: [email protected]
10
*
11
* This library is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU Lesser General Public
13
* License as published by the Free Software Foundation; either
14
* version 2.1 of the License, or (at your option) any later version.
15
*
16
* This library is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
* Lesser General Public License for more details.
20
*
21
* You should have received a copy of the GNU Lesser General Public
22
* License along with this library; if not, write to the Free Software
23
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24
* 02111-1307 USA.
25
*/
26
27
// for documentation see www.jmol.org/jslibrary
28
29
try{if(typeof(_jmol)!="undefined")exit()
30
31
// place "?NOAPPLET" on your command line to check applet control action with a textarea
32
// place "?JMOLJAR=xxxxx" to use a specific jar file
33
34
// bob hanson -- jmolResize(w,h) -- resizes absolutely or by percent (w or h 0.5 means 50%)
35
// angel herraez -- update of jmolResize(w,h,targetSuffix) so it is not tied to first applet
36
// bob hanson -- jmolEvaluate -- evaluates molecular math 8:37 AM 2/23/2007
37
// bob hanson -- jmolScriptMessage -- returns all "scriptStatus" messages 8:37 AM 2/23/2007
38
// bob hanson -- jmolScriptEcho -- returns all "scriptEcho" messages 8:37 AM 2/23/2007
39
// bob hanson -- jmolScriptWait -- 11:31 AM 5/2/2006
40
// bob hanson -- remove trailing separatorHTML in radio groups -- 12:18 PM 5/6/2006
41
// bob hanson -- adds support for dynamic DOM script nodes 7:04 AM 5/19/2006
42
// bob hanson -- adds try/catch for wiki - multiple code passes 7:05 AM 5/19/2006
43
// bob hanson -- auto-initiates to defaultdir/defaultjar -- change as desired.
44
// bob hanson -- adding save/restore orientation w/ and w/o delay 11:49 AM 5/25/2006
45
// bob hanson -- adding AjaxJS service 11:16 AM 6/3/2006
46
// bob hanson -- fix for iframes not available for finding applet
47
// bob hanson -- added applet fake ?NOAPPLET URL flag
48
// bob hanson -- added jmolSetCallback(calbackName, funcName) 3:32 PM 6/13/2006
49
// used PRIOR to jmolApplet() or jmolAppletInline()
50
// added 4th array element in jmolRadioGroup -- title
51
// added <span> and id around link, checkbox, radio, menu
52
// fixing AJAX loads for MSIE/Opera-Mozilla incompatibility
53
// -- renamed Jmol-11.js from Jmol-new.js; JmolApplet.jar from JmolAppletProto.jar
54
// renamed Jmol.js for Jmol 11 distribution
55
// -- modified jmolRestoreOrientation() to be immediate, no 1-second delay
56
// bob hanson -- jmolScriptWait always returns a string -- 11:23 AM 9/16/2006
57
// bh -- jmolCommandInput()
58
// bh -- jmolSetTranslation(TF) -- forces translation even if there might be message callback issues
59
// bh -- minor fixes suggested by Angel
60
// bh -- adds jmolSetSyncId() and jmolGetSyncId()
61
// bh 3/2008 -- adds jmolAppendInlineScript() and jmolAppendInlineArray()
62
// bh 3/2008 -- fixes IE7 bug in relation to jmolLoadInlineArray()
63
// bh 6/2008 -- adds jmolSetAppletWindow()
64
// Angel H. 6/2008 -- added html <label> tags to checkboxes and radio buttons [in jmolCheckbox() and _jmolRadio() functions]
65
// bh 7/2008 -- code fix "for(i..." not "for(var i..."
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
68
69
// bh 5/2009 -- Support for XHTML using jmolSetXHTML(id)
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
81
// bh 4/2010 -- added jmolSetMemoryMb(nMb)
82
// ah 1/2011 -- wider detection of browsers; more browsers now use the object tag instead of the applet tag;
83
// fix of object tag (removed classid) accounts for change of behavior in Chrome
84
85
var defaultdir = "."
86
var defaultjar = "JmolApplet.jar"
87
88
89
// Note added 12:41 PM 9/21/2008 by Bob Hanson, [email protected]:
90
91
// JMOLJAR=xxxxx.jar on the URL for this page will override
92
// the JAR file specified in the jmolInitialize() call.
93
94
// The idea is that it can be very useful to test a web page with different JAR files
95
// Or for an expert user to substitute a signed applet for an unsigned one
96
// so as to use a broader range of models or to create JPEG files, for example.
97
98
// If the JAR file is not in the current directory (has any sort of "/" in its name)
99
// then the user is presented with a warning and asked whether it is OK to change Jar files.
100
// The default action, if the user just presses "OK" is to NOT allow the change.
101
// The user must type the word "yes" in the prompt box for the change to be approved.
102
103
// If you don't want people to be able to switch in their own JAR file on your page,
104
// simply set this next line to read "var allowJMOLJAR = false".
105
106
107
var undefined; // for IE 5 ... wherein undefined is undefined
108
109
////////////////////////////////////////////////////////////////
110
// Basic Scripting infrastruture
111
////////////////////////////////////////////////////////////////
112
113
function jmolInitialize(codebaseDirectory, fileNameOrUseSignedApplet) {
114
if (_jmol.initialized)
115
return;
116
_jmol.initialized = true;
117
if(_jmol.jmoljar) {
118
var f = _jmol.jmoljar;
119
if (f.indexOf("/") >= 0) {
120
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.")
121
var ok = prompt("Do you want to use applet " + f + "? ","yes or no")
122
if (ok == "yes") {
123
codebaseDirectory = f.substring(0, f.lastIndexOf("/"));
124
fileNameOrUseSignedApplet = f.substring(f.lastIndexOf("/") + 1);
125
} else {
126
_jmolGetJarFilename(fileNameOrUseSignedApplet);
127
alert("The web page URL was ignored. Continuing using " + _jmol.archivePath + ' in directory "' + codebaseDirectory + '"');
128
}
129
} else {
130
fileNameOrUseSignedApplet = f;
131
}
132
}
133
_jmolSetCodebase(codebaseDirectory);
134
_jmolGetJarFilename(fileNameOrUseSignedApplet);
135
_jmolOnloadResetForms();
136
}
137
138
function jmolSetTranslation(TF) {
139
_jmol.params.doTranslate = ''+TF;
140
}
141
142
function jmolToSigned(){
143
_jmolGetJarFilename(true);
144
}
145
146
function _jmolGetJarFilename(fileNameOrFlag) {
147
_jmol.archivePath =
148
(typeof(fileNameOrFlag) == "string" ? fileNameOrFlag : (fileNameOrFlag ? "JmolAppletSigned" : "JmolApplet") + "0.jar");
149
}
150
151
function jmolSetDocument(doc) {
152
_jmol.currentDocument = doc;
153
}
154
155
function jmolSetAppletColor(boxbgcolor, boxfgcolor, progresscolor) {
156
_jmolInitCheck();
157
_jmol.params.boxbgcolor = boxbgcolor;
158
if (boxfgcolor)
159
_jmol.params.boxfgcolor = boxfgcolor
160
else if (boxbgcolor == "white" || boxbgcolor == "#FFFFFF")
161
_jmol.params.boxfgcolor = "black";
162
else
163
_jmol.params.boxfgcolor = "white";
164
if (progresscolor)
165
_jmol.params.progresscolor = progresscolor;
166
if (_jmol.debugAlert)
167
alert(" boxbgcolor=" + _jmol.params.boxbgcolor +
168
" boxfgcolor=" + _jmol.params.boxfgcolor +
169
" progresscolor=" + _jmol.params.progresscolor);
170
}
171
172
function jmolSetAppletWindow(w) {
173
_jmol.appletWindow = w;
174
}
175
176
function jmolApplet(size, script, nameSuffix) {
177
_jmolInitCheck();
178
return _jmolApplet(size, null, script, nameSuffix);
179
}
180
181
////////////////////////////////////////////////////////////////
182
// Basic controls
183
////////////////////////////////////////////////////////////////
184
185
// undefined means it wasn't there; null means it was explicitly listed as null (so as to skip it)
186
187
function jmolButton(script, label, id, title) {
188
_jmolInitCheck();
189
id != undefined && id != null || (id = "jmolButton" + _jmol.buttonCount);
190
label != undefined && label != null || (label = script.substring(0, 32));
191
++_jmol.buttonCount;
192
var scriptIndex = _jmolAddScript(script);
193
var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input type='button' name='" + id + "' id='" + id +
194
"' value='" + label +
195
"' onclick='_jmolClick(this," + scriptIndex + _jmol.targetText +
196
")' onmouseover='_jmolMouseOver(" + scriptIndex +
197
");return true' onmouseout='_jmolMouseOut()' " +
198
_jmol.buttonCssText + " /></span>";
199
if (_jmol.debugAlert)
200
alert(t);
201
return _jmolDocumentWrite(t);
202
}
203
204
function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked,
205
labelHtml, isChecked, id, title) {
206
_jmolInitCheck();
207
id != undefined && id != null || (id = "jmolCheckbox" + _jmol.checkboxCount);
208
++_jmol.checkboxCount;
209
if (scriptWhenChecked == undefined || scriptWhenChecked == null ||
210
scriptWhenUnchecked == undefined || scriptWhenUnchecked == null) {
211
alert("jmolCheckbox requires two scripts");
212
return;
213
}
214
if (labelHtml == undefined || labelHtml == null) {
215
alert("jmolCheckbox requires a label");
216
return;
217
}
218
var indexChecked = _jmolAddScript(scriptWhenChecked);
219
var indexUnchecked = _jmolAddScript(scriptWhenUnchecked);
220
var eospan = "</span>"
221
var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input type='checkbox' name='" + id + "' id='" + id +
222
"' onclick='_jmolCbClick(this," +
223
indexChecked + "," + indexUnchecked + _jmol.targetText +
224
")' onmouseover='_jmolCbOver(this," + indexChecked + "," +
225
indexUnchecked +
226
");return true' onmouseout='_jmolMouseOut()' " +
227
(isChecked ? "checked='true' " : "")+ _jmol.checkboxCssText + " />"
228
if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
229
t += eospan
230
eospan = "";
231
}
232
t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan;
233
if (_jmol.debugAlert)
234
alert(t);
235
return _jmolDocumentWrite(t);
236
}
237
238
function jmolStartNewRadioGroup() {
239
++_jmol.radioGroupCount;
240
}
241
242
function jmolRadioGroup(arrayOfRadioButtons, separatorHtml, groupName, id, title) {
243
/*
244
245
array: [radio1,radio2,radio3...]
246
where radioN = ["script","label",isSelected,"id","title"]
247
248
*/
249
250
_jmolInitCheck();
251
var type = typeof arrayOfRadioButtons;
252
if (type != "object" || type == null || ! arrayOfRadioButtons.length) {
253
alert("invalid arrayOfRadioButtons");
254
return;
255
}
256
separatorHtml != undefined && separatorHtml != null || (separatorHtml = "&nbsp; ");
257
var len = arrayOfRadioButtons.length;
258
jmolStartNewRadioGroup();
259
groupName || (groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1));
260
var t = "<span id='"+(id ? id : groupName)+"'>";
261
for (var i = 0; i < len; ++i) {
262
if (i == len - 1)
263
separatorHtml = "";
264
var radio = arrayOfRadioButtons[i];
265
type = typeof radio;
266
if (type == "object") {
267
t += _jmolRadio(radio[0], radio[1], radio[2], separatorHtml, groupName, (radio.length > 3 ? radio[3]: (id ? id : groupName)+"_"+i), (radio.length > 4 ? radio[4] : 0), title);
268
} else {
269
t += _jmolRadio(radio, null, null, separatorHtml, groupName, (id ? id : groupName)+"_"+i, title);
270
}
271
}
272
t+="</span>"
273
if (_jmol.debugAlert)
274
alert(t);
275
return _jmolDocumentWrite(t);
276
}
277
278
279
function jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
280
_jmolInitCheck();
281
if (_jmol.radioGroupCount == 0)
282
++_jmol.radioGroupCount;
283
var t = _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, (id ? id : groupName + "_" + _jmol.radioCount), title ? title : 0);
284
if (_jmol.debugAlert)
285
alert(t);
286
return _jmolDocumentWrite(t);
287
}
288
289
function jmolLink(script, label, id, title) {
290
_jmolInitCheck();
291
id != undefined && id != null || (id = "jmolLink" + _jmol.linkCount);
292
label != undefined && label != null || (label = script.substring(0, 32));
293
++_jmol.linkCount;
294
var scriptIndex = _jmolAddScript(script);
295
var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><a name='" + id + "' id='" + id +
296
"' href='javascript:_jmolClick(this," + scriptIndex + _jmol.targetText + ");' onmouseover='_jmolMouseOver(" + scriptIndex +
297
");return true;' onmouseout='_jmolMouseOut()' " +
298
_jmol.linkCssText + ">" + label + "</a></span>";
299
if (_jmol.debugAlert)
300
alert(t);
301
return _jmolDocumentWrite(t);
302
}
303
304
function jmolCommandInput(label, size, id, title) {
305
_jmolInitCheck();
306
id != undefined && id != null || (id = "jmolCmd" + _jmol.cmdCount);
307
label != undefined && label != null || (label = "Execute");
308
size != undefined && !isNaN(size) || (size = 60);
309
++_jmol.cmdCount;
310
var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='" + id + "' id='" + id +
311
"' size='"+size+"' onkeypress='_jmolCommandKeyPress(event,\""+id+"\"" + _jmol.targetText + ")'><input type=button value = '"+label+"' onclick='jmolScript(document.getElementById(\""+id+"\").value" + _jmol.targetText + ")' /></span>";
312
if (_jmol.debugAlert)
313
alert(t);
314
return _jmolDocumentWrite(t);
315
}
316
317
function _jmolCommandKeyPress(e, id, target) {
318
var keycode = (window.event ? window.event.keyCode : e ? e.which : 0);
319
if (keycode == 13) {
320
var inputBox = document.getElementById(id)
321
_jmolScriptExecute(inputBox, inputBox.value, target)
322
}
323
}
324
325
function _jmolScriptExecute(element,script,target) {
326
if (typeof(script) == "object")
327
script[0](element, script, target)
328
else
329
jmolScript(script, target)
330
}
331
332
function jmolMenu(arrayOfMenuItems, size, id, title) {
333
_jmolInitCheck();
334
id != undefined && id != null || (id = "jmolMenu" + _jmol.menuCount);
335
++_jmol.menuCount;
336
var type = typeof arrayOfMenuItems;
337
if (type != null && type == "object" && arrayOfMenuItems.length) {
338
var len = arrayOfMenuItems.length;
339
if (typeof size != "number" || size == 1)
340
size = null;
341
else if (size < 0)
342
size = len;
343
var sizeText = size ? " size='" + size + "' " : "";
344
var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><select name='" + id + "' id='" + id +
345
"' onChange='_jmolMenuSelected(this" + _jmol.targetText + ")'" +
346
sizeText + _jmol.menuCssText + ">";
347
for (var i = 0; i < len; ++i) {
348
var menuItem = arrayOfMenuItems[i];
349
type = typeof menuItem;
350
var script, text;
351
var isSelected = undefined;
352
if (type == "object" && menuItem != null) {
353
script = menuItem[0];
354
text = menuItem[1];
355
isSelected = menuItem[2];
356
} else {
357
script = text = menuItem;
358
}
359
text != undefined && text != null || (text = script);
360
if (script=="#optgroup") {
361
t += "<optgroup label='" + text + "'>";
362
} else if (script=="#optgroupEnd") {
363
t += "</optgroup>";
364
} else {
365
var scriptIndex = _jmolAddScript(script);
366
var selectedText = isSelected ? "' selected='true'>" : "'>";
367
t += "<option value='" + scriptIndex + selectedText + text + "</option>";
368
}
369
}
370
t += "</select></span>";
371
if (_jmol.debugAlert)
372
alert(t);
373
return _jmolDocumentWrite(t);
374
}
375
}
376
377
function jmolHtml(html) {
378
return _jmolDocumentWrite(html);
379
}
380
381
function jmolBr() {
382
return _jmolDocumentWrite("<br />");
383
}
384
385
////////////////////////////////////////////////////////////////
386
// advanced scripting functions
387
////////////////////////////////////////////////////////////////
388
389
function jmolDebugAlert(enableAlerts) {
390
_jmol.debugAlert = (enableAlerts == undefined || enableAlerts)
391
}
392
393
function jmolAppletInline(size, inlineModel, script, nameSuffix) {
394
_jmolInitCheck();
395
return _jmolApplet(size, _jmolSterilizeInline(inlineModel),
396
script, nameSuffix);
397
}
398
399
function jmolSetTarget(targetSuffix) {
400
_jmol.targetSuffix = targetSuffix;
401
_jmol.targetText = targetSuffix ? ",\"" + targetSuffix + "\"" : ",0";
402
}
403
404
function jmolScript(script, targetSuffix) {
405
if (script) {
406
_jmolCheckBrowser();
407
if (targetSuffix == "all") {
408
with (_jmol) {
409
for (var i = 0; i < appletSuffixes.length; ++i) {
410
var applet = _jmolGetApplet(appletSuffixes[i]);
411
if (applet) applet.script(script);
412
}
413
}
414
} else {
415
var applet=_jmolGetApplet(targetSuffix);
416
if (applet) applet.script(script);
417
}
418
}
419
}
420
421
function jmolLoadInline(model, targetSuffix) {
422
if (!model)return "ERROR: NO MODEL"
423
var applet=_jmolGetApplet(targetSuffix);
424
if (!applet)return "ERROR: NO APPLET"
425
if (typeof(model) == "string")
426
return applet.loadInlineString(model, "", false);
427
else
428
return applet.loadInlineArray(model, "", false);
429
}
430
431
432
function jmolLoadInlineScript(model, script, targetSuffix) {
433
if (!model)return "ERROR: NO MODEL"
434
var applet=_jmolGetApplet(targetSuffix);
435
if (!applet)return "ERROR: NO APPLET"
436
return applet.loadInlineString(model, script, false);
437
}
438
439
440
function jmolLoadInlineArray(ModelArray, script, targetSuffix) {
441
if (!model)return "ERROR: NO MODEL"
442
script || (script="")
443
var applet=_jmolGetApplet(targetSuffix);
444
if (!applet)return "ERROR: NO APPLET"
445
try {
446
return applet.loadInlineArray(ModelArray, script, false);
447
} catch (err) {
448
//IE 7 bug
449
return applet.loadInlineString(ModelArray.join("\n"), script, false);
450
}
451
}
452
453
function jmolAppendInlineArray(ModelArray, script, targetSuffix) {
454
if (!model)return "ERROR: NO MODEL"
455
script || (script="")
456
var applet=_jmolGetApplet(targetSuffix);
457
if (!applet)return "ERROR: NO APPLET"
458
try {
459
return applet.loadInlineArray(ModelArray, script, true);
460
} catch (err) {
461
//IE 7 bug
462
return applet.loadInlineString(ModelArray.join("\n"), script, true);
463
}
464
}
465
466
function jmolAppendInlineScript(model, script, targetSuffix) {
467
if (!model)return "ERROR: NO MODEL"
468
var applet=_jmolGetApplet(targetSuffix);
469
if (!applet)return "ERROR: NO APPLET"
470
return applet.loadInlineString(model, script, true);
471
}
472
473
function jmolCheckBrowser(action, urlOrMessage, nowOrLater) {
474
if (typeof action == "string") {
475
action = action.toLowerCase();
476
action == "alert" || action == "redirect" || action == "popup" || (action = null);
477
}
478
if (typeof action != "string")
479
alert("jmolCheckBrowser(action, urlOrMessage, nowOrLater)\n\n" +
480
"action must be 'alert', 'redirect', or 'popup'");
481
else {
482
if (typeof urlOrMessage != "string")
483
alert("jmolCheckBrowser(action, urlOrMessage, nowOrLater)\n\n" +
484
"urlOrMessage must be a string");
485
else {
486
_jmol.checkBrowserAction = action;
487
_jmol.checkBrowserUrlOrMessage = urlOrMessage;
488
}
489
}
490
if (typeof nowOrLater == "string" && nowOrLater.toLowerCase() == "now")
491
_jmolCheckBrowser();
492
}
493
494
////////////////////////////////////////////////////////////////
495
// Cascading Style Sheet Class support
496
////////////////////////////////////////////////////////////////
497
498
function jmolSetAppletCssClass(appletCssClass) {
499
if (_jmol.hasGetElementById) {
500
_jmol.appletCssClass = appletCssClass;
501
_jmol.appletCssText = appletCssClass ? "class='" + appletCssClass + "' " : "";
502
}
503
}
504
505
function jmolSetButtonCssClass(buttonCssClass) {
506
if (_jmol.hasGetElementById) {
507
_jmol.buttonCssClass = buttonCssClass;
508
_jmol.buttonCssText = buttonCssClass ? "class='" + buttonCssClass + "' " : "";
509
}
510
}
511
512
function jmolSetCheckboxCssClass(checkboxCssClass) {
513
if (_jmol.hasGetElementById) {
514
_jmol.checkboxCssClass = checkboxCssClass;
515
_jmol.checkboxCssText = checkboxCssClass ? "class='" + checkboxCssClass + "' " : "";
516
}
517
}
518
519
function jmolSetRadioCssClass(radioCssClass) {
520
if (_jmol.hasGetElementById) {
521
_jmol.radioCssClass = radioCssClass;
522
_jmol.radioCssText = radioCssClass ? "class='" + radioCssClass + "' " : "";
523
}
524
}
525
526
function jmolSetLinkCssClass(linkCssClass) {
527
if (_jmol.hasGetElementById) {
528
_jmol.linkCssClass = linkCssClass;
529
_jmol.linkCssText = linkCssClass ? "class='" + linkCssClass + "' " : "";
530
}
531
}
532
533
function jmolSetMenuCssClass(menuCssClass) {
534
if (_jmol.hasGetElementById) {
535
_jmol.menuCssClass = menuCssClass;
536
_jmol.menuCssText = menuCssClass ? "class='" + menuCssClass + "' " : "";
537
}
538
}
539
540
////////////////////////////////////////////////////////////////
541
// functions for INTERNAL USE ONLY which are subject to change
542
// use at your own risk ... you have been WARNED!
543
////////////////////////////////////////////////////////////////
544
var _jmol = {
545
currentDocument: document,
546
547
debugAlert: false,
548
549
codebase: "",
550
modelbase: ".",
551
552
appletCount: 0,
553
appletSuffixes: [],
554
appletWindow: null,
555
allowedJmolSize: [25, 2048, 300], // min, max, default (pixels)
556
/* By setting the _jmol.allowedJmolSize[] variable in the webpage
557
before calling jmolApplet(), limits for applet size can be overriden.
558
2048 standard for GeoWall (http://geowall.geo.lsa.umich.edu/home.html)
559
*/
560
buttonCount: 0,
561
checkboxCount: 0,
562
linkCount: 0,
563
cmdCount: 0,
564
menuCount: 0,
565
radioCount: 0,
566
radioGroupCount: 0,
567
568
appletCssClass: null,
569
appletCssText: "",
570
buttonCssClass: null,
571
buttonCssText: "",
572
checkboxCssClass: null,
573
checkboxCssText: "",
574
java_arguments: "-Xmx512m",
575
radioCssClass: null,
576
radioCssText: "",
577
linkCssClass: null,
578
linkCssText: "",
579
menuCssClass: null,
580
menuCssText: "",
581
582
targetSuffix: 0,
583
targetText: ",0",
584
scripts: [""],
585
params: {
586
syncId: ("" + Math.random()).substring(3),
587
progressbar: "true",
588
progresscolor: "blue",
589
boxbgcolor: "black",
590
boxfgcolor: "white",
591
boxmessage: "Downloading JmolApplet ..."
592
},
593
ua: navigator.userAgent.toLowerCase(),
594
// uaVersion: parseFloat(navigator.appVersion), // not used
595
596
os: "unknown",
597
browser: "unknown",
598
browserVersion: 0,
599
hasGetElementById: !!document.getElementById,
600
isJavaEnabled: navigator.javaEnabled(),
601
// isNetscape47Win: false, // not used, N4.7 is no longer supported even for detection
602
useIEObject: false,
603
useHtml4Object: false,
604
605
windowsClassId: "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93",
606
windowsCabUrl:
607
"http://java.sun.com/update/1.6.0/jinstall-6u22-windows-i586.cab",
608
609
isBrowserCompliant: false,
610
isJavaCompliant: false,
611
isFullyCompliant: false,
612
613
initialized: false,
614
initChecked: false,
615
616
browserChecked: false,
617
checkBrowserAction: "alert",
618
checkBrowserUrlOrMessage: null,
619
620
archivePath: null, // JmolApplet0.jar OR JmolAppletSigned0.jar
621
622
previousOnloadHandler: null,
623
624
jmoljar: null,
625
useNoApplet: false,
626
627
ready: {}
628
}
629
630
with (_jmol) {
631
function _jmolTestUA(candidate) {
632
var ua = _jmol.ua;
633
var index = ua.indexOf(candidate);
634
if (index < 0)
635
return false;
636
_jmol.browser = candidate;
637
_jmol.browserVersion = parseFloat(ua.substring(index+candidate.length+1));
638
return true;
639
}
640
641
function _jmolTestOS(candidate) {
642
if (_jmol.ua.indexOf(candidate) < 0)
643
return false;
644
_jmol.os = candidate;
645
return true;
646
}
647
648
_jmolTestUA("konqueror") ||
649
_jmolTestUA("webkit") ||
650
_jmolTestUA("omniweb") ||
651
_jmolTestUA("opera") ||
652
_jmolTestUA("webtv") ||
653
_jmolTestUA("icab") ||
654
_jmolTestUA("msie") ||
655
(_jmol.ua.indexOf("compatible") < 0 && _jmolTestUA("mozilla")); //Netscape, Mozilla, Seamonkey, Firefox and anything assimilated
656
657
_jmolTestOS("linux") ||
658
_jmolTestOS("unix") ||
659
_jmolTestOS("mac") ||
660
_jmolTestOS("win");
661
662
isBrowserCompliant = hasGetElementById;
663
// known exceptions (old browsers):
664
if (browser == "opera" && browserVersion <= 7.54 && os == "mac"
665
|| browser == "webkit" && browserVersion < 125.12
666
|| browser == "msie" && os == "mac"
667
|| browser == "konqueror" && browserVersion <= 3.3
668
) {
669
isBrowserCompliant = false;
670
}
671
672
// possibly more checks in the future for this
673
isJavaCompliant = isJavaEnabled;
674
675
isFullyCompliant = isBrowserCompliant && isJavaCompliant;
676
677
useIEObject = (os == "win" && browser == "msie" && browserVersion >= 5.5);
678
useHtml4Object =
679
(browser == "mozilla" && browserVersion >= 5) ||
680
(browser == "opera" && browserVersion >= 8) ||
681
(browser == "webkit" && browserVersion >= 412.2);
682
try {
683
if (top.location.search.indexOf("JMOLJAR=")>=0)
684
jmoljar = top.location.search.split("JMOLJAR=")[1].split("&")[0];
685
} catch(e) {
686
// can't access top.location
687
}
688
try {
689
useNoApplet = (top.location.search.indexOf("NOAPPLET")>=0);
690
} catch(e) {
691
// can't access top.document
692
}
693
}
694
695
function jmolSetMemoryMb(nMb) {
696
_jmol.java_arguments = "-Xmx" + Math.round(nMb) + "m"
697
}
698
699
function jmolSetParameter(name,value) {
700
_jmol.params[name] = value
701
}
702
703
function jmolSetCallback(callbackName,funcName) {
704
_jmol.params[callbackName] = funcName
705
}
706
707
try {
708
// note this is done FIRST, so it cannot override a setting done by the developer
709
if (top.location.search.indexOf("PARAMS=")>=0) {
710
var pars = unescape(top.location.search.split("PARAMS=")[1].split("&")[0]).split(";");
711
for (var i = 0; i < pars.length; i++) {
712
var p = pars[i].split(":");
713
jmolSetParameter(p[0],p[1]);
714
}
715
}
716
} catch(e) {
717
// can't access top.location
718
}
719
720
function jmolSetSyncId(n) {
721
return _jmol.params["syncId"] = n
722
}
723
724
function jmolGetSyncId() {
725
return _jmol.params["syncId"]
726
}
727
728
function jmolSetLogLevel(n) {
729
_jmol.params.logLevel = ''+n;
730
}
731
732
/* AngelH, mar2007:
733
By (re)setting these variables in the webpage before calling jmolApplet(),
734
a custom message can be provided (e.g. localized for user's language) when no Java is installed.
735
*/
736
if (noJavaMsg==undefined) var noJavaMsg =
737
"You do not have Java applets enabled in your web browser, or your browser is blocking this applet.<br />\n" +
738
"Check the warning message from your browser and/or enable Java applets in<br />\n" +
739
"your web browser preferences, or install the Java Runtime Environment from <a href='http://www.java.com'>www.java.com</a><br />";
740
if (noJavaMsg2==undefined) var noJavaMsg2 =
741
"You do not have the<br />\n" +
742
"Java Runtime Environment<br />\n" +
743
"installed for applet support.<br />\n" +
744
"Visit <a href='http://www.java.com'>www.java.com</a>";
745
function _jmolApplet(size, inlineModel, script, nameSuffix) {
746
/* AngelH, mar2007
747
Fixed percent / pixel business, to avoid browser errors:
748
put "px" where needed, avoid where not.
749
750
Bob Hanson, 1/2010
751
Fixed inline escape changing returns to |
752
*/
753
with (_jmol) {
754
nameSuffix == undefined && (nameSuffix = appletCount);
755
appletSuffixes.push(nameSuffix);
756
++appletCount;
757
script || (script = "select *");
758
var sz = _jmolGetAppletSize(size);
759
var widthAndHeight = " width='" + sz[0] + "' height='" + sz[1] + "' ";
760
var tHeader, tFooter;
761
codebase || jmolInitialize(".");
762
if (useIEObject || useHtml4Object) {
763
params.archive = archivePath;
764
params.mayscript = 'true';
765
params.codebase = codebase;
766
params.code = 'JmolApplet';
767
tHeader =
768
"<object name='jmolApplet" + nameSuffix +
769
"' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +
770
widthAndHeight + "\n";
771
tFooter = "</object>";
772
}
773
if (java_arguments)
774
params.java_arguments = java_arguments;
775
if (useIEObject) { // use MSFT IE6 object tag with .cab file reference
776
tHeader += " classid='" + windowsClassId + "'\n" +
777
(windowsCabUrl ? " codebase='" + windowsCabUrl + "'\n" : "") + ">\n";
778
} else if (useHtml4Object) { // use HTML4 object tag
779
tHeader += " type='application/x-java-applet'\n>\n";
780
/* " classid='java:JmolApplet'\n" + AH removed this
781
Chromium Issue 62076: Java Applets using an <object> with a classid paramater don't load.
782
http://code.google.com/p/chromium/issues/detail?id=62076
783
They say this is the correct behavior according to the spec, and there's no indication at this point
784
that WebKit will be changing the handling, so eventually Safari will acquire this behavior too.
785
Removing the classid parameter seems to be well tolerated by all browsers (even IE!).
786
*/
787
} else { // use applet tag
788
tHeader =
789
"<applet name='jmolApplet" + nameSuffix +
790
"' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +
791
widthAndHeight + "\n" +
792
" code='JmolApplet'" +
793
" archive='" + archivePath + "' codebase='" + codebase + "'\n" +
794
" mayscript='true'>\n";
795
tFooter = "</applet>";
796
}
797
var visitJava;
798
if (useIEObject || useHtml4Object) {
799
var szX = "width:" + sz[0]
800
if ( szX.indexOf("%")==-1 ) szX+="px"
801
var szY = "height:" + sz[1]
802
if ( szY.indexOf("%")==-1 ) szY+="px"
803
visitJava =
804
"<p style='background-color:yellow; color:black; " +
805
szX + ";" + szY + ";" +
806
// why doesn't this vertical-align work?
807
"text-align:center;vertical-align:middle;'>\n" +
808
noJavaMsg +
809
"</p>";
810
} else {
811
visitJava =
812
"<table bgcolor='yellow'><tr>" +
813
"<td align='center' valign='middle' " + widthAndHeight + "><font color='black'>\n" +
814
noJavaMsg2 +
815
"</font></td></tr></table>";
816
}
817
params.loadInline = (inlineModel ? inlineModel : "");
818
params.script = (script ? _jmolSterilizeScript(script) : "");
819
var t = tHeader + _jmolParams() + visitJava + tFooter;
820
jmolSetTarget(nameSuffix);
821
ready["jmolApplet" + nameSuffix] = false;
822
if (_jmol.debugAlert)
823
alert(t);
824
return _jmolDocumentWrite(t);
825
}
826
}
827
828
function _jmolParams() {
829
var t = "";
830
for (var i in _jmol.params)
831
if(_jmol.params[i]!="")
832
t+=" <param name='"+i+"' value='"+_jmol.params[i]+"' />\n";
833
return t
834
}
835
836
function _jmolInitCheck() {
837
if (_jmol.initChecked)
838
return;
839
_jmol.initChecked = true;
840
jmolInitialize(defaultdir, defaultjar)
841
}
842
843
function _jmolCheckBrowser() {
844
with (_jmol) {
845
if (browserChecked)
846
return;
847
browserChecked = true;
848
849
if (isFullyCompliant)
850
return true;
851
852
if (checkBrowserAction == "redirect")
853
location.href = checkBrowserUrlOrMessage;
854
else if (checkBrowserAction == "popup")
855
_jmolPopup(checkBrowserUrlOrMessage);
856
else {
857
var msg = checkBrowserUrlOrMessage;
858
if (msg == null)
859
msg = "Your web browser is not fully compatible with Jmol\n\n" +
860
"browser: " + browser +
861
" version: " + browserVersion +
862
" os: " + os +
863
" isBrowserCompliant: " + isBrowserCompliant +
864
" isJavaCompliant: " + isJavaCompliant +
865
"\n\n" + ua;
866
alert(msg);
867
}
868
}
869
return false;
870
}
871
872
function jmolSetXHTML(id) {
873
_jmol.isXHTML = true
874
_jmol.XhtmlElement = null
875
_jmol.XhtmlAppendChild = false
876
if (id){
877
_jmol.XhtmlElement = document.getElementById(id)
878
_jmol.XhtmlAppendChild = true
879
}
880
}
881
882
function _jmolDocumentWrite(text) {
883
if (_jmol.currentDocument) {
884
if (_jmol.isXHTML && !_jmol.XhtmlElement) {
885
var s = document.getElementsByTagName("script")
886
_jmol.XhtmlElement = s.item(s.length - 1)
887
_jmol.XhtmlAppendChild = false
888
}
889
if (_jmol.XhtmlElement) {
890
_jmolDomDocumentWrite(text)
891
} else {
892
_jmol.currentDocument.write(text);
893
}
894
}
895
return text;
896
}
897
898
function _jmolDomDocumentWrite(data) {
899
var pt = 0
900
var Ptr = []
901
Ptr[0] = 0
902
while (Ptr[0] < data.length) {
903
var child = _jmolGetDomElement(data, Ptr)
904
if (!child)break
905
if (_jmol.XhtmlAppendChild)
906
_jmol.XhtmlElement.appendChild(child)
907
else
908
_jmol.XhtmlElement.parentNode.insertBefore(child, _jmol.XhtmlElement);
909
}
910
}
911
function _jmolGetDomElement(data, Ptr, closetag, lvel) {
912
var e = document.createElement("span")
913
e.innerHTML = data
914
Ptr[0] = data.length
915
return e
916
917
//unnecessary?
918
919
closetag || (closetag = "")
920
lvel || (lvel = 0)
921
var pt0 = Ptr[0]
922
var pt = pt0
923
while (pt < data.length && data.charAt(pt) != "<") pt++
924
if (pt != pt0) {
925
var text = data.substring(pt0, pt)
926
Ptr[0] = pt
927
return document.createTextNode(text)
928
}
929
pt0 = ++pt
930
var ch
931
while (pt < data.length && "\n\r\t >".indexOf(ch = data.charAt(pt)) < 0) pt++
932
var tagname = data.substring(pt0, pt)
933
var e = (tagname == closetag || tagname == "/" ? ""
934
: document.createElementNS ? document.createElementNS('http://www.w3.org/1999/xhtml', tagname)
935
: document.createElement(tagname));
936
if (ch == ">") {
937
Ptr[0] = ++pt
938
return e
939
}
940
while (pt < data.length && (ch = data.charAt(pt)) != ">") {
941
while (pt < data.length && "\n\r\t ".indexOf(ch = data.charAt(pt)) >= 0) pt++
942
pt0 = pt
943
while (pt < data.length && "\n\r\t =/>".indexOf(ch = data.charAt(pt)) < 0) pt++
944
var attrname = data.substring(pt0, pt).toLowerCase()
945
if (attrname && ch != "=")
946
e.setAttribute(attrname, "true")
947
while (pt < data.length && "\n\r\t ".indexOf(ch = data.charAt(pt)) >= 0) pt++
948
if (ch == "/") {
949
Ptr[0] = pt + 2
950
return e
951
} else if (ch == "=") {
952
var quote = data.charAt(++pt)
953
pt0 = ++pt
954
while (pt < data.length && (ch = data.charAt(pt)) != quote) pt++
955
var attrvalue = data.substring(pt0, pt)
956
e.setAttribute(attrname, attrvalue)
957
pt++
958
}
959
}
960
Ptr[0] = ++pt
961
while (Ptr[0] < data.length) {
962
var child = _jmolGetDomElement(data, Ptr, "/" + tagname, lvel+1)
963
if (!child)break
964
e.appendChild(child)
965
}
966
return e
967
}
968
969
function _jmolPopup(url) {
970
var popup = window.open(url, "JmolPopup",
971
"left=150,top=150,height=400,width=600," +
972
"directories=yes,location=yes,menubar=yes," +
973
"toolbar=yes," +
974
"resizable=yes,scrollbars=yes,status=yes");
975
if (popup.focus)
976
poup.focus();
977
}
978
979
function _jmolReadyCallback(name) {
980
if (_jmol.debugAlert)
981
alert(name + " is ready");
982
_jmol.ready["" + name] = true;
983
}
984
985
function _jmolSterilizeScript(script) {
986
script = script.replace(/'/g, "&#39;");
987
if (_jmol.debugAlert)
988
alert("script:\n" + script);
989
return script;
990
}
991
992
function _jmolSterilizeInline(model) {
993
model = model.replace(/\r|\n|\r\n/g, (model.indexOf("|") >= 0 ? "\\/n" : "|")).replace(/'/g, "&#39;");
994
if (_jmol.debugAlert)
995
alert("inline model:\n" + model);
996
return model;
997
}
998
999
function _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
1000
++_jmol.radioCount;
1001
groupName != undefined && groupName != null || (groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1));
1002
if (!script)
1003
return "";
1004
labelHtml != undefined && labelHtml != null || (labelHtml = script.substring(0, 32));
1005
separatorHtml || (separatorHtml = "")
1006
var scriptIndex = _jmolAddScript(script);
1007
var eospan = "</span>"
1008
var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='"
1009
+ groupName + "' id='"+id+"' type='radio' onclick='_jmolClick(this," +
1010
scriptIndex + _jmol.targetText + ");return true;' onmouseover='_jmolMouseOver(" +
1011
scriptIndex + ");return true;' onmouseout='_jmolMouseOut()' " +
1012
(isChecked ? "checked='true' " : "") + _jmol.radioCssText + " />"
1013
if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
1014
t += eospan
1015
eospan = "";
1016
}
1017
t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan + separatorHtml;
1018
1019
return t;
1020
}
1021
1022
function _jmolFindApplet(target) {
1023
// first look for the target in the current window
1024
var applet = _jmolFindAppletInWindow(_jmol.appletWindow != null ? _jmol.appletWindow : window, target);
1025
// THEN look for the target in child frames
1026
if (applet == undefined)
1027
applet = _jmolSearchFrames(window, target);
1028
// FINALLY look for the target in sibling frames
1029
if (applet == undefined)
1030
applet = _jmolSearchFrames(top, target); // look starting in top frame
1031
return applet;
1032
}
1033
1034
function _jmolGetApplet(targetSuffix){
1035
var target = "jmolApplet" + (targetSuffix ? targetSuffix : "0");
1036
var applet = _jmolFindApplet(target);
1037
if (applet) return applet
1038
_jmol.alerted || alert("could not find applet " + target);
1039
_jmol.alerted = true;
1040
return null
1041
}
1042
1043
function _jmolSearchFrames(win, target) {
1044
var applet;
1045
var frames = win.frames;
1046
if (frames && frames.length) { // look in all the frames below this window
1047
try{
1048
for (var i = 0; i < frames.length; ++i) {
1049
applet = _jmolSearchFrames(frames[i], target);
1050
if (applet)
1051
return applet;
1052
}
1053
}catch(e) {
1054
if (_jmol.debugAlert)
1055
alert("Jmol.js _jmolSearchFrames cannot access " + win.name + ".frame[" + i + "] consider using jmolSetAppletWindow()")
1056
}
1057
}
1058
return applet = _jmolFindAppletInWindow(win, target)
1059
}
1060
1061
function _jmolFindAppletInWindow(win, target) {
1062
var doc = win.document;
1063
if (doc.getElementById(target))
1064
return doc.getElementById(target);
1065
else if (doc.applets)
1066
return doc.applets[target];
1067
else
1068
return doc[target];
1069
}
1070
1071
function _jmolAddScript(script) {
1072
if (!script)
1073
return 0;
1074
var index = _jmol.scripts.length;
1075
_jmol.scripts[index] = script;
1076
return index;
1077
}
1078
1079
function _jmolClick(elementClicked, scriptIndex, targetSuffix) {
1080
_jmol.element = elementClicked;
1081
_jmolScriptExecute(elementClicked, _jmol.scripts[scriptIndex], targetSuffix);
1082
}
1083
1084
function _jmolMenuSelected(menuObject, targetSuffix) {
1085
var scriptIndex = menuObject.value;
1086
if (scriptIndex != undefined) {
1087
_jmolScriptExecute(menuObject, _jmol.scripts[scriptIndex], targetSuffix);
1088
return;
1089
}
1090
var len = menuObject.length;
1091
if (typeof len == "number") {
1092
for (var i = 0; i < len; ++i) {
1093
if (menuObject[i].selected) {
1094
_jmolClick(menuObject[i], menuObject[i].value, targetSuffix);
1095
return;
1096
}
1097
}
1098
}
1099
alert("?Que? menu selected bug #8734");
1100
}
1101
1102
1103
_jmol.checkboxMasters = {};
1104
_jmol.checkboxItems = {};
1105
1106
function jmolSetCheckboxGroup(chkMaster,chkBox) {
1107
var id = chkMaster;
1108
if(typeof(id)=="number")id = "jmolCheckbox" + id;
1109
chkMaster = document.getElementById(id);
1110
if (!chkMaster)alert("jmolSetCheckboxGroup: master checkbox not found: " + id);
1111
var m = _jmol.checkboxMasters[id] = {};
1112
m.chkMaster = chkMaster;
1113
m.chkGroup = {};
1114
for (var i = 1; i < arguments.length; i++){
1115
var id = arguments[i];
1116
if(typeof(id)=="number")id = "jmolCheckbox" + id;
1117
checkboxItem = document.getElementById(id);
1118
if (!checkboxItem)alert("jmolSetCheckboxGroup: group checkbox not found: " + id);
1119
m.chkGroup[id] = checkboxItem;
1120
_jmol.checkboxItems[id] = m;
1121
}
1122
}
1123
1124
function _jmolNotifyMaster(m){
1125
//called when a group item is checked
1126
var allOn = true;
1127
var allOff = true;
1128
for (var chkBox in m.chkGroup){
1129
if(m.chkGroup[chkBox].checked)
1130
allOff = false;
1131
else
1132
allOn = false;
1133
}
1134
if (allOn)m.chkMaster.checked = true;
1135
if (allOff)m.chkMaster.checked = false;
1136
if ((allOn || allOff) && _jmol.checkboxItems[m.chkMaster.id])
1137
_jmolNotifyMaster(_jmol.checkboxItems[m.chkMaster.id])
1138
}
1139
1140
function _jmolNotifyGroup(m, isOn){
1141
//called when a master item is checked
1142
for (var chkBox in m.chkGroup){
1143
var item = m.chkGroup[chkBox]
1144
item.checked = isOn;
1145
if (_jmol.checkboxMasters[item.id])
1146
_jmolNotifyGroup(_jmol.checkboxMasters[item.id], isOn)
1147
}
1148
}
1149
1150
function _jmolCbClick(ckbox, whenChecked, whenUnchecked, targetSuffix) {
1151
_jmol.control = ckbox
1152
_jmolClick(ckbox, ckbox.checked ? whenChecked : whenUnchecked, targetSuffix);
1153
if(_jmol.checkboxMasters[ckbox.id])
1154
_jmolNotifyGroup(_jmol.checkboxMasters[ckbox.id], ckbox.checked)
1155
if(_jmol.checkboxItems[ckbox.id])
1156
_jmolNotifyMaster(_jmol.checkboxItems[ckbox.id])
1157
}
1158
1159
function _jmolCbOver(ckbox, whenChecked, whenUnchecked) {
1160
window.status = _jmol.scripts[ckbox.checked ? whenUnchecked : whenChecked];
1161
}
1162
1163
function _jmolMouseOver(scriptIndex) {
1164
window.status = _jmol.scripts[scriptIndex];
1165
}
1166
1167
function _jmolMouseOut() {
1168
window.status = " ";
1169
return true;
1170
}
1171
1172
function _jmolSetCodebase(codebase) {
1173
_jmol.codebase = codebase ? codebase : ".";
1174
if (_jmol.debugAlert)
1175
alert("jmolCodebase=" + _jmol.codebase);
1176
}
1177
1178
function _jmolOnloadResetForms() {
1179
// must be evaluated ONLY once
1180
_jmol.previousOnloadHandler = window.onload;
1181
window.onload =
1182
function() {
1183
with (_jmol) {
1184
if (buttonCount+checkboxCount+menuCount+radioCount+radioGroupCount > 0) {
1185
var forms = document.forms;
1186
for (var i = forms.length; --i >= 0; )
1187
forms[i].reset();
1188
}
1189
if (previousOnloadHandler)
1190
previousOnloadHandler();
1191
}
1192
}
1193
}
1194
1195
////////////////////////////////////
1196
/////extensions for getProperty/////
1197
////////////////////////////////////
1198
1199
1200
function _jmolEvalJSON(s,key){
1201
s=s+""
1202
if(!s)return []
1203
if(s.charAt(0)!="{"){
1204
if(s.indexOf(" | ")>=0)s=s.replace(/\ \|\ /g, "\n")
1205
return s
1206
}
1207
var A = eval("("+s+")")
1208
if(!A)return
1209
if(key && A[key])A=A[key]
1210
return A
1211
}
1212
1213
function _jmolEnumerateObject(A,key){
1214
var sout=""
1215
if(typeof(A) == "string" && A!="null"){
1216
sout+="\n"+key+"=\""+A+"\""
1217
}else if(!isNaN(A)||A==null){
1218
sout+="\n"+key+"="+(A+""==""?"null":A)
1219
}else if(A.length){
1220
sout+=key+"=[]"
1221
for(var i=0;i<A.length;i++){
1222
sout+="\n"
1223
if(typeof(A[i]) == "object"||typeof(A[i]) == "array"){
1224
sout+=_jmolEnumerateObject(A[i],key+"["+i+"]")
1225
}else{
1226
sout+=key+"["+i+"]="+(typeof(A[i]) == "string" && A[i]!="null"?"\""+A[i].replace(/\"/g,"\\\"")+"\"":A[i])
1227
}
1228
}
1229
}else{
1230
if(key != ""){
1231
sout+=key+"={}"
1232
key+="."
1233
}
1234
1235
for(var i in A){
1236
sout+="\n"
1237
if(typeof(A[i]) == "object"||typeof(A[i]) == "array"){
1238
sout+=_jmolEnumerateObject(A[i],key+i)
1239
}else{
1240
sout+=key+i+"="+(typeof(A[i]) == "string" && A[i]!="null"?"\""+A[i].replace(/\"/g,"\\\"")+"\"":A[i])
1241
}
1242
}
1243
}
1244
return sout
1245
}
1246
1247
1248
function _jmolSortKey0(a,b){
1249
return (a[0]<b[0]?1:a[0]>b[0]?-1:0)
1250
}
1251
1252
function _jmolSortMessages(A){
1253
if(!A || typeof(A)!="object")return []
1254
var B = []
1255
for(var i=A.length-1;i>=0;i--)for(var j=0;j<A[i].length;j++)B[B.length]=A[i][j]
1256
if(B.length == 0) return
1257
B=B.sort(_jmolSortKey0)
1258
return B
1259
}
1260
1261
/////////additional extensions //////////
1262
1263
1264
function _jmolDomScriptLoad(URL){
1265
//open(URL) //to debug
1266
_jmol.servercall=URL
1267
var node = document.getElementById("_jmolScriptNode")
1268
if (node && _jmol.browser!="msie"){
1269
document.getElementsByTagName("HEAD")[0].removeChild(node)
1270
node=null
1271
}
1272
if (node) {
1273
node.setAttribute("src",URL)
1274
} else {
1275
node=document.createElement("script")
1276
node.setAttribute("id","_jmolScriptNode")
1277
node.setAttribute("type","text/javascript")
1278
node.setAttribute("src",URL)
1279
document.getElementsByTagName("HEAD")[0].appendChild(node)
1280
}
1281
}
1282
1283
1284
function _jmolExtractPostData(url){
1285
S=url.split("&POST:")
1286
var s=""
1287
for(var i=1;i<S.length;i++){
1288
KV=S[i].split("=")
1289
s+="&POSTKEY"+i+"="+KV[0]
1290
s+="&POSTVALUE"+i+"="+KV[1]
1291
}
1292
return "&url="+escape(S[0])+s
1293
}
1294
1295
function _jmolLoadModel(targetSuffix,remoteURL,array,isError,errorMessage){
1296
//called by server, but in client
1297
//overload this function to customize return
1298
_jmol.remoteURL=remoteURL
1299
isError && alert(errorMessage)
1300
jmolLoadInlineScript(array.join("\n"),_jmol.optionalscript,targetSuffix)
1301
}
1302
1303
//////////user property/status functions/////////
1304
1305
function jmolGetStatus(strStatus,targetSuffix){
1306
return _jmolSortMessages(jmolGetPropertyAsArray("jmolStatus",strStatus,targetSuffix))
1307
}
1308
1309
function jmolGetPropertyAsArray(sKey,sValue,targetSuffix) {
1310
return _jmolEvalJSON(jmolGetPropertyAsJSON(sKey,sValue,targetSuffix),sKey)
1311
}
1312
1313
function jmolGetPropertyAsString(sKey,sValue,targetSuffix) {
1314
var applet = _jmolGetApplet(targetSuffix);
1315
sValue == undefined && (sValue="");
1316
return (applet ? applet.getPropertyAsString(sKey,sValue) + "" : "")
1317
}
1318
1319
function jmolGetPropertyAsJSON(sKey,sValue,targetSuffix) {
1320
sValue == undefined && (sValue = "")
1321
var applet = _jmolGetApplet(targetSuffix);
1322
try {
1323
return (applet ? applet.getPropertyAsJSON(sKey,sValue) + "" : "")
1324
} catch(e) {
1325
return ""
1326
}
1327
}
1328
1329
function jmolGetPropertyAsJavaObject(sKey,sValue,targetSuffix) {
1330
sValue == undefined && (sValue = "")
1331
var applet = _jmolGetApplet(targetSuffix);
1332
return (applet ? applet.getProperty(sKey,sValue) : null)
1333
}
1334
1335
1336
function jmolDecodeJSON(s) {
1337
return _jmolEnumerateObject(_jmolEvalJSON(s),"")
1338
}
1339
1340
1341
///////// synchronous scripting ////////
1342
1343
function jmolScriptWait(script, targetSuffix) {
1344
targetSuffix == undefined && (targetSuffix="0")
1345
var Ret=jmolScriptWaitAsArray(script, targetSuffix)
1346
var s = ""
1347
for(var i=Ret.length;--i>=0;)
1348
for(var j=0;j< Ret[i].length;j++)
1349
s+=Ret[i][j]+"\n"
1350
return s
1351
}
1352
1353
function jmolScriptWaitOutput(script, targetSuffix) {
1354
targetSuffix == undefined && (targetSuffix="0")
1355
var ret = ""
1356
try{
1357
if (script) {
1358
_jmolCheckBrowser();
1359
var applet=_jmolGetApplet(targetSuffix);
1360
if (applet) ret += applet.scriptWaitOutput(script);
1361
}
1362
}catch(e){
1363
}
1364
return ret;
1365
}
1366
1367
function jmolEvaluate(molecularMath, targetSuffix) {
1368
1369
//carries out molecular math on a model
1370
1371
targetSuffix == undefined && (targetSuffix="0")
1372
var result = "" + jmolGetPropertyAsJavaObject("evaluate", molecularMath, targetSuffix);
1373
var s = result.replace(/\-*\d+/,"")
1374
if (s == "" && !isNaN(parseInt(result)))return parseInt(result);
1375
var s = result.replace(/\-*\d*\.\d*/,"")
1376
if (s == "" && !isNaN(parseFloat(result)))return parseFloat(result);
1377
return result;
1378
}
1379
1380
function jmolScriptEcho(script, targetSuffix) {
1381
// returns a newline-separated list of all echos from a script
1382
targetSuffix == undefined && (targetSuffix="0")
1383
var Ret=jmolScriptWaitAsArray(script, targetSuffix)
1384
var s = ""
1385
for(var i=Ret.length;--i>=0;)
1386
for(var j=Ret[i].length;--j>=0;)
1387
if (Ret[i][j][1] == "scriptEcho")s+=Ret[i][j][3]+"\n"
1388
return s.replace(/ \| /g, "\n")
1389
}
1390
1391
1392
function jmolScriptMessage(script, targetSuffix) {
1393
// returns a newline-separated list of all messages from a script, ending with "script completed\n"
1394
targetSuffix == undefined && (targetSuffix="0")
1395
var Ret=jmolScriptWaitAsArray(script, targetSuffix)
1396
var s = ""
1397
for(var i=Ret.length;--i>=0;)
1398
for(var j=Ret[i].length;--j>=0;)
1399
if (Ret[i][j][1] == "scriptStatus")s+=Ret[i][j][3]+"\n"
1400
return s.replace(/ \| /g, "\n")
1401
}
1402
1403
1404
function jmolScriptWaitAsArray(script, targetSuffix) {
1405
var ret = ""
1406
try{
1407
jmolGetStatus("scriptEcho,scriptMessage,scriptStatus,scriptError",targetSuffix)
1408
if (script) {
1409
_jmolCheckBrowser();
1410
var applet=_jmolGetApplet(targetSuffix);
1411
if (applet) ret += applet.scriptWait(script);
1412
ret = _jmolEvalJSON(ret,"jmolStatus")
1413
if(typeof ret == "object")
1414
return ret
1415
}
1416
}catch(e){
1417
}
1418
return [[ret]]
1419
}
1420
1421
1422
1423
//////////// save/restore orientation /////////////
1424
1425
function jmolSaveOrientation(id, targetSuffix) {
1426
targetSuffix == undefined && (targetSuffix="0")
1427
return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo
1428
}
1429
1430
function jmolRestoreOrientation(id, targetSuffix) {
1431
targetSuffix == undefined && (targetSuffix="0")
1432
var s=_jmol["savedOrientation"+id]
1433
if (!s || s == "")return
1434
s=s.replace(/1\.0/,"0")
1435
return jmolScriptWait(s,targetSuffix)
1436
}
1437
1438
function jmolRestoreOrientationDelayed(id, delay, targetSuffix) {
1439
arguments.length < 2 && (delay=1)
1440
targetSuffix == undefined && (targetSuffix="0")
1441
var s=_jmol["savedOrientation"+id]
1442
if (!s || s == "")return
1443
s=s.replace(/1\.0/,delay)
1444
return jmolScriptWait(s,targetSuffix)
1445
}
1446
1447
//////////// add parameter /////////////
1448
/*
1449
* for adding callbacks or other parameters. Use:
1450
1451
jmolSetDocument(0)
1452
var s= jmolApplet(....)
1453
s = jmolAppletAddParam(s,"messageCallback", "myFunctionName")
1454
document.write(s)
1455
jmolSetDocument(document) // if you want to then write buttons and such normally
1456
1457
*/
1458
1459
function jmolAppletAddParam(appletCode,name,value){
1460
return (value == "" ? appletCode : appletCode.replace(/\<param/,"\n<param name='"+name+"' value='"+value+"' />\n<param"))
1461
}
1462
1463
///////////////auto load Research Consortium for Structural Biology (RCSB) data ///////////
1464
1465
function jmolLoadAjax_STOLAF_RCSB(fileformat,pdbid,optionalscript,targetSuffix){
1466
1467
_jmol.thismodel || (_jmol.thismodel = "1crn")
1468
_jmol.serverURL || (_jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm")
1469
_jmol.RCSBserver || (_jmol.RCSBserver="http://www.rcsb.org")
1470
_jmol.defaultURL_RCSB || (_jmol.defaultURL_RCSB=_jmol.RCSBserver+"/pdb/files/1CRN.CIF")
1471
fileformat || (fileformat="PDB")
1472
pdbid || (pdbid=prompt("Enter a 4-digit PDB ID:",_jmol.thismodel))
1473
if(!pdbid || pdbid.length != 4)return ""
1474
targetSuffix || (targetSuffix="0")
1475
optionalscript || (optionalscript="")
1476
var url=_jmol.defaultURL_RCSB.replace(/1CRN/g,pdbid.toUpperCase())
1477
fileformat=="CIF" || (url=url.replace(/CIF/,fileformat))
1478
_jmol.optionalscript=optionalscript
1479
_jmol.thismodel=pdbid
1480
_jmol.thistargetsuffix=targetSuffix
1481
_jmol.thisurl=url
1482
_jmol.modelArray = []
1483
url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)
1484
_jmolDomScriptLoad(url)
1485
return url
1486
}
1487
1488
/////////////// St. Olaf College AJAX server -- ANY URL ///////////
1489
1490
function jmolLoadAjax_STOLAF_ANY(url, userid, optionalscript,targetSuffix){
1491
_jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"
1492
_jmol.thisurlANY || (_jmol.thisurlANY = "http://www.stolaf.edu/depts/chemistry/mo/struc/data/ycp3-1.mol")
1493
url || (url=prompt("Enter any (uncompressed file) URL:", _jmol.thisurlANY))
1494
userid || (userid="0")
1495
targetSuffix || (targetSuffix="0")
1496
optionalscript || (optionalscript="")
1497
_jmol.optionalscript=optionalscript
1498
_jmol.thistargetsuffix=targetSuffix
1499
_jmol.modelArray = []
1500
_jmol.thisurl = url
1501
url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)
1502
_jmolDomScriptLoad(url)
1503
}
1504
1505
1506
/////////////// Mineralogical Society of America (MSA) data /////////
1507
1508
function jmolLoadAjax_MSA(key,value,optionalscript,targetSuffix){
1509
1510
_jmol.thiskeyMSA || (_jmol.thiskeyMSA = "mineral")
1511
_jmol.thismodelMSA || (_jmol.thismodelMSA = "quartz")
1512
_jmol.ajaxURL_MSA || (_jmol.ajaxURL_MSA="http://rruff.geo.arizona.edu/AMS/result.php?mineral=quartz&viewing=ajaxjs")
1513
key || (key=prompt("Enter a field:", _jmol.thiskeyMSA))
1514
if(!key)return ""
1515
value || (value=prompt("Enter a "+key+":", _jmol.thismodelMSA))
1516
if(!value)return ""
1517
targetSuffix || (targetSuffix="0")
1518
optionalscript || (optionalscript="")
1519
optionalscript == 1 && (optionalscript='load "" {1 1 1}')
1520
var url=_jmol.ajaxURL_MSA.replace(/mineral/g,key).replace(/quartz/g,value)
1521
_jmol.optionalscript=optionalscript
1522
_jmol.thiskeyMSA=key
1523
_jmol.thismodelMSA=value
1524
_jmol.thistargetsuffix=targetSuffix
1525
_jmol.thisurl=url
1526
_jmol.modelArray = []
1527
loadModel=_jmolLoadModel
1528
_jmolDomScriptLoad(url)
1529
return url
1530
}
1531
1532
1533
1534
function jmolLoadAjaxJS(url, userid, optionalscript,targetSuffix){
1535
userid || (userid="0")
1536
targetSuffix || (targetSuffix="0")
1537
optionalscript || (optionalscript="")
1538
_jmol.optionalscript=optionalscript
1539
_jmol.thismodel=userid
1540
_jmol.thistargetsuffix=targetSuffix
1541
_jmol.modelArray = []
1542
_jmol.thisurl = url
1543
url+="&returnFunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix
1544
_jmolDomScriptLoad(url)
1545
}
1546
1547
1548
//// in case Jmol library has already been loaded:
1549
1550
}catch(e){}
1551
1552
///////////////moving atoms //////////////
1553
1554
// HIGHLY experimental!!
1555
1556
function jmolSetAtomCoord(i,x,y,z,targetSuffix){
1557
_jmolCheckBrowser();
1558
var applet=_jmolGetApplet(targetSuffix);
1559
if (applet) applet.getProperty('jmolViewer').setAtomCoord(i,x,y,z)
1560
}
1561
1562
function jmolSetAtomCoordRelative(i,x,y,z,targetSuffix){
1563
_jmolCheckBrowser();
1564
var applet=_jmolGetApplet(targetSuffix);
1565
if (applet) applet.getProperty('jmolViewer').setAtomCoordRelative(i,x,y,z)
1566
}
1567
1568
1569
///////////////applet fake for testing buttons/////////////
1570
1571
1572
if(_jmol.useNoApplet){
1573
jmolApplet = function(w){
1574
var s="<table style='background-color:black' width="+w+"><tr height="+w+">"
1575
+"<td align=center valign=center style='background-color:white'>"
1576
+"Applet would be here"
1577
+"<p><textarea id=fakeApplet rows=5 cols=50></textarea>"
1578
+"</td></tr></table>"
1579
return _jmolDocumentWrite(s)
1580
}
1581
1582
_jmolFindApplet = function(){return jmolApplet0}
1583
1584
jmolApplet0 = {
1585
script: function(script){document.getElementById("fakeApplet").value="\njmolScript:\n"+script}
1586
,scriptWait: function(script){document.getElementById("fakeApplet").value="\njmolScriptWait:\n"+script}
1587
,loadInline: function(data,script){document.getElementById("fakeApplet").value="\njmolLoadInline data:\n"+data+"\n\nscript:\n"+script}
1588
}
1589
}
1590
1591
1592
///////////////////////////////////////////
1593
1594
// This should no longer be needed, jmolResizeApplet() is better; kept for backwards compatibility
1595
/*
1596
Resizes absolutely (pixels) or by percent of window (w or h 0.5 means 50%).
1597
targetSuffix is optional and defaults to zero (first applet in page).
1598
Both w and h are optional, but needed if you want to use targetSuffix.
1599
h defaults to w
1600
w defaults to 100% of window
1601
If either w or h is between 0 and 1, then it is taken as percent/100.
1602
If either w or h is greater than 1, then it is taken as a size (pixels).
1603
*/
1604
function jmolResize(w,h,targetSuffix) {
1605
_jmol.alerted = true;
1606
var percentW = (!w ? 100 : w <= 1 && w > 0 ? w * 100 : 0);
1607
var percentH = (!h ? percentW : h <= 1 && h > 0 ? h * 100 : 0);
1608
if (_jmol.browser=="msie") {
1609
var width=document.body.clientWidth;
1610
var height=document.body.clientHeight;
1611
} else {
1612
var netscapeScrollWidth=15;
1613
var width=window.innerWidth - netscapeScrollWidth;
1614
var height=window.innerHeight-netscapeScrollWidth;
1615
}
1616
var applet = _jmolGetApplet(targetSuffix);
1617
if(!applet)return;
1618
applet.style.width = (percentW ? width * percentW/100 : w)+"px";
1619
applet.style.height = (percentH ? height * percentH/100 : (h ? h : w))+"px";
1620
//title=width + " " + height + " " + (new Date());
1621
}
1622
1623
// 13 Jun 09 -- makes jmolResize() obsolete (kept for backwards compatibility)
1624
function jmolResizeApplet(size,targetSuffix) {
1625
// See _jmolGetAppletSize() for the formats accepted as size [same used by jmolApplet()]
1626
// Special case: an empty value for width or height is accepted, meaning no change in that dimension.
1627
_jmol.alerted = true;
1628
var applet = _jmolGetApplet(targetSuffix);
1629
if(!applet)return;
1630
var sz = _jmolGetAppletSize(size, "px");
1631
sz[0] && (applet.style.width = sz[0]);
1632
sz[1] && (applet.style.height = sz[1]);
1633
}
1634
1635
function _jmolGetAppletSize(size, units) {
1636
/* Accepts single number or 2-value array, each one can be one of:
1637
percent (text string ending %), decimal 0 to 1 (percent/100), number, or text string (interpreted as nr.)
1638
[width, height] array of strings is returned, with units added if specified.
1639
Percent is relative to container div or element (which should have explicitly set size).
1640
*/
1641
var width, height;
1642
if ( (typeof size) == "object" && size != null ) {
1643
width = size[0]; height = size[1];
1644
} else {
1645
width = height = size;
1646
}
1647
return [_jmolFixDim(width, units), _jmolFixDim(height, units)];
1648
}
1649
1650
function _jmolFixDim(x, units) {
1651
var sx = "" + x;
1652
return (sx.length == 0 ? (units ? "" : _jmol.allowedJmolSize[2])
1653
: sx.indexOf("%") == sx.length-1 ? sx
1654
: (x = parseFloat(x)) <= 1 && x > 0 ? x * 100 + "%"
1655
: (isNaN(x = Math.floor(x)) ? _jmol.allowedJmolSize[2]
1656
: x < _jmol.allowedJmolSize[0] ? _jmol.allowedJmolSize[0]
1657
: x > _jmol.allowedJmolSize[1] ? _jmol.allowedJmolSize[1]
1658
: x) + (units ? units : ""));
1659
}
1660
1661
1662
1663
1664
1665