--- loncom/html/adm/jmol/Jmol.js 2005/07/01 20:23:42 1.1 +++ loncom/html/adm/jmol/Jmol.js 2007/10/11 00:42:00 1.3 @@ -1,730 +1,1431 @@ -/* $RCSfile: Jmol.js,v $ - * $Author: albertel $ - * $Date: 2005/07/01 20:23:42 $ - * $Revision: 1.1 $ - * - * Copyright (C) 2004 The Jmol Development Team - * - * Contact: jmol-developers@lists.sf.net - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - * 02111-1307 USA. - */ - -// for documentation see www.jmol.org/jslibrary - -var undefined; // for IE 5 ... wherein undefined is undefined - -//////////////////////////////////////////////////////////////// -// Basic Scripting infrastruture -//////////////////////////////////////////////////////////////// - -function jmolInitialize(codebaseDirectory) { - if (_jmol.initialized) { - alert("jmolInitialize() should only be called *ONCE* within a page"); - return; - } - if (! codebaseDirectory) { - alert("codebaseDirectory is a required parameter to jmolInitialize"); - codebaseDirectory = "."; - } - if (codebaseDirectory.indexOf("http://") == 0 || - codebaseDirectory.indexOf("https://") == 0) - alert("codebaseDirectory should be directory relative,\n" + - "not be an absolute URL : " + codebaseDirectory); - else if (codebaseDirectory.charAt(0) == '/') - alert("codebaseDirectory should be directory relative,\n" + - "not relative to the root of the web server : " + codebaseDirectory); - _jmolSetCodebase(codebaseDirectory); - _jmolOnloadResetForms(); - _jmol.initialized = true; -} - -function jmolSetAppletColor(boxbgcolor, boxfgcolor, progresscolor) { - _jmolInitCheck(); - _jmol.boxbgcolor = boxbgcolor; - if (boxfgcolor) - _jmol.boxfgcolor = boxfgcolor - else if (boxbgcolor == "white" || boxbgcolor == "#FFFFFF") - _jmol.boxfgcolor = "black"; - else - _jmol.boxfgcolor = "white"; - if (progresscolor) - _jmol.progresscolor = progresscolor; - if (_jmol.debugAlert) - alert(" boxbgcolor=" + _jmol.boxbgcolor + - " boxfgcolor=" + _jmol.boxfgcolor + - " progresscolor=" + _jmol.progresscolor); -} - -function jmolApplet(size, script, nameSuffix) { - _jmolInitCheck(); - _jmolApplet(size, null, script, nameSuffix); -} - -//////////////////////////////////////////////////////////////// -// Basic controls -//////////////////////////////////////////////////////////////// - -function jmolButton(script, label, id) { - _jmolInitCheck(); - var scriptIndex = _jmolAddScript(script); - if (label == undefined || label == null) - label = script.substring(0, 32); - if (id == undefined || id == null) - id = "jmolButton" + _jmol.buttonCount; - ++_jmol.buttonCount; - var t = ""; - if (_jmol.debugAlert) - alert(t); - document.write(t); -} - -function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked, - labelHtml, isChecked, id) { - _jmolInitCheck(); - if (id == undefined || id == null) - id = "jmolCheckbox" + _jmol.checkboxCount; - ++_jmol.checkboxCount; - if (scriptWhenChecked == undefined || scriptWhenChecked == null || - scriptWhenUnchecked == undefined || scriptWhenUnchecked == null) { - alert("jmolCheckbox requires two scripts"); - return; - } - if (labelHtml == undefined || labelHtml == null) { - alert("jmolCheckbox requires a label"); - return; - } - var indexChecked = _jmolAddScript(scriptWhenChecked); - var indexUnchecked = _jmolAddScript(scriptWhenUnchecked); - var t = "" + - labelHtml; - if (_jmol.debugAlert) - alert(t); - document.write(t); -} - -function jmolRadioGroup(arrayOfRadioButtons, separatorHtml, groupName) { - _jmolInitCheck(); - var type = typeof arrayOfRadioButtons; - if (type != "object" || type == null || ! arrayOfRadioButtons.length) { - alert("invalid arrayOfRadioButtons"); - return; - } - if (separatorHtml == undefined || separatorHtml == null) - separatorHtml = "  "; - var length = arrayOfRadioButtons.length; - var t = ""; - jmolStartNewRadioGroup(); - for (var i = 0; i < length; ++i) { - var radio = arrayOfRadioButtons[i]; - type = typeof radio; - if (type == "object") { - t += _jmolRadio(radio[0], radio[1], radio[2], separatorHtml, groupName); - } else { - t += _jmolRadio(radio, null, null, separatorHtml, groupName); - } - } - if (_jmol.debugAlert) - alert(t); - document.write(t); -} - -function jmolLink(script, text, id) { - _jmolInitCheck(); - if (id == undefined || id == null) - id = "jmolLink" + _jmol.linkCount; - ++_jmol.linkCount; - var scriptIndex = _jmolAddScript(script); - var t = "" + text + ""; - if (_jmol.debugAlert) - alert(t); - document.write(t); -} - -function jmolMenu(arrayOfMenuItems, size, id) { - _jmolInitCheck(); - if (id == undefined || id == null) - id = "jmolMenu" + _jmol.menuCount; - ++_jmol.menuCount; - var type = typeof arrayOfMenuItems; - if (type != null && type == "object" && arrayOfMenuItems.length) { - var length = arrayOfMenuItems.length; - if (typeof size != "number" || size == 1) - size = null; - else if (size < 0) - size = length; - var sizeText = size ? " size='" + size + "' " : ""; - var t = "" + - labelHtml + separatorHtml; -} - -function _jmolFindApplet(target) { - // first look for the target in the current window - var applet = _jmolSearchFrames(window, target); - if (applet == undefined) - applet = _jmolSearchFrames(top, target); // look starting in top frame - return applet; -} - -function _jmolSearchFrames(win, target) { - var applet; - var frames = win.frames; - if (frames && frames.length) { // look in all the frames below this window - for (var i = 0; i < frames.length; ++i) { - applet = _jmolSearchFrames(frames[i++], target); - if (applet) - break; - } - } else { // look for the applet in this window - var doc = win.document; -// getElementById fails on MacOSX Safari & Mozilla - if (doc.applets) - applet = doc.applets[target]; - else - applet = doc[target]; - } - return applet; -} - -function _jmolAddScript(script) { - if (! script) - return 0; - var index = _jmol.scripts.length; - _jmol.scripts[index] = script; - return index; -} - -function _jmolClick(scriptIndex, targetSuffix) { - jmolScript(_jmol.scripts[scriptIndex], targetSuffix); -} - -function _jmolMenuSelected(menuObject, targetSuffix) { - var scriptIndex = menuObject.value; - if (scriptIndex != undefined) { - jmolScript(_jmol.scripts[scriptIndex], targetSuffix); - return; - } - var length = menuObject.length; - if (typeof length == "number") { - for (var i = 0; i < length; ++i) { - if (menuObject[i].selected) { - _jmolClick(menuObject[i].value, targetSuffix); - return; - } - } - } - alert("?Que? menu selected bug #8734"); -} - -function _jmolCbClick(ckbox, whenChecked, whenUnchecked, targetSuffix) { - _jmolClick(ckbox.checked ? whenChecked : whenUnchecked, targetSuffix); -} - -function _jmolCbOver(ckbox, whenChecked, whenUnchecked) { - window.status = _jmol.scripts[ckbox.checked ? whenUnchecked : whenChecked]; -} - -function _jmolMouseOver(scriptIndex) { - window.status = _jmol.scripts[scriptIndex]; -} - -function _jmolMouseOut() { - window.status = " "; - return true; -} - -function _jmolSetCodebase(codebase) { - _jmol.codebase = codebase ? codebase : "."; - if (_jmol.debugAlert) - alert("jmolCodebase=" + _jmol.codebase); -} - -function _jmolOnloadResetForms() { - _jmol.previousOnloadHandler = window.onload; - window.onload = - function() { -// alert("onloadResetForms"); - with (_jmol) { - if (buttonCount+checkboxCount+menuCount+radioCount+radioGroupCount > 0) { - var forms = document.forms; - if (!forms || forms.length == 0) { - alert("
tags seem to be missing\n" + - "Jmol/HTML input controls must be contained " + - "within form tags" -// + "\n\n" + forms + " forms.length=" + forms.length + -// " typeof=" + (typeof forms) - ); - } else { - for (var i = forms.length; --i >= 0; ) - forms[i].reset(); - } - } - if (previousOnloadHandler) - previousOnloadHandler(); - } - } -} - + +/* Jmol 11.0 script library Jmol.js (aka Jmol-11.js) 1:34 AM 3/19/2007 + + checkbox heirarchy -- see http://www.stolaf.edu/academics/jmol/docs/examples-11/check.htm + + based on: + * + * Copyright (C) 2004-2005 Miguel, Jmol Development, www.jmol.org + * + * Contact: hansonr@stolaf.edu + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA. + */ + +// for documentation see www.jmol.org/jslibrary + +try{if(typeof(_jmol)!="undefined")exit() + +// place "?NOAPPLET" on your command line to check applet control action with a textarea + +// bob hanson -- jmolResize(w,h) -- resizes absolutely or by percent (w or h 0.5 means 50%) +// bob hanson -- jmolEvaluate -- evaluates molecular math 8:37 AM 2/23/2007 +// bob hanson -- jmolScriptMessage -- returns all "scriptStatus" messages 8:37 AM 2/23/2007 +// bob hanson -- jmolScriptEcho -- returns all "scriptEcho" messages 8:37 AM 2/23/2007 +// bob hanson -- jmolScriptWait -- 11:31 AM 5/2/2006 +// bob hanson -- remove trailing separatorHTML in radio groups -- 12:18 PM 5/6/2006 +// bob hanson -- adds support for dynamic DOM script nodes 7:04 AM 5/19/2006 +// bob hanson -- adds try/catch for wiki - multiple code passes 7:05 AM 5/19/2006 +// bob hanson -- auto-initiates to defaultdir/defaultjar -- change as desired. +// bob hanson -- adding save/restore orientation w/ and w/o delay 11:49 AM 5/25/2006 +// bob hanson -- adding AjaxJS service 11:16 AM 6/3/2006 +// bob hanson -- fix for iframes not available for finding applet +// bob hanson -- added applet fake ?NOAPPLET URL flag +// bob hanson -- added jmolSetCallback(calbackName, funcName) 3:32 PM 6/13/2006 +// used PRIOR to jmolApplet() or jmolAppletInline() +// added 4th array element in jmolRadioGroup -- title +// added and id around link, checkbox, radio, menu +// fixing AJAX loads for MSIE/Opera-Mozilla incompatibility +// -- renamed Jmol-11.js from Jmol-new.js; JmolApplet.jar from JmolAppletProto.jar +// renamed Jmol.js for Jmol 11 distribution +// -- modified jmolRestoreOrientation() to be immediate, no 1-second delay +// bob hanson -- jmolScriptWait always returns a string -- 11:23 AM 9/16/2006 +// bh -- jmolCommandInput() +// bh -- jmolSetTranslation(TF) -- forces translation even if there might be message callback issues +// bh -- minor fixes suggested by Angel + +var defaultdir = "." +var defaultjar = "JmolApplet.jar" + +var undefined; // for IE 5 ... wherein undefined is undefined + +//////////////////////////////////////////////////////////////// +// Basic Scripting infrastruture +//////////////////////////////////////////////////////////////// + +function jmolInitialize(codebaseDirectory, fileNameOrUseSignedApplet) { + if (_jmol.initialized) { + //alert("jmolInitialize() should only be called *ONCE* within a page"); + return; + } + if (! codebaseDirectory) { + alert("codebaseDirectory is a required parameter to jmolInitialize"); + codebaseDirectory = "."; + } + + if (codebaseDirectory.indexOf("http://") == 0 || + codebaseDirectory.indexOf("https://") == 0) + alert("In general, an absolute URL is not recommended for codebaseDirectory.\n" + + "A directory- or docroot-relative reference is recommended.\n\n" + + "If you need to use an absolute URL (because, for example, the JAR and data\n" + + "files are on another server), then insert a space before\n" + + "\"http\" in your URL to avoid this warning message."); + + _jmolSetCodebase(codebaseDirectory); + _jmolGetJarFilename(fileNameOrUseSignedApplet); + _jmolOnloadResetForms(); + _jmol.initialized = true; +} + +function jmolSetTranslation(TF) { + _jmol.params.doTranslate = ''+TF; +} + +function _jmolGetJarFilename(fileNameOrFlag) { + _jmol.archivePath = + (typeof(fileNameOrFlag) == "string" ? fileNameOrFlag : (fileNameOrFlag ? "JmolAppletSigned" : "JmolApplet") + "0.jar"); +} + +function jmolSetDocument(doc) { + _jmol.currentDocument = doc; +} + +function jmolSetAppletColor(boxbgcolor, boxfgcolor, progresscolor) { + _jmolInitCheck(); + _jmol.params.boxbgcolor = boxbgcolor; + if (boxfgcolor) + _jmol.params.boxfgcolor = boxfgcolor + else if (boxbgcolor == "white" || boxbgcolor == "#FFFFFF") + _jmol.params.boxfgcolor = "black"; + else + _jmol.params.boxfgcolor = "white"; + if (progresscolor) + _jmol.params.progresscolor = progresscolor; + if (_jmol.debugAlert) + alert(" boxbgcolor=" + _jmol.params.boxbgcolor + + " boxfgcolor=" + _jmol.params.boxfgcolor + + " progresscolor=" + _jmol.params.progresscolor); +} + +function jmolApplet(size, script, nameSuffix) { + _jmolInitCheck(); + return _jmolApplet(size, null, script, nameSuffix); +} + +//////////////////////////////////////////////////////////////// +// Basic controls +//////////////////////////////////////////////////////////////// + +function jmolButton(script, label, id, title) { + _jmolInitCheck(); + if (id == undefined || id == null) + id = "jmolButton" + _jmol.buttonCount; + if (label == undefined || label == null) + label = script.substring(0, 32); + ++_jmol.buttonCount; + var scriptIndex = _jmolAddScript(script); + var t = ""; + if (_jmol.debugAlert) + alert(t); + return _jmolDocumentWrite(t); +} + +function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked, + labelHtml, isChecked, id, title) { + _jmolInitCheck(); + if (id == undefined || id == null) + id = "jmolCheckbox" + _jmol.checkboxCount; + ++_jmol.checkboxCount; + if (scriptWhenChecked == undefined || scriptWhenChecked == null || + scriptWhenUnchecked == undefined || scriptWhenUnchecked == null) { + alert("jmolCheckbox requires two scripts"); + return; + } + if (labelHtml == undefined || labelHtml == null) { + alert("jmolCheckbox requires a label"); + return; + } + var indexChecked = _jmolAddScript(scriptWhenChecked); + var indexUnchecked = _jmolAddScript(scriptWhenUnchecked); + var eospan = "" + var t = "" + if (labelHtml.toLowerCase().indexOf("")>=0) { + t += eospan + eospan = ""; + } + t += labelHtml +eospan; + if (_jmol.debugAlert) + alert(t); + return _jmolDocumentWrite(t); +} + +function jmolStartNewRadioGroup() { + ++_jmol.radioGroupCount; +} + +function jmolRadioGroup(arrayOfRadioButtons, separatorHtml, groupName, id, title) { + /* + + array: [radio1,radio2,radio3...] + where radioN = ["script","label",isSelected,"id","title"] + + */ + + _jmolInitCheck(); + var type = typeof arrayOfRadioButtons; + if (type != "object" || type == null || ! arrayOfRadioButtons.length) { + alert("invalid arrayOfRadioButtons"); + return; + } + if (separatorHtml == undefined || separatorHtml == null) + separatorHtml = "  "; + var len = arrayOfRadioButtons.length; + jmolStartNewRadioGroup(); + if (!groupName) + groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1); + var t = ""; + for (var i = 0; i < len; ++i) { + if (i == len - 1) + separatorHtml = ""; + var radio = arrayOfRadioButtons[i]; + type = typeof radio; + if (type == "object") { + 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); + } else { + t += _jmolRadio(radio, null, null, separatorHtml, groupName, (id ? id : groupName)+"_"+i, title); + } + } + t+="" + if (_jmol.debugAlert) + alert(t); + return _jmolDocumentWrite(t); +} + + +function jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) { + _jmolInitCheck(); + if (_jmol.radioGroupCount == 0) + ++_jmol.radioGroupCount; + var t = _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, (id ? id : groupName + "_" + _jmol.radioCount), title ? title : 0); + if (_jmol.debugAlert) + alert(t); + return _jmolDocumentWrite(t); +} + +function jmolLink(script, label, id, title) { + _jmolInitCheck(); + if (id == undefined || id == null) + id = "jmolLink" + _jmol.linkCount; + if (label == undefined || label == null) + label = script.substring(0, 32); + ++_jmol.linkCount; + var scriptIndex = _jmolAddScript(script); + var t = "" + label + ""; + if (_jmol.debugAlert) + alert(t); + return _jmolDocumentWrite(t); +} + +function jmolCommandInput(label, size, id, title) { + _jmolInitCheck(); + if (id == undefined || id == null) + id = "jmolCmd" + _jmol.cmdCount; + if (label == undefined || label == null) + label = "Execute"; + if (size == undefined || isNaN(size)) + size = 60; + ++_jmol.cmdCount; + var t = ""; + if (_jmol.debugAlert) + alert(t); + return _jmolDocumentWrite(t); +} + +function jmolMenu(arrayOfMenuItems, size, id, title) { + _jmolInitCheck(); + if (id == undefined || id == null) + id = "jmolMenu" + _jmol.menuCount; + ++_jmol.menuCount; + var type = typeof arrayOfMenuItems; + if (type != null && type == "object" && arrayOfMenuItems.length) { + var len = arrayOfMenuItems.length; + if (typeof size != "number" || size == 1) + size = null; + else if (size < 0) + size = len; + var sizeText = size ? " size='" + size + "' " : ""; + var t = "" + if (labelHtml.toLowerCase().indexOf("")>=0) { + t += eospan + eospan = ""; + } + t += labelHtml +eospan + separatorHtml; + return t; +} + +function _jmolFindApplet(target) { + // first look for the target in the current window + var applet = _jmolFindAppletInWindow(window, target); + // THEN look for the target in child frames + if (applet == undefined) + applet = _jmolSearchFrames(window, target); + // FINALLY look for the target in sibling frames + if (applet == undefined) + applet = _jmolSearchFrames(top, target); // look starting in top frame + return applet; +} + +function _jmolGetApplet(targetSuffix){ + var target = "jmolApplet" + (targetSuffix ? targetSuffix : "0"); + var applet = _jmolFindApplet(target); + if (applet) return applet + if(!_jmol.alerted)alert("could not find applet " + target); + _jmol.alerted = true; + return null +} + +function _jmolSearchFrames(win, target) { + var applet; + var frames = win.frames; + if (frames && frames.length) { // look in all the frames below this window + for (var i = 0; i < frames.length; ++i) { + applet = _jmolSearchFrames(frames[i], target); + if (applet) + break; + } + } else { // look for the applet in this window + applet = _jmolFindAppletInWindow(win, target) + } + return applet; +} + +function _jmolFindAppletInWindow(win, target) { + var doc = win.document; + // getElementById fails on MacOSX Safari & Mozilla + if (_jmol.useHtml4Object || _jmol.useIEObject) + return doc.getElementById(target); + else if (doc.applets) + return doc.applets[target]; + else + return doc[target]; +} + +function _jmolAddScript(script) { + if (! script) + return 0; + var index = _jmol.scripts.length; + _jmol.scripts[index] = script; + return index; +} + +function _jmolClick(scriptIndex, targetSuffix) { + jmolScript(_jmol.scripts[scriptIndex], targetSuffix); +} + +function _jmolMenuSelected(menuObject, targetSuffix) { + var scriptIndex = menuObject.value; + if (scriptIndex != undefined) { + jmolScript(_jmol.scripts[scriptIndex], targetSuffix); + return; + } + var len = menuObject.length; + if (typeof len == "number") { + for (var i = 0; i < len; ++i) { + if (menuObject[i].selected) { + _jmolClick(menuObject[i].value, targetSuffix); + return; + } + } + } + alert("?Que? menu selected bug #8734"); +} + + +_jmol.checkboxMasters = new Array(); +_jmol.checkboxItems = new Array(); + +function jmolSetCheckboxGroup(chkMaster,chkBox) { + var id = chkMaster; + if(typeof(id)=="number")id = "jmolCheckbox" + id; + chkMaster = document.getElementById(id); + if (!chkMaster)alert("jmolSetCheckboxGroup: master checkbox not found: " + id); + var m = _jmol.checkboxMasters[id] = new Array(); + m.chkMaster = chkMaster; + m.chkGroup = new Array(); + for (var i = 1; i < arguments.length; i++){ + var id = arguments[i]; + if(typeof(id)=="number")id = "jmolCheckbox" + id; + checkboxItem = document.getElementById(id); + if (!checkboxItem)alert("jmolSetCheckboxGroup: group checkbox not found: " + id); + m.chkGroup[id] = checkboxItem; + _jmol.checkboxItems[id] = m; + } +} + +function _jmolNotifyMaster(m){ + //called when a group item is checked + var allOn = true; + var allOff = true; + for (var chkBox in m.chkGroup){ + if(m.chkGroup[chkBox].checked) + allOff = false; + else + allOn = false; + } + if (allOn)m.chkMaster.checked = true; + if (allOff)m.chkMaster.checked = false; + if ((allOn || allOff) && _jmol.checkboxItems[m.chkMaster.id]) + _jmolNotifyMaster(_jmol.checkboxItems[m.chkMaster.id]) +} + +function _jmolNotifyGroup(m, isOn){ + //called when a master item is checked + for (var chkBox in m.chkGroup){ + var item = m.chkGroup[chkBox] + item.checked = isOn; + if (_jmol.checkboxMasters[item.id]) + _jmolNotifyGroup(_jmol.checkboxMasters[item.id], isOn) + } +} + +function _jmolCbClick(ckbox, whenChecked, whenUnchecked, targetSuffix) { + _jmolClick(ckbox.checked ? whenChecked : whenUnchecked, targetSuffix); + if(_jmol.checkboxMasters[ckbox.id]) + _jmolNotifyGroup(_jmol.checkboxMasters[ckbox.id], ckbox.checked) + if(_jmol.checkboxItems[ckbox.id]) + _jmolNotifyMaster(_jmol.checkboxItems[ckbox.id]) +} + +function _jmolCbOver(ckbox, whenChecked, whenUnchecked) { + window.status = _jmol.scripts[ckbox.checked ? whenUnchecked : whenChecked]; +} + +function _jmolMouseOver(scriptIndex) { + window.status = _jmol.scripts[scriptIndex]; +} + +function _jmolMouseOut() { + window.status = " "; + return true; +} + +function _jmolSetCodebase(codebase) { + _jmol.codebase = codebase ? codebase : "."; + if (_jmol.debugAlert) + alert("jmolCodebase=" + _jmol.codebase); +} + +function _jmolOnloadResetForms() { + _jmol.previousOnloadHandler = window.onload; + window.onload = + function() { + with (_jmol) { + if (buttonCount+checkboxCount+menuCount+radioCount+radioGroupCount > 0) { + var forms = document.forms; + for (var i = forms.length; --i >= 0; ) + forms[i].reset(); + } + if (previousOnloadHandler) + previousOnloadHandler(); + } + } +} + +//////////////////////////////////// +/////extensions for getProperty///// +//////////////////////////////////// + + +function _jmolEvalJSON(s,key){ + s=s+"" + if(!s)return [] + if(s.charAt(0)!="{"){ + if(s.indexOf(" | ")>=0)s=s.replace(/\ \|\ /g, "\n") + return s + } + var A = eval("("+s+")") + if(!A)return + if(key && A[key])A=A[key] + return A +} + +function _jmolEnumerateObject(A,key){ + var sout="" + if(typeof(A) == "string" && A!="null"){ + sout+="\n"+key+"=\""+A+"\"" + }else if(!isNaN(A)||A==null){ + sout+="\n"+key+"="+(A+""==""?"null":A) + }else if(A.length){ + sout+=key+"=new Array()" + for(var i=0;ib[0]?-1:0) +} + +function _jmolSortMessages(A){ + if(!A || typeof(A)!="object")return [] + var B = new Array() + for(var i=A.length-1;i>=0;i--)for(var j=0;j=0;) + for(j=0;j< Ret[i].length;j++) + s+=Ret[i][j]+"\n" + return s +} + +function jmolEvaluate(molecularMath, targetSuffix) { + + //carries out molecular math on a model + + if(!targetSuffix)targetSuffix="0" + var result = "" + jmolGetPropertyAsJavaObject("evaluate", molecularMath, targetSuffix); + var s = result.replace(/\-*\d+/,"") + if (s == "" && !isNaN(parseInt(result)))return parseInt(result); + var s = result.replace(/\-*\d*\.\d*/,"") + if (s == "" && !isNaN(parseFloat(result)))return parseFloat(result); + return result; +} + +function jmolScriptEcho(script, targetSuffix) { + // returns a newline-separated list of all echos from a script + if(!targetSuffix)targetSuffix="0" + var Ret=jmolScriptWaitAsArray(script, targetSuffix) + var s = "" + for(i=Ret.length;--i>=0;) + for(j=Ret[i].length;--j>=0;) + if (Ret[i][j][1] == "scriptEcho")s+=Ret[i][j][3]+"\n" + return s.replace(/ \| /g, "\n") +} + + +function jmolScriptMessage(script, targetSuffix) { + // returns a newline-separated list of all messages from a script, ending with "script completed\n" + if(!targetSuffix)targetSuffix="0" + var Ret=jmolScriptWaitAsArray(script, targetSuffix) + var s = "" + for(i=Ret.length;--i>=0;) + for(j=Ret[i].length;--j>=0;) + if (Ret[i][j][1] == "scriptStatus")s+=Ret[i][j][3]+"\n" + return s.replace(/ \| /g, "\n") +} + + +function jmolScriptWaitAsArray(script, targetSuffix) { + var ret = "" + try{ + jmolGetStatus("scriptEcho,scriptMessage,scriptStatus,scriptError",targetSuffix) + if (script) { + _jmolCheckBrowser(); + var applet=_jmolGetApplet(targetSuffix); + if (applet) ret += applet.scriptWait(script); + ret = _jmolEvalJSON(ret,"jmolStatus") + if(typeof ret == "object") + return ret + } + }catch(e){ + } + return [[ret]] +} + + + +//////////// save/restore orientation ///////////// + +function jmolSaveOrientation(id, targetSuffix) { + if(!targetSuffix)targetSuffix="0" + return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo +} + +function jmolRestoreOrientation(id, targetSuffix) { + if(!targetSuffix)targetSuffix="0" + var s=_jmol["savedOrientation"+id] + if (!s || s == "")return + s=s.replace(/1\.0/,"0") + return jmolScriptWait(s,targetSuffix) +} + +function jmolRestoreOrientationDelayed(id, delay, targetSuffix) { + if(arguments.length < 2)delay=1; + if(!targetSuffix)targetSuffix="0" + var s=_jmol["savedOrientation"+id] + if (!s || s == "")return + s=s.replace(/1\.0/,delay) + return jmolScriptWait(s,targetSuffix) +} + +//////////// add parameter ///////////// +/* + * for adding callbacks or other parameters. Use: + + jmolSetDocument(0) + var s= jmolApplet(....) + s = jmolAppletAddParam(s,"messageCallback", "myFunctionName") + document.write(s) + jmolSetDocument(document) // if you want to then write buttons and such normally + + */ + +function jmolAppletAddParam(appletCode,name,value){ + if(value == "")return appletCode + return appletCode.replace(/\\n=0){ + jmolApplet = function(w){ + var s="" + +"
" + +"Applet would be here" + +"

" + +"

" + return _jmolDocumentWrite(s) + } + + _jmolFindApplet = function(){return jmolApplet0} + + jmolApplet0 = { + script: function(script){document.getElementById("fakeApplet").value="\njmolScript:\n"+script} + ,scriptWait: function(script){document.getElementById("fakeApplet").value="\njmolScriptWait:\n"+script} + ,loadInline: function(data,script){document.getElementById("fakeApplet").value="\njmolLoadInline data:\n"+data+"\n\nscript:\n"+script} + } +} + + +/////////////////////////////////////////// + +//new 9:49 AM 3/6/2007: + +//both w and h are optional. +//if either is between 0 and 1, then it is taken as percent/100. +//if either is greater than 1, then it is taken as a size. +function jmolResize(w,h) { + _jmol.alerted = true; + var percentW = (!w ? 100 : w <= 1 && w > 0 ? w * 100 : 0) + var percentH = (!h ? percentW : h <= 1 && h > 0 ? h * 100 : 0) + if (_jmol.browser=="msie") { + var width=document.body.clientWidth; + var height=document.body.clientHeight; + } else { + var netscapeScrollWidth=15; + var width=window.innerWidth - netscapeScrollWidth; + var height=window.innerHeight-netscapeScrollWidth; + } + var applet = _jmolGetApplet(0); + if(!applet)return; + applet.style.width = (percentW ? width * percentW/100 : w)+"px" + applet.style.height = (percentH ? height * percentH/100 : h)+"px" + title=width + " " + height + " " + (new Date()) +} +