/* $RCSfile: Jmol.js,v $ * $Author: albertel $ * $Date: 2005/07/05 14:11:47 $ * $Revision: 1.2 $ * * 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(); } } }