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