PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/plugin-jmol/src/main/resources/emma/plugin/jmol/files/Jmol.js

https://bitbucket.org/clarion/emma
JavaScript | 1648 lines | 1270 code | 200 blank | 178 comment | 473 complexity | 88c1fe9e5956b9faacd466f4206eb0af MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. /* Jmol 11.7 script library Jmol.js 12:17 AM 4/20/2009 Bob Hanson
  2. checkbox heirarchy -- see http://chemapps.stolaf.edu/jmol/docs/examples-11/check.htm
  3. based on:
  4. *
  5. * Copyright (C) 2004-2005 Miguel, Jmol Development, www.jmol.org
  6. *
  7. * Contact: hansonr@stolaf.edu
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  22. * 02111-1307 USA.
  23. */
  24. // for documentation see www.jmol.org/jslibrary
  25. try{if(typeof(_jmol)!="undefined")exit()
  26. // place "?NOAPPLET" on your command line to check applet control action with a textarea
  27. // place "?JMOLJAR=xxxxx" to use a specific jar file
  28. // bob hanson -- jmolResize(w,h) -- resizes absolutely or by percent (w or h 0.5 means 50%)
  29. // angel herraez -- update of jmolResize(w,h,targetSuffix) so it is not tied to first applet
  30. // bob hanson -- jmolEvaluate -- evaluates molecular math 8:37 AM 2/23/2007
  31. // bob hanson -- jmolScriptMessage -- returns all "scriptStatus" messages 8:37 AM 2/23/2007
  32. // bob hanson -- jmolScriptEcho -- returns all "scriptEcho" messages 8:37 AM 2/23/2007
  33. // bob hanson -- jmolScriptWait -- 11:31 AM 5/2/2006
  34. // bob hanson -- remove trailing separatorHTML in radio groups -- 12:18 PM 5/6/2006
  35. // bob hanson -- adds support for dynamic DOM script nodes 7:04 AM 5/19/2006
  36. // bob hanson -- adds try/catch for wiki - multiple code passes 7:05 AM 5/19/2006
  37. // bob hanson -- auto-initiates to defaultdir/defaultjar -- change as desired.
  38. // bob hanson -- adding save/restore orientation w/ and w/o delay 11:49 AM 5/25/2006
  39. // bob hanson -- adding AjaxJS service 11:16 AM 6/3/2006
  40. // bob hanson -- fix for iframes not available for finding applet
  41. // bob hanson -- added applet fake ?NOAPPLET URL flag
  42. // bob hanson -- added jmolSetCallback(calbackName, funcName) 3:32 PM 6/13/2006
  43. // used PRIOR to jmolApplet() or jmolAppletInline()
  44. // added 4th array element in jmolRadioGroup -- title
  45. // added <span> and id around link, checkbox, radio, menu
  46. // fixing AJAX loads for MSIE/Opera-Mozilla incompatibility
  47. // -- renamed Jmol-11.js from Jmol-new.js; JmolApplet.jar from JmolAppletProto.jar
  48. // renamed Jmol.js for Jmol 11 distribution
  49. // -- modified jmolRestoreOrientation() to be immediate, no 1-second delay
  50. // bob hanson -- jmolScriptWait always returns a string -- 11:23 AM 9/16/2006
  51. // bh -- jmolCommandInput()
  52. // bh -- jmolSetTranslation(TF) -- forces translation even if there might be message callback issues
  53. // bh -- minor fixes suggested by Angel
  54. // bh -- adds jmolSetSyncId() and jmolGetSyncId()
  55. // bh 3/2008 -- adds jmolAppendInlineScript() and jmolAppendInlineArray()
  56. // bh 3/2008 -- fixes IE7 bug in relation to jmolLoadInlineArray()
  57. // bh 6/2008 -- adds jmolSetAppletWindow()
  58. // Angel H. 6/2008 -- added html <label> tags to checkboxes and radio buttons [in jmolCheckbox() and _jmolRadio() functions]
  59. // bh 7/2008 -- code fix "for(i..." not "for(var i..."
  60. // bh 12/2008 -- jmolLoadInline, jmolLoadInlineArray, jmolLoadInlineScript, jmolAppendInlineScript, jmolAppendInlineArray all return error message or null (Jmol 11.7.16)
  61. // bh 12/2008 -- jmolScriptWaitOutput() -- waits for script to complete and delivers output normally sent to console
  62. // bh 5/2009 -- Support for XHTML using jmolSetXHTML(id)
  63. // ah & bh 6/2009 -- New jmolResizeApplet() more flexible, similar to jmolApplet() size syntax
  64. var defaultdir = "."
  65. var defaultjar = "JmolApplet.jar"
  66. // Note added 12:41 PM 9/21/2008 by Bob Hanson, hansonr@stolaf.edu:
  67. // JMOLJAR=xxxxx.jar on the URL for this page will override
  68. // the JAR file specified in the jmolInitialize() call.
  69. // The idea is that it can be very useful to test a web page with different JAR files
  70. // Or for an expert user to substitute a signed applet for an unsigned one
  71. // so as to use a broader range of models or to create JPEG files, for example.
  72. // If the JAR file is not in the current directory (has any sort of "/" in its name)
  73. // then the user is presented with a warning and asked whether it is OK to change Jar files.
  74. // The default action, if the user just presses "OK" is to NOT allow the change.
  75. // The user must type the word "yes" in the prompt box for the change to be approved.
  76. // If you don't want people to be able to switch in their own JAR file on your page,
  77. // simply set this next line to read "var allowJMOLJAR = false".
  78. var allowJMOLJAR = true
  79. var undefined; // for IE 5 ... wherein undefined is undefined
  80. ////////////////////////////////////////////////////////////////
  81. // Basic Scripting infrastruture
  82. ////////////////////////////////////////////////////////////////
  83. function jmolInitialize(codebaseDirectory, fileNameOrUseSignedApplet) {
  84. if (_jmol.initialized)
  85. return;
  86. _jmol.initialized = true;
  87. if(allowJMOLJAR && document.location.search.indexOf("JMOLJAR=")>=0) {
  88. var f = document.location.search.split("JMOLJAR=")[1].split("&")[0];
  89. if (f.indexOf("/") >= 0) {
  90. 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.")
  91. var ok = prompt("Do you want to use applet " + f + "? ","yes or no")
  92. if (ok == "yes") {
  93. codebaseDirectory = f.substring(0, f.lastIndexOf("/"));
  94. fileNameOrUseSignedApplet = f.substring(f.lastIndexOf("/") + 1);
  95. } else {
  96. _jmolGetJarFilename(fileNameOrUseSignedApplet);
  97. alert("The web page URL was ignored. Continuing using " + _jmol.archivePath + ' in directory "' + codebaseDirectory + '"');
  98. }
  99. } else {
  100. fileNameOrUseSignedApplet = f;
  101. }
  102. }
  103. _jmolSetCodebase(codebaseDirectory);
  104. _jmolGetJarFilename(fileNameOrUseSignedApplet);
  105. _jmolOnloadResetForms();
  106. }
  107. function jmolSetTranslation(TF) {
  108. _jmol.params.doTranslate = ''+TF;
  109. }
  110. function _jmolGetJarFilename(fileNameOrFlag) {
  111. _jmol.archivePath =
  112. (typeof(fileNameOrFlag) == "string" ? fileNameOrFlag : (fileNameOrFlag ? "JmolAppletSigned" : "JmolApplet") + "0.jar");
  113. }
  114. function jmolSetDocument(doc) {
  115. _jmol.currentDocument = doc;
  116. }
  117. function jmolSetAppletColor(boxbgcolor, boxfgcolor, progresscolor) {
  118. _jmolInitCheck();
  119. _jmol.params.boxbgcolor = boxbgcolor;
  120. if (boxfgcolor)
  121. _jmol.params.boxfgcolor = boxfgcolor
  122. else if (boxbgcolor == "white" || boxbgcolor == "#FFFFFF")
  123. _jmol.params.boxfgcolor = "black";
  124. else
  125. _jmol.params.boxfgcolor = "white";
  126. if (progresscolor)
  127. _jmol.params.progresscolor = progresscolor;
  128. if (_jmol.debugAlert)
  129. alert(" boxbgcolor=" + _jmol.params.boxbgcolor +
  130. " boxfgcolor=" + _jmol.params.boxfgcolor +
  131. " progresscolor=" + _jmol.params.progresscolor);
  132. }
  133. function jmolSetAppletWindow(w) {
  134. _jmol.appletWindow = w;
  135. }
  136. function jmolApplet(size, script, nameSuffix) {
  137. _jmolInitCheck();
  138. return _jmolApplet(size, null, script, nameSuffix);
  139. }
  140. ////////////////////////////////////////////////////////////////
  141. // Basic controls
  142. ////////////////////////////////////////////////////////////////
  143. function jmolButton(script, label, id, title) {
  144. _jmolInitCheck();
  145. if (id == undefined || id == null)
  146. id = "jmolButton" + _jmol.buttonCount;
  147. if (label == undefined || label == null)
  148. label = script.substring(0, 32);
  149. ++_jmol.buttonCount;
  150. var scriptIndex = _jmolAddScript(script);
  151. var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input type='button' name='" + id + "' id='" + id +
  152. "' value='" + label +
  153. "' onclick='_jmolClick(" + scriptIndex + _jmol.targetText +
  154. ")' onmouseover='_jmolMouseOver(" + scriptIndex +
  155. ");return true' onmouseout='_jmolMouseOut()' " +
  156. _jmol.buttonCssText + " /></span>";
  157. if (_jmol.debugAlert)
  158. alert(t);
  159. return _jmolDocumentWrite(t);
  160. }
  161. function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked,
  162. labelHtml, isChecked, id, title) {
  163. _jmolInitCheck();
  164. if (id == undefined || id == null)
  165. id = "jmolCheckbox" + _jmol.checkboxCount;
  166. ++_jmol.checkboxCount;
  167. if (scriptWhenChecked == undefined || scriptWhenChecked == null ||
  168. scriptWhenUnchecked == undefined || scriptWhenUnchecked == null) {
  169. alert("jmolCheckbox requires two scripts");
  170. return;
  171. }
  172. if (labelHtml == undefined || labelHtml == null) {
  173. alert("jmolCheckbox requires a label");
  174. return;
  175. }
  176. var indexChecked = _jmolAddScript(scriptWhenChecked);
  177. var indexUnchecked = _jmolAddScript(scriptWhenUnchecked);
  178. var eospan = "</span>"
  179. var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input type='checkbox' name='" + id + "' id='" + id +
  180. "' onclick='_jmolCbClick(this," +
  181. indexChecked + "," + indexUnchecked + _jmol.targetText +
  182. ")' onmouseover='_jmolCbOver(this," + indexChecked + "," +
  183. indexUnchecked +
  184. ");return true' onmouseout='_jmolMouseOut()' " +
  185. (isChecked ? "checked='true' " : "")+ _jmol.checkboxCssText + " />"
  186. if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
  187. t += eospan
  188. eospan = "";
  189. }
  190. t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan;
  191. if (_jmol.debugAlert)
  192. alert(t);
  193. return _jmolDocumentWrite(t);
  194. }
  195. function jmolStartNewRadioGroup() {
  196. ++_jmol.radioGroupCount;
  197. }
  198. function jmolRadioGroup(arrayOfRadioButtons, separatorHtml, groupName, id, title) {
  199. /*
  200. array: [radio1,radio2,radio3...]
  201. where radioN = ["script","label",isSelected,"id","title"]
  202. */
  203. _jmolInitCheck();
  204. var type = typeof arrayOfRadioButtons;
  205. if (type != "object" || type == null || ! arrayOfRadioButtons.length) {
  206. alert("invalid arrayOfRadioButtons");
  207. return;
  208. }
  209. if (separatorHtml == undefined || separatorHtml == null)
  210. separatorHtml = "&nbsp; ";
  211. var len = arrayOfRadioButtons.length;
  212. jmolStartNewRadioGroup();
  213. if (!groupName)
  214. groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1);
  215. var t = "<span id='"+(id ? id : groupName)+"'>";
  216. for (var i = 0; i < len; ++i) {
  217. if (i == len - 1)
  218. separatorHtml = "";
  219. var radio = arrayOfRadioButtons[i];
  220. type = typeof radio;
  221. if (type == "object") {
  222. 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);
  223. } else {
  224. t += _jmolRadio(radio, null, null, separatorHtml, groupName, (id ? id : groupName)+"_"+i, title);
  225. }
  226. }
  227. t+="</span>"
  228. if (_jmol.debugAlert)
  229. alert(t);
  230. return _jmolDocumentWrite(t);
  231. }
  232. function jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
  233. _jmolInitCheck();
  234. if (_jmol.radioGroupCount == 0)
  235. ++_jmol.radioGroupCount;
  236. var t = _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, (id ? id : groupName + "_" + _jmol.radioCount), title ? title : 0);
  237. if (_jmol.debugAlert)
  238. alert(t);
  239. return _jmolDocumentWrite(t);
  240. }
  241. function jmolLink(script, label, id, title) {
  242. _jmolInitCheck();
  243. if (id == undefined || id == null)
  244. id = "jmolLink" + _jmol.linkCount;
  245. if (label == undefined || label == null)
  246. label = script.substring(0, 32);
  247. ++_jmol.linkCount;
  248. var scriptIndex = _jmolAddScript(script);
  249. var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><a name='" + id + "' id='" + id +
  250. "' href='javascript:_jmolClick(" + scriptIndex + _jmol.targetText + ");' onmouseover='_jmolMouseOver(" + scriptIndex +
  251. ");return true;' onmouseout='_jmolMouseOut()' " +
  252. _jmol.linkCssText + ">" + label + "</a></span>";
  253. if (_jmol.debugAlert)
  254. alert(t);
  255. return _jmolDocumentWrite(t);
  256. }
  257. function jmolCommandInput(label, size, id, title) {
  258. _jmolInitCheck();
  259. if (id == undefined || id == null)
  260. id = "jmolCmd" + _jmol.cmdCount;
  261. if (label == undefined || label == null)
  262. label = "Execute";
  263. if (size == undefined || isNaN(size))
  264. size = 60;
  265. ++_jmol.cmdCount;
  266. var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='" + id + "' id='" + id +
  267. "' size='"+size+"' onkeypress='_jmolCommandKeyPress(event,\""+id+"\"" + _jmol.targetText + ")'><input type=button value = '"+label+"' onclick='jmolScript(document.getElementById(\""+id+"\").value" + _jmol.targetText + ")' /></span>";
  268. if (_jmol.debugAlert)
  269. alert(t);
  270. return _jmolDocumentWrite(t);
  271. }
  272. function _jmolCommandKeyPress(e, id, target) {
  273. var keycode = (window.event ? window.event.keyCode : e ? e.which : 0);
  274. if (keycode == 13) {
  275. jmolScript(document.getElementById(id).value, target)
  276. }
  277. }
  278. function jmolMenu(arrayOfMenuItems, size, id, title) {
  279. _jmolInitCheck();
  280. if (id == undefined || id == null)
  281. id = "jmolMenu" + _jmol.menuCount;
  282. ++_jmol.menuCount;
  283. var type = typeof arrayOfMenuItems;
  284. if (type != null && type == "object" && arrayOfMenuItems.length) {
  285. var len = arrayOfMenuItems.length;
  286. if (typeof size != "number" || size == 1)
  287. size = null;
  288. else if (size < 0)
  289. size = len;
  290. var sizeText = size ? " size='" + size + "' " : "";
  291. var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><select name='" + id + "' id='" + id +
  292. "' onChange='_jmolMenuSelected(this" + _jmol.targetText + ")'" +
  293. sizeText + _jmol.menuCssText + ">";
  294. for (var i = 0; i < len; ++i) {
  295. var menuItem = arrayOfMenuItems[i];
  296. type = typeof menuItem;
  297. var script, text;
  298. var isSelected = undefined;
  299. if (type == "object" && menuItem != null) {
  300. script = menuItem[0];
  301. text = menuItem[1];
  302. isSelected = menuItem[2];
  303. } else {
  304. script = text = menuItem;
  305. }
  306. if (text == undefined || text == null)
  307. text = script;
  308. if (script=="#optgroup") {
  309. t += "<optgroup label='" + text + "'>";
  310. } else if (script=="#optgroupEnd") {
  311. t += "</optgroup>";
  312. } else {
  313. var scriptIndex = _jmolAddScript(script);
  314. var selectedText = isSelected ? "' selected='true'>" : "'>";
  315. t += "<option value='" + scriptIndex + selectedText + text + "</option>";
  316. }
  317. }
  318. t += "</select></span>";
  319. if (_jmol.debugAlert)
  320. alert(t);
  321. return _jmolDocumentWrite(t);
  322. }
  323. }
  324. function jmolHtml(html) {
  325. return _jmolDocumentWrite(html);
  326. }
  327. function jmolBr() {
  328. return _jmolDocumentWrite("<br />");
  329. }
  330. ////////////////////////////////////////////////////////////////
  331. // advanced scripting functions
  332. ////////////////////////////////////////////////////////////////
  333. function jmolDebugAlert(enableAlerts) {
  334. _jmol.debugAlert = (enableAlerts == undefined || enableAlerts)
  335. }
  336. function jmolAppletInline(size, inlineModel, script, nameSuffix) {
  337. _jmolInitCheck();
  338. return _jmolApplet(size, _jmolSterilizeInline(inlineModel),
  339. script, nameSuffix);
  340. }
  341. function jmolSetTarget(targetSuffix) {
  342. _jmol.targetSuffix = targetSuffix;
  343. _jmol.targetText = targetSuffix ? ",\"" + targetSuffix + "\"" : "";
  344. }
  345. function jmolScript(script, targetSuffix) {
  346. if (script) {
  347. _jmolCheckBrowser();
  348. if (targetSuffix == "all") {
  349. with (_jmol) {
  350. for (var i = 0; i < appletSuffixes.length; ++i) {
  351. var applet = _jmolGetApplet(appletSuffixes[i]);
  352. if (applet) applet.script(script);
  353. }
  354. }
  355. } else {
  356. var applet=_jmolGetApplet(targetSuffix);
  357. if (applet) applet.script(script);
  358. }
  359. }
  360. }
  361. function jmolLoadInline(model, targetSuffix) {
  362. if (!model)return "ERROR: NO MODEL"
  363. var applet=_jmolGetApplet(targetSuffix);
  364. if (!applet)return "ERROR: NO APPLET"
  365. if (typeof(model) == "string")
  366. return applet.loadInlineString(model, "", false);
  367. else
  368. return applet.loadInlineArray(model, "", false);
  369. }
  370. function jmolLoadInlineScript(model, script, targetSuffix) {
  371. if (!model)return "ERROR: NO MODEL"
  372. var applet=_jmolGetApplet(targetSuffix);
  373. if (!applet)return "ERROR: NO APPLET"
  374. return applet.loadInlineString(model, script, false);
  375. }
  376. function jmolLoadInlineArray(ModelArray, script, targetSuffix) {
  377. if (!model)return "ERROR: NO MODEL"
  378. if (!script)script=""
  379. var applet=_jmolGetApplet(targetSuffix);
  380. if (!applet)return "ERROR: NO APPLET"
  381. try {
  382. return applet.loadInlineArray(ModelArray, script, false);
  383. } catch (err) {
  384. //IE 7 bug
  385. return applet.loadInlineString(ModelArray.join("\n"), script, false);
  386. }
  387. }
  388. function jmolAppendInlineArray(ModelArray, script, targetSuffix) {
  389. if (!model)return "ERROR: NO MODEL"
  390. if (!script)script=""
  391. var applet=_jmolGetApplet(targetSuffix);
  392. if (!applet)return "ERROR: NO APPLET"
  393. try {
  394. return applet.loadInlineArray(ModelArray, script, true);
  395. } catch (err) {
  396. //IE 7 bug
  397. return applet.loadInlineString(ModelArray.join("\n"), script, true);
  398. }
  399. }
  400. function jmolAppendInlineScript(model, script, targetSuffix) {
  401. if (!model)return "ERROR: NO MODEL"
  402. var applet=_jmolGetApplet(targetSuffix);
  403. if (!applet)return "ERROR: NO APPLET"
  404. return applet.loadInlineString(model, script, true);
  405. }
  406. function jmolCheckBrowser(action, urlOrMessage, nowOrLater) {
  407. if (typeof action == "string") {
  408. action = action.toLowerCase();
  409. if (action != "alert" && action != "redirect" && action != "popup")
  410. action = null;
  411. }
  412. if (typeof action != "string")
  413. alert("jmolCheckBrowser(action, urlOrMessage, nowOrLater)\n\n" +
  414. "action must be 'alert', 'redirect', or 'popup'");
  415. else {
  416. if (typeof urlOrMessage != "string")
  417. alert("jmolCheckBrowser(action, urlOrMessage, nowOrLater)\n\n" +
  418. "urlOrMessage must be a string");
  419. else {
  420. _jmol.checkBrowserAction = action;
  421. _jmol.checkBrowserUrlOrMessage = urlOrMessage;
  422. }
  423. }
  424. if (typeof nowOrLater == "string" && nowOrLater.toLowerCase() == "now")
  425. _jmolCheckBrowser();
  426. }
  427. ////////////////////////////////////////////////////////////////
  428. // Cascading Style Sheet Class support
  429. ////////////////////////////////////////////////////////////////
  430. function jmolSetAppletCssClass(appletCssClass) {
  431. if (_jmol.hasGetElementById) {
  432. _jmol.appletCssClass = appletCssClass;
  433. _jmol.appletCssText = appletCssClass ? "class='" + appletCssClass + "' " : "";
  434. }
  435. }
  436. function jmolSetButtonCssClass(buttonCssClass) {
  437. if (_jmol.hasGetElementById) {
  438. _jmol.buttonCssClass = buttonCssClass;
  439. _jmol.buttonCssText = buttonCssClass ? "class='" + buttonCssClass + "' " : "";
  440. }
  441. }
  442. function jmolSetCheckboxCssClass(checkboxCssClass) {
  443. if (_jmol.hasGetElementById) {
  444. _jmol.checkboxCssClass = checkboxCssClass;
  445. _jmol.checkboxCssText = checkboxCssClass ? "class='" + checkboxCssClass + "' " : "";
  446. }
  447. }
  448. function jmolSetRadioCssClass(radioCssClass) {
  449. if (_jmol.hasGetElementById) {
  450. _jmol.radioCssClass = radioCssClass;
  451. _jmol.radioCssText = radioCssClass ? "class='" + radioCssClass + "' " : "";
  452. }
  453. }
  454. function jmolSetLinkCssClass(linkCssClass) {
  455. if (_jmol.hasGetElementById) {
  456. _jmol.linkCssClass = linkCssClass;
  457. _jmol.linkCssText = linkCssClass ? "class='" + linkCssClass + "' " : "";
  458. }
  459. }
  460. function jmolSetMenuCssClass(menuCssClass) {
  461. if (_jmol.hasGetElementById) {
  462. _jmol.menuCssClass = menuCssClass;
  463. _jmol.menuCssText = menuCssClass ? "class='" + menuCssClass + "' " : "";
  464. }
  465. }
  466. ////////////////////////////////////////////////////////////////
  467. // functions for INTERNAL USE ONLY which are subject to change
  468. // use at your own risk ... you have been WARNED!
  469. ////////////////////////////////////////////////////////////////
  470. var _jmol = {
  471. currentDocument: document,
  472. debugAlert: false,
  473. codebase: "",
  474. modelbase: ".",
  475. appletCount: 0,
  476. appletSuffixes: [],
  477. appletWindow: null,
  478. allowedJmolSize: [25, 2048, 300], // min, max, default (pixels)
  479. /* By setting the _jmol.allowedJmolSize[] variable in the webpage
  480. before calling jmolApplet(), limits for applet size can be overriden.
  481. 2048 standard for GeoWall (http://geowall.geo.lsa.umich.edu/home.html)
  482. */
  483. buttonCount: 0,
  484. checkboxCount: 0,
  485. linkCount: 0,
  486. cmdCount: 0,
  487. menuCount: 0,
  488. radioCount: 0,
  489. radioGroupCount: 0,
  490. appletCssClass: null,
  491. appletCssText: "",
  492. buttonCssClass: null,
  493. buttonCssText: "",
  494. checkboxCssClass: null,
  495. checkboxCssText: "",
  496. radioCssClass: null,
  497. radioCssText: "",
  498. linkCssClass: null,
  499. linkCssText: "",
  500. menuCssClass: null,
  501. menuCssText: "",
  502. targetSuffix: 0,
  503. targetText: "",
  504. scripts: [""],
  505. params: {
  506. syncId: ("" + Math.random()).substring(3),
  507. progressbar: "true",
  508. progresscolor: "blue",
  509. boxbgcolor: "black",
  510. boxfgcolor: "white",
  511. boxmessage: "Downloading JmolApplet ..."
  512. },
  513. ua: navigator.userAgent.toLowerCase(),
  514. uaVersion: parseFloat(navigator.appVersion),
  515. os: "unknown",
  516. browser: "unknown",
  517. browserVersion: 0,
  518. hasGetElementById: !!document.getElementById,
  519. isJavaEnabled: navigator.javaEnabled(),
  520. isNetscape47Win: false,
  521. isIEWin: false,
  522. useIEObject: false,
  523. useHtml4Object: false,
  524. windowsClassId: "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93",
  525. windowsCabUrl:
  526. "http://java.sun.com/update/1.5.0/jinstall-1_5_0_05-windows-i586.cab",
  527. isBrowserCompliant: false,
  528. isJavaCompliant: false,
  529. isFullyCompliant: false,
  530. initialized: false,
  531. initChecked: false,
  532. browserChecked: false,
  533. checkBrowserAction: "alert",
  534. checkBrowserUrlOrMessage: null,
  535. archivePath: null, // JmolApplet0.jar OR JmolAppletSigned0.jar
  536. previousOnloadHandler: null,
  537. ready: {}
  538. }
  539. with (_jmol) {
  540. function _jmolTestUA(candidate) {
  541. var ua = _jmol.ua;
  542. var index = ua.indexOf(candidate);
  543. if (index < 0)
  544. return false;
  545. _jmol.browser = candidate;
  546. _jmol.browserVersion = parseFloat(ua.substring(index+candidate.length+1));
  547. return true;
  548. }
  549. function _jmolTestOS(candidate) {
  550. if (_jmol.ua.indexOf(candidate) < 0)
  551. return false;
  552. _jmol.os = candidate;
  553. return true;
  554. }
  555. _jmolTestUA("konqueror") ||
  556. _jmolTestUA("safari") ||
  557. _jmolTestUA("omniweb") ||
  558. _jmolTestUA("opera") ||
  559. _jmolTestUA("webtv") ||
  560. _jmolTestUA("icab") ||
  561. _jmolTestUA("msie") ||
  562. (_jmol.ua.indexOf("compatible") < 0 && _jmolTestUA("mozilla"));
  563. _jmolTestOS("linux") ||
  564. _jmolTestOS("unix") ||
  565. _jmolTestOS("mac") ||
  566. _jmolTestOS("win");
  567. isNetscape47Win = (os == "win" && browser == "mozilla" &&
  568. browserVersion >= 4.78 && browserVersion <= 4.8);
  569. if (os == "win") {
  570. isBrowserCompliant = hasGetElementById;
  571. } else if (os == "mac") { // mac is the problem child :-(
  572. if (browser == "mozilla" && browserVersion >= 5) {
  573. // miguel 2004 11 17
  574. // checking the plugins array does not work because
  575. // Netscape 7.2 OS X still has Java 1.3.1 listed even though
  576. // javaplugin.sf.net is installed to upgrade to 1.4.2
  577. eval("try {var v = java.lang.System.getProperty('java.version');" +
  578. " _jmol.isBrowserCompliant = v >= '1.4.2';" +
  579. " } catch (e) { }");
  580. } else if (browser == "opera" && browserVersion <= 7.54) {
  581. isBrowserCompliant = false;
  582. } else {
  583. isBrowserCompliant = hasGetElementById &&
  584. !((browser == "msie") ||
  585. (browser == "safari" && browserVersion < 125.12));
  586. }
  587. } else if (os == "linux" || os == "unix") {
  588. if (browser == "konqueror" && browserVersion <= 3.3)
  589. isBrowserCompliant = false;
  590. else
  591. isBrowserCompliant = hasGetElementById;
  592. } else { // other OS
  593. isBrowserCompliant = hasGetElementById;
  594. }
  595. // possibly more checks in the future for this
  596. isJavaCompliant = isJavaEnabled;
  597. isFullyCompliant = isBrowserCompliant && isJavaCompliant;
  598. // IE5.5 works just fine ... but let's push them to Sun Java
  599. isIEWin = (os == "win" && browser == "msie" && browserVersion >= 5.5);
  600. useIEObject = isIEWin;
  601. useHtml4Object =
  602. (os != "mac" && browser == "mozilla" && browserVersion >= 5) ||
  603. (os == "win" && browser == "opera" && browserVersion >= 8) ||
  604. (os == "mac" && browser == "safari" && browserVersion >= 412.2);
  605. doTranslate = true;
  606. haveSetTranslate = false;
  607. }
  608. function jmolSetCallback(callbackName,funcName) {
  609. _jmol.params[callbackName] = funcName
  610. }
  611. function jmolSetSyncId(n) {
  612. return _jmol.params["syncId"] = n
  613. }
  614. function jmolGetSyncId() {
  615. return _jmol.params["syncId"]
  616. }
  617. function jmolSetLogLevel(n) {
  618. _jmol.params.logLevel = ''+n;
  619. }
  620. /* AngelH, mar2007:
  621. By (re)setting these variables in the webpage before calling jmolApplet(),
  622. a custom message can be provided (e.g. localized for user's language) when no Java is installed.
  623. */
  624. if (noJavaMsg==undefined) var noJavaMsg =
  625. "You do not have Java applets enabled in your web browser, or your browser is blocking this applet.<br />\n" +
  626. "Check the warning message from your browser and/or enable Java applets in<br />\n" +
  627. "your web browser preferences, or install the Java Runtime Environment from <a href='http://www.java.com'>www.java.com</a><br />";
  628. if (noJavaMsg2==undefined) var noJavaMsg2 =
  629. "You do not have the<br />\n" +
  630. "Java Runtime Environment<br />\n" +
  631. "installed for applet support.<br />\n" +
  632. "Visit <a href='http://www.java.com'>www.java.com</a>";
  633. function _jmolApplet(size, inlineModel, script, nameSuffix) {
  634. /* AngelH, mar2007
  635. Fixed percent / pixel business, to avoid browser errors:
  636. put "px" where needed, avoid where not.
  637. */
  638. with (_jmol) {
  639. if (! nameSuffix)
  640. nameSuffix = appletCount;
  641. appletSuffixes.push(nameSuffix);
  642. ++appletCount;
  643. if (! script)
  644. script = "select *";
  645. var sz = _jmolGetAppletSize(size);
  646. var widthAndHeight = " width='" + sz[0] + "' height='" + sz[1] + "' ";
  647. var tHeader, tFooter;
  648. if (!codebase)
  649. jmolInitialize(".");
  650. if (useIEObject || useHtml4Object) {
  651. params.name = 'jmolApplet' + nameSuffix;
  652. params.archive = archivePath;
  653. params.mayscript = 'true';
  654. params.codebase = codebase;
  655. }
  656. if (useIEObject) { // use MSFT IE6 object tag with .cab file reference
  657. winCodebase = (windowsCabUrl ? " codebase='" + windowsCabUrl + "'\n" : "");
  658. params.code = 'JmolApplet';
  659. tHeader =
  660. "<object name='jmolApplet" + nameSuffix +
  661. "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +
  662. " classid='" + windowsClassId + "'\n" + winCodebase + widthAndHeight + ">\n";
  663. tFooter = "</object>";
  664. } else if (useHtml4Object) { // use HTML4 object tag
  665. tHeader =
  666. "<object name='jmolApplet" + nameSuffix +
  667. "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" +
  668. " classid='java:JmolApplet'\n" +
  669. " type='application/x-java-applet'\n" +
  670. widthAndHeight + ">\n";
  671. tFooter = "</object>";
  672. } else { // use applet tag
  673. tHeader =
  674. "<applet name='jmolApplet" + nameSuffix +
  675. "' id='jmolApplet" + nameSuffix +
  676. "' " + appletCssText +
  677. " code='JmolApplet'" +
  678. " archive='" + archivePath + "' codebase='" + codebase + "'\n" +
  679. widthAndHeight +
  680. " mayscript='true'>\n";
  681. tFooter = "</applet>";
  682. }
  683. var visitJava;
  684. if (isIEWin || useHtml4Object) {
  685. var szX = "width:" + sz[0]
  686. if ( szX.indexOf("%")==-1 ) szX+="px"
  687. var szY = "height:" + sz[1]
  688. if ( szY.indexOf("%")==-1 ) szY+="px"
  689. visitJava =
  690. "<p style='background-color:yellow; color:black; " +
  691. szX + ";" + szY + ";" +
  692. // why doesn't this vertical-align work?
  693. "text-align:center;vertical-align:middle;'>\n" +
  694. noJavaMsg +
  695. "</p>";
  696. } else {
  697. visitJava =
  698. "<table bgcolor='yellow'><tr>" +
  699. "<td align='center' valign='middle' " + widthAndHeight + "><font color='black'>\n" +
  700. noJavaMsg2 +
  701. "</font></td></tr></table>";
  702. }
  703. params.loadInline = (inlineModel ? inlineModel : "");
  704. params.script = (script ? _jmolSterilizeScript(script) : "");
  705. var t = tHeader + _jmolParams() + visitJava + tFooter;
  706. jmolSetTarget(nameSuffix);
  707. ready["jmolApplet" + nameSuffix] = false;
  708. if (_jmol.debugAlert)
  709. alert(t);
  710. return _jmolDocumentWrite(t);
  711. }
  712. }
  713. function _jmolParams() {
  714. var t = "";
  715. for (var i in _jmol.params)
  716. if(_jmol.params[i]!="")
  717. t+=" <param name='"+i+"' value='"+_jmol.params[i]+"' />\n";
  718. return t
  719. }
  720. function _jmolInitCheck() {
  721. if (_jmol.initChecked)
  722. return;
  723. _jmol.initChecked = true;
  724. jmolInitialize(defaultdir, defaultjar)
  725. }
  726. function _jmolCheckBrowser() {
  727. with (_jmol) {
  728. if (browserChecked)
  729. return;
  730. browserChecked = true;
  731. if (isFullyCompliant)
  732. return true;
  733. if (checkBrowserAction == "redirect")
  734. location.href = checkBrowserUrlOrMessage;
  735. else if (checkBrowserAction == "popup")
  736. _jmolPopup(checkBrowserUrlOrMessage);
  737. else {
  738. var msg = checkBrowserUrlOrMessage;
  739. if (msg == null)
  740. msg = "Your web browser is not fully compatible with Jmol\n\n" +
  741. "browser: " + browser +
  742. " version: " + browserVersion +
  743. " os: " + os +
  744. " isBrowserCompliant: " + isBrowserCompliant +
  745. " isJavaCompliant: " + isJavaCompliant +
  746. "\n\n" + ua;
  747. alert(msg);
  748. }
  749. }
  750. return false;
  751. }
  752. function jmolSetXHTML(id) {
  753. _jmol.isXHTML = true
  754. _jmol.XhtmlElement = null
  755. _jmol.XhtmlAppendChild = false
  756. if (id){
  757. _jmol.XhtmlElement = document.getElementById(id)
  758. _jmol.XhtmlAppendChild = true
  759. }
  760. }
  761. function _jmolDocumentWrite(text) {
  762. if (_jmol.currentDocument) {
  763. if (_jmol.isXHTML && !_jmol.XhtmlElement) {
  764. var s = document.getElementsByTagName("script")
  765. _jmol.XhtmlElement = s.item(s.length - 1)
  766. _jmol.XhtmlAppendChild = false
  767. }
  768. if (_jmol.XhtmlElement) {
  769. _jmolDomDocumentWrite(text)
  770. } else {
  771. _jmol.currentDocument.write(text);
  772. }
  773. }
  774. return text;
  775. }
  776. function _jmolDomDocumentWrite(data) {
  777. var pt = 0
  778. var Ptr = []
  779. Ptr[0] = 0
  780. while (Ptr[0] < data.length) {
  781. var child = _jmolGetDomElement(data, Ptr)
  782. if (!child)break
  783. if (_jmol.XhtmlAppendChild)
  784. _jmol.XhtmlElement.appendChild(child)
  785. else
  786. _jmol.XhtmlElement.parentNode.insertBefore(child, _jmol.XhtmlElement);
  787. }
  788. }
  789. function _jmolGetDomElement(data, Ptr, closetag, lvel) {
  790. var e = document.createElement("span")
  791. e.innerHTML = data
  792. Ptr[0] = data.length
  793. return e
  794. //unnecessary?
  795. if (!closetag)closetag = ""
  796. if (!lvel) lvel = 0
  797. var pt0 = Ptr[0]
  798. var pt = pt0
  799. while (pt < data.length && data.charAt(pt) != "<") pt++
  800. if (pt != pt0) {
  801. var text = data.substring(pt0, pt)
  802. Ptr[0] = pt
  803. return document.createTextNode(text)
  804. }
  805. pt0 = ++pt
  806. var ch
  807. while (pt < data.length && "\n\r\t >".indexOf(ch = data.charAt(pt)) < 0) pt++
  808. var tagname = data.substring(pt0, pt)
  809. var e = (tagname == closetag || tagname == "/" ? ""
  810. : document.createElementNS ? document.createElementNS('http://www.w3.org/1999/xhtml', tagname)
  811. : document.createElement(tagname));
  812. if (ch == ">") {
  813. Ptr[0] = ++pt
  814. return e
  815. }
  816. while (pt < data.length && (ch = data.charAt(pt)) != ">") {
  817. while (pt < data.length && "\n\r\t ".indexOf(ch = data.charAt(pt)) >= 0) pt++
  818. pt0 = pt
  819. while (pt < data.length && "\n\r\t =/>".indexOf(ch = data.charAt(pt)) < 0) pt++
  820. var attrname = data.substring(pt0, pt).toLowerCase()
  821. if (attrname && ch != "=")
  822. e.setAttribute(attrname, "true")
  823. while (pt < data.length && "\n\r\t ".indexOf(ch = data.charAt(pt)) >= 0) pt++
  824. if (ch == "/") {
  825. Ptr[0] = pt + 2
  826. return e
  827. } else if (ch == "=") {
  828. var quote = data.charAt(++pt)
  829. pt0 = ++pt
  830. while (pt < data.length && (ch = data.charAt(pt)) != quote) pt++
  831. var attrvalue = data.substring(pt0, pt)
  832. e.setAttribute(attrname, attrvalue)
  833. pt++
  834. }
  835. }
  836. Ptr[0] = ++pt
  837. while (Ptr[0] < data.length) {
  838. var child = _jmolGetDomElement(data, Ptr, "/" + tagname, lvel+1)
  839. if (!child)break
  840. e.appendChild(child)
  841. }
  842. return e
  843. }
  844. function _jmolPopup(url) {
  845. var popup = window.open(url, "JmolPopup",
  846. "left=150,top=150,height=400,width=600," +
  847. "directories=yes,location=yes,menubar=yes," +
  848. "toolbar=yes," +
  849. "resizable=yes,scrollbars=yes,status=yes");
  850. if (popup.focus)
  851. poup.focus();
  852. }
  853. function _jmolReadyCallback(name) {
  854. if (_jmol.debugAlert)
  855. alert(name + " is ready");
  856. _jmol.ready["" + name] = true;
  857. }
  858. function _jmolSterilizeScript(script) {
  859. var inlineScript = script.replace(/'/g, "&#39;");
  860. if (_jmol.debugAlert)
  861. alert("script:\n" + inlineScript);
  862. return inlineScript;
  863. }
  864. function _jmolSterilizeInline(model) {
  865. var inlineModel =
  866. model.replace(/\r|\n|\r\n/g, "|").replace(/'/g, "&#39;");
  867. if (_jmol.debugAlert)
  868. alert("inline model:\n" + inlineModel);
  869. return inlineModel;
  870. }
  871. function _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
  872. ++_jmol.radioCount;
  873. if (groupName == undefined || groupName == null)
  874. groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1);
  875. if (!script)
  876. return "";
  877. if (labelHtml == undefined || labelHtml == null)
  878. labelHtml = script.substring(0, 32);
  879. if (! separatorHtml)
  880. separatorHtml = "";
  881. var scriptIndex = _jmolAddScript(script);
  882. var eospan = "</span>"
  883. var t = "<span id=\"span_"+id+"\""+(title ? " title=\"" + title + "\"":"")+"><input name='"
  884. + groupName + "' id='"+id+"' type='radio' onclick='_jmolClick(" +
  885. scriptIndex + _jmol.targetText + ");return true;' onmouseover='_jmolMouseOver(" +
  886. scriptIndex + ");return true;' onmouseout='_jmolMouseOut()' " +
  887. (isChecked ? "checked='true' " : "") + _jmol.radioCssText + " />"
  888. if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
  889. t += eospan
  890. eospan = "";
  891. }
  892. t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan + separatorHtml;
  893. return t;
  894. }
  895. function _jmolFindApplet(target) {
  896. // first look for the target in the current window
  897. var applet = _jmolFindAppletInWindow(_jmol.appletWindow != null ? _jmol.appletWindow : window, target);
  898. // THEN look for the target in child frames
  899. if (applet == undefined)
  900. applet = _jmolSearchFrames(window, target);
  901. // FINALLY look for the target in sibling frames
  902. if (applet == undefined)
  903. applet = _jmolSearchFrames(top, target); // look starting in top frame
  904. return applet;
  905. }
  906. function _jmolGetApplet(targetSuffix){
  907. var target = "jmolApplet" + (targetSuffix ? targetSuffix : "0");
  908. var applet = _jmolFindApplet(target);
  909. if (applet) return applet
  910. if(!_jmol.alerted)alert("could not find applet " + target);
  911. _jmol.alerted = true;
  912. return null
  913. }
  914. function _jmolSearchFrames(win, target) {
  915. var applet;
  916. var frames = win.frames;
  917. if (frames && frames.length) { // look in all the frames below this window
  918. try{
  919. for (var i = 0; i < frames.length; ++i) {
  920. applet = _jmolSearchFrames(frames[i], target);
  921. if (applet)
  922. return applet;
  923. }
  924. }catch(e) {
  925. if (_jmol.debugAlert)
  926. alert("Jmol.js _jmolSearchFrames cannot access " + win.name + ".frame[" + i + "] consider using jmolSetAppletWindow()")
  927. }
  928. }
  929. return applet = _jmolFindAppletInWindow(win, target)
  930. }
  931. function _jmolFindAppletInWindow(win, target) {
  932. var doc = win.document;
  933. // getElementById fails on MacOSX Safari & Mozilla
  934. if (_jmol.useHtml4Object || _jmol.useIEObject)
  935. return doc.getElementById(target);
  936. else if (doc.applets)
  937. return doc.applets[target];
  938. else
  939. return doc[target];
  940. }
  941. function _jmolAddScript(script) {
  942. if (! script)
  943. return 0;
  944. var index = _jmol.scripts.length;
  945. _jmol.scripts[index] = script;
  946. return index;
  947. }
  948. function _jmolClick(scriptIndex, targetSuffix, elementClicked) {
  949. _jmol.element = elementClicked;
  950. jmolScript(_jmol.scripts[scriptIndex], targetSuffix);
  951. }
  952. function _jmolMenuSelected(menuObject, targetSuffix) {
  953. var scriptIndex = menuObject.value;
  954. if (scriptIndex != undefined) {
  955. jmolScript(_jmol.scripts[scriptIndex], targetSuffix);
  956. return;
  957. }
  958. var len = menuObject.length;
  959. if (typeof len == "number") {
  960. for (var i = 0; i < len; ++i) {
  961. if (menuObject[i].selected) {
  962. _jmolClick(menuObject[i].value, targetSuffix);
  963. return;
  964. }
  965. }
  966. }
  967. alert("?Que? menu selected bug #8734");
  968. }
  969. _jmol.checkboxMasters = {};
  970. _jmol.checkboxItems = {};
  971. function jmolSetCheckboxGroup(chkMaster,chkBox) {
  972. var id = chkMaster;
  973. if(typeof(id)=="number")id = "jmolCheckbox" + id;
  974. chkMaster = document.getElementById(id);
  975. if (!chkMaster)alert("jmolSetCheckboxGroup: master checkbox not found: " + id);
  976. var m = _jmol.checkboxMasters[id] = {};
  977. m.chkMaster = chkMaster;
  978. m.chkGroup = {};
  979. for (var i = 1; i < arguments.length; i++){
  980. var id = arguments[i];
  981. if(typeof(id)=="number")id = "jmolCheckbox" + id;
  982. checkboxItem = document.getElementById(id);
  983. if (!checkboxItem)alert("jmolSetCheckboxGroup: group checkbox not found: " + id);
  984. m.chkGroup[id] = checkboxItem;
  985. _jmol.checkboxItems[id] = m;
  986. }
  987. }
  988. function _jmolNotifyMaster(m){
  989. //called when a group item is checked
  990. var allOn = true;
  991. var allOff = true;
  992. for (var chkBox in m.chkGroup){
  993. if(m.chkGroup[chkBox].checked)
  994. allOff = false;
  995. else
  996. allOn = false;
  997. }
  998. if (allOn)m.chkMaster.checked = true;
  999. if (allOff)m.chkMaster.checked = false;
  1000. if ((allOn || allOff) && _jmol.checkboxItems[m.chkMaster.id])
  1001. _jmolNotifyMaster(_jmol.checkboxItems[m.chkMaster.id])
  1002. }
  1003. function _jmolNotifyGroup(m, isOn){
  1004. //called when a master item is checked
  1005. for (var chkBox in m.chkGroup){
  1006. var item = m.chkGroup[chkBox]
  1007. item.checked = isOn;
  1008. if (_jmol.checkboxMasters[item.id])
  1009. _jmolNotifyGroup(_jmol.checkboxMasters[item.id], isOn)
  1010. }
  1011. }
  1012. function _jmolCbClick(ckbox, whenChecked, whenUnchecked, targetSuffix) {
  1013. _jmol.control = ckbox
  1014. _jmolClick(ckbox.checked ? whenChecked : whenUnchecked, targetSuffix);
  1015. if(_jmol.checkboxMasters[ckbox.id])
  1016. _jmolNotifyGroup(_jmol.checkboxMasters[ckbox.id], ckbox.checked)
  1017. if(_jmol.checkboxItems[ckbox.id])
  1018. _jmolNotifyMaster(_jmol.checkboxItems[ckbox.id])
  1019. }
  1020. function _jmolCbOver(ckbox, whenChecked, whenUnchecked) {
  1021. window.status = _jmol.scripts[ckbox.checked ? whenUnchecked : whenChecked];
  1022. }
  1023. function _jmolMouseOver(scriptIndex) {
  1024. window.status = _jmol.scripts[scriptIndex];
  1025. }
  1026. function _jmolMouseOut() {
  1027. window.status = " ";
  1028. return true;
  1029. }
  1030. function _jmolSetCodebase(codebase) {
  1031. _jmol.codebase = codebase ? codebase : ".";
  1032. if (_jmol.debugAlert)
  1033. alert("jmolCodebase=" + _jmol.codebase);
  1034. }
  1035. function _jmolOnloadResetForms() {
  1036. // must be evaluated ONLY once
  1037. _jmol.previousOnloadHandler = window.onload;
  1038. window.onload =
  1039. function() {
  1040. with (_jmol) {
  1041. if (buttonCount+checkboxCount+menuCount+radioCount+radioGroupCount > 0) {
  1042. var forms = document.forms;
  1043. for (var i = forms.length; --i >= 0; )
  1044. forms[i].reset();
  1045. }
  1046. if (previousOnloadHandler)
  1047. previousOnloadHandler();
  1048. }
  1049. }
  1050. }
  1051. ////////////////////////////////////
  1052. /////extensions for getProperty/////
  1053. ////////////////////////////////////
  1054. function _jmolEvalJSON(s,key){
  1055. s=s+""
  1056. if(!s)return []
  1057. if(s.charAt(0)!="{"){
  1058. if(s.indexOf(" | ")>=0)s=s.replace(/\ \|\ /g, "\n")
  1059. return s
  1060. }
  1061. var A = eval("("+s+")")
  1062. if(!A)return
  1063. if(key && A[key])A=A[key]
  1064. return A
  1065. }
  1066. function _jmolEnumerateObject(A,key){
  1067. var sout=""
  1068. if(typeof(A) == "string" && A!="null"){
  1069. sout+="\n"+key+"=\""+A+"\""
  1070. }else if(!isNaN(A)||A==null){
  1071. sout+="\n"+key+"="+(A+""==""?"null":A)
  1072. }else if(A.length){
  1073. sout+=key+"=[]"
  1074. for(var i=0;i<A.length;i++){
  1075. sout+="\n"
  1076. if(typeof(A[i]) == "object"||typeof(A[i]) == "array"){
  1077. sout+=_jmolEnumerateObject(A[i],key+"["+i+"]")
  1078. }else{
  1079. sout+=key+"["+i+"]="+(typeof(A[i]) == "string" && A[i]!="null"?"\""+A[i].replace(/\"/g,"\\\"")+"\"":A[i])
  1080. }
  1081. }
  1082. }else{
  1083. if(key != ""){
  1084. sout+=key+"={}"
  1085. key+="."
  1086. }
  1087. for(var i in A){
  1088. sout+="\n"
  1089. if(typeof(A[i]) == "object"||typeof(A[i]) == "array"){
  1090. sout+=_jmolEnumerateObject(A[i],key+i)
  1091. }else{
  1092. sout+=key+i+"="+(typeof(A[i]) == "string" && A[i]!="null"?"\""+A[i].replace(/\"/g,"\\\"")+"\"":A[i])
  1093. }
  1094. }
  1095. }
  1096. return sout
  1097. }
  1098. function _jmolSortKey0(a,b){
  1099. return (a[0]<b[0]?1:a[0]>b[0]?-1:0)
  1100. }
  1101. function _jmolSortMessages(A){
  1102. if(!A || typeof(A)!="object")return []
  1103. var B = []
  1104. for(var i=A.length-1;i>=0;i--)for(var j=0;j<A[i].length;j++)B[B.length]=A[i][j]
  1105. if(B.length == 0) return
  1106. B=B.sort(_jmolSortKey0)
  1107. return B
  1108. }
  1109. /////////additional extensions //////////
  1110. function _jmolDomScriptLoad(URL){
  1111. //open(URL) //to debug
  1112. _jmol.servercall=URL
  1113. var node = document.getElementById("_jmolScriptNode")
  1114. if (node && _jmol.browser!="msie"){
  1115. document.getElementsByTagName("HEAD")[0].removeChild(node)
  1116. node=null
  1117. }
  1118. if (node) {
  1119. node.setAttribute("src",URL)
  1120. } else {
  1121. node=document.createElement("script")
  1122. node.setAttribute("id","_jmolScriptNode")
  1123. node.setAttribute("type","text/javascript")
  1124. node.setAttribute("src",URL)
  1125. document.getElementsByTagName("HEAD")[0].appendChild(node)
  1126. }
  1127. }
  1128. function _jmolExtractPostData(url){
  1129. S=url.split("&POST:")
  1130. var s=""
  1131. for(var i=1;i<S.length;i++){
  1132. KV=S[i].split("=")
  1133. s+="&POSTKEY"+i+"="+KV[0]
  1134. s+="&POSTVALUE"+i+"="+KV[1]
  1135. }
  1136. return "&url="+escape(S[0])+s
  1137. }
  1138. function _jmolLoadModel(targetSuffix,remoteURL,array,isError,errorMessage){
  1139. //called by server, but in client
  1140. //overload this function to customize return
  1141. _jmol.remoteURL=remoteURL
  1142. if(isError)alert(errorMessage)
  1143. jmolLoadInlineScript(array.join("\n"),_jmol.optionalscript,targetSuffix)
  1144. }
  1145. //////////user property/status functions/////////
  1146. function jmolGetStatus(strStatus,targetSuffix){
  1147. return _jmolSortMessages(jmolGetPropertyAsArray("jmolStatus",strStatus,targetSuffix))
  1148. }
  1149. function jmolGetPropertyAsArray(sKey,sValue,targetSuffix) {
  1150. return _jmolEvalJSON(jmolGetPropertyAsJSON(sKey,sValue,targetSuffix),sKey)
  1151. }
  1152. function jmolGetPropertyAsString(sKey,sValue,targetSuffix) {
  1153. var applet = _jmolGetApplet(targetSuffix);
  1154. if(!sValue)sValue=""
  1155. return (applet ? applet.getPropertyAsString(sKey,sValue) + "" : "")
  1156. }
  1157. function jmolGetPropertyAsJSON(sKey,sValue,targetSuffix) {
  1158. if(!sValue)sValue = ""
  1159. var applet = _jmolGetApplet(targetSuffix);
  1160. try {
  1161. return (applet ? applet.getPropertyAsJSON(sKey,sValue) + "" : "")
  1162. } catch(e) {
  1163. return ""
  1164. }
  1165. }
  1166. function jmolGetPropertyAsJavaObject(sKey,sValue,targetSuffix) {
  1167. if(!sValue)sValue = ""
  1168. var applet = _jmolGetApplet(targetSuffix);
  1169. return (applet ? applet.getProperty(sKey,sValue) : null)
  1170. }
  1171. function jmolDecodeJSON(s) {
  1172. return _jmolEnumerateObject(_jmolEvalJSON(s),"")
  1173. }
  1174. ///////// synchronous scripting ////////
  1175. function jmolScriptWait(script, targetSuffix) {
  1176. if(!targetSuffix)targetSuffix="0"
  1177. var Ret=jmolScriptWaitAsArray(script, targetSuffix)
  1178. var s = ""
  1179. for(var i=Ret.length;--i>=0;)
  1180. for(var j=0;j< Ret[i].length;j++)
  1181. s+=Ret[i][j]+"\n"
  1182. return s
  1183. }
  1184. function jmolScriptWaitOutput(script, targetSuffix) {
  1185. if(!targetSuffix)targetSuffix="0"
  1186. var ret = ""
  1187. try{
  1188. if (script) {
  1189. _jmolCheckBrowser();
  1190. var applet=_jmolGetApplet(targetSuffix);
  1191. if (applet) ret += applet.scriptWaitOutput(script);
  1192. }
  1193. }catch(e){
  1194. }
  1195. return ret;
  1196. }
  1197. function jmolEvaluate(molecularMath, targetSuffix) {
  1198. //carries out molecular math on a model
  1199. if(!targetSuffix)targetSuffix="0"
  1200. var result = "" + jmolGetPropertyAsJavaObject("evaluate", molecularMath, targetSuffix);
  1201. var s = result.replace(/\-*\d+/,"")
  1202. if (s == "" && !isNaN(parseInt(result)))return parseInt(result);
  1203. var s = result.replace(/\-*\d*\.\d*/,"")
  1204. if (s == "" && !isNaN(parseFloat(result)))return parseFloat(result);
  1205. return result;
  1206. }
  1207. function jmolScriptEcho(script, targetSuffix) {
  1208. // returns a newline-separated list of all echos from a script
  1209. if(!targetSuffix)targetSuffix="0"
  1210. var Ret=jmolScriptWaitAsArray(script, targetSuffix)
  1211. var s = ""
  1212. for(var i=Ret.length;--i>=0;)
  1213. for(var j=Ret[i].length;--j>=0;)
  1214. if (Ret[i][j][1] == "scriptEcho")s+=Ret[i][j][3]+"\n"
  1215. return s.replace(/ \| /g, "\n")
  1216. }
  1217. function jmolScriptMessage(script, targetSuffix) {
  1218. // returns a newline-separated list of all messages from a script, ending with "script completed\n"
  1219. if(!targetSuffix)targetSuffix="0"
  1220. var Ret=jmolScriptWaitAsArray(script, targetSuffix)
  1221. var s = ""
  1222. for(var i=Ret.length;--i>=0;)
  1223. for(var j=Ret[i].length;--j>=0;)
  1224. if (Ret[i][j][1] == "scriptStatus")s+=Ret[i][j][3]+"\n"
  1225. return s.replace(/ \| /g, "\n")
  1226. }
  1227. function jmolScriptWaitAsArray(script, targetSuffix) {
  1228. var ret = ""
  1229. try{
  1230. jmolGetStatus("scriptEcho,scriptMessage,scriptStatus,scriptError",targetSuffix)
  1231. if (script) {
  1232. _jmolCheckBrowser();
  1233. var applet=_jmolGetApplet(targetSuffix);
  1234. if (applet) ret += applet.scriptWait(script);
  1235. ret = _jmolEvalJSON(ret,"jmolStatus")
  1236. if(typeof ret == "object")
  1237. return ret
  1238. }
  1239. }catch(e){
  1240. }
  1241. return [[ret]]
  1242. }
  1243. //////////// save/restore orientation /////////////
  1244. function jmolSaveOrientation(id, targetSuffix) {
  1245. if(!targetSuffix)targetSuffix="0"
  1246. return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo
  1247. }
  1248. function jmolRestoreOrientation(id, targetSuffix) {
  1249. if(!targetSuffix)targetSuffix="0"
  1250. var s=_jmol["savedOrientation"+id]
  1251. if (!s || s == "")return
  1252. s=s.replace(/1\.0/,"0")
  1253. return jmolScriptWait(s,targetSuffix)
  1254. }
  1255. function jmolRestoreOrientationDelayed(id, delay, targetSuffix) {
  1256. if(arguments.length < 2)delay=1;
  1257. if(!targetSuffix)targetSuffix="0"
  1258. var s=_jmol["savedOrientation"+id]
  1259. if (!s || s == "")return
  1260. s=s.replace(/1\.0/,delay)
  1261. return jmolScriptWait(s,targetSuffix)
  1262. }
  1263. //////////// add parameter /////////////
  1264. /*
  1265. * for adding callbacks or other parameters. Use:
  1266. jmolSetDocument(0)
  1267. var s= jmolApplet(....)
  1268. s = jmolAppletAddParam(s,"messageCallback", "myFunctionName")
  1269. document.write(s)
  1270. jmolSetDocument(document) // if you want to then write buttons and such normally
  1271. */
  1272. function jmolAppletAddParam(appletCode,name,value){
  1273. if(value == "")return appletCode
  1274. return appletCode.replace(/\<param/,"\n<param name='"+name+"' value='"+value+"' />\n<param")
  1275. }
  1276. ///////////////auto load Research Consortium for Structural Biology (RCSB) data ///////////
  1277. function jmolLoadAjax_STOLAF_RCSB(fileformat,pdbid,optionalscript,targetSuffix){
  1278. if(!_jmol.thismodel)_jmol.thismodel = "1crn"
  1279. if(!_jmol.serverURL)_jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"
  1280. if(!_jmol.RCSBserver)_jmol.RCSBserver="http://www.rcsb.org"
  1281. if(!_jmol.defaultURL_RCSB)_jmol.defaultURL_RCSB=_jmol.RCSBserver+"/pdb/files/1CRN.CIF"
  1282. if(!fileformat)fileformat="PDB"
  1283. if(!pdbid)pdbid=prompt("Enter a 4-digit PDB ID:",_jmol.thismodel)
  1284. if(!pdbid || pdbid.length != 4)return ""
  1285. if(!targetSuffix)targetSuffix="0"
  1286. if(!optionalscript)optionalscript=""
  1287. var url=_jmol.defaultURL_RCSB.replace(/1CRN/g,pdbid.toUpperCase())
  1288. if(fileformat!="CIF")url=url.replace(/CIF/,fileformat)
  1289. _jmol.optionalscript=optionalscript
  1290. _jmol.thismodel=pdbid
  1291. _jmol.thistargetsuffix=targetSuffix
  1292. _jmol.thisurl=url
  1293. _jmol.modelArray = []
  1294. url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)
  1295. _jmolDomScriptLoad(url)
  1296. return url
  1297. }
  1298. /////////////// St. Olaf College AJAX server -- ANY URL ///////////
  1299. function jmolLoadAjax_STOLAF_ANY(url, userid, optionalscript,targetSuffix){
  1300. _jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"
  1301. if(!_jmol.thisurlANY)_jmol.thisurlANY = "http://www.stolaf.edu/depts/chemistry/mo/struc/data/ycp3-1.mol"
  1302. if(!url)url=prompt("Enter any (uncompressed file) URL:", _jmol.thisurlANY)
  1303. if(!userid)userid="0"
  1304. if(!targetSuffix)targetSuffix="0"
  1305. if(!optionalscript)optionalscript=""
  1306. _jmol.optionalscript=optionalscript
  1307. _jmol.thistargetsuffix=targetSuffix
  1308. _jmol.modelArray = []
  1309. _jmol.thisurl = url
  1310. url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)
  1311. _jmolDomScriptLoad(url)
  1312. }
  1313. /////////////// Mineralogical Society of America (MSA) data /////////
  1314. function jmolLoadAjax_MSA(key,value,optionalscript,targetSuffix){
  1315. if(!_jmol.thiskeyMSA)_jmol.thiske

Large files files are truncated, but you can click here to view the full file