/* Jmol 11.7 script library Jmol.js 12:17 AM 4/20/2009 Bob Hanson
checkbox heirarchy -- see http://chemapps.stolaf.edu/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
// place "?JMOLJAR=xxxxx" to use a specific jar file
// bob hanson -- jmolResize(w,h) -- resizes absolutely or by percent (w or h 0.5 means 50%)
// angel herraez -- update of jmolResize(w,h,targetSuffix) so it is not tied to first applet
// 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
// bh -- adds jmolSetSyncId() and jmolGetSyncId()
// bh 3/2008 -- adds jmolAppendInlineScript() and jmolAppendInlineArray()
// bh 3/2008 -- fixes IE7 bug in relation to jmolLoadInlineArray()
// bh 6/2008 -- adds jmolSetAppletWindow()
// Angel H. 6/2008 -- added html "
var t = ""
if (labelHtml.toLowerCase().indexOf("
")>=0) {
t += eospan
eospan = "";
}
t += "" +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 _jmolCommandKeyPress(e, id, target) {
var keycode = (window.event ? window.event.keyCode : e ? e.which : 0);
if (keycode == 13) {
jmolScript(document.getElementById(id).value, target)
}
}
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 = ""
var t = ""
if (labelHtml.toLowerCase().indexOf("
"
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}
}
}
///////////////////////////////////////////
// This should no longer be needed, jmolResizeApplet() is better; kept for backwards compatibility
/*
Resizes absolutely (pixels) or by percent of window (w or h 0.5 means 50%).
targetSuffix is optional and defaults to zero (first applet in page).
Both w and h are optional, but needed if you want to use targetSuffix.
h defaults to w
w defaults to 100% of window
If either w or h is between 0 and 1, then it is taken as percent/100.
If either w or h is greater than 1, then it is taken as a size (pixels).
*/
function jmolResize(w,h,targetSuffix) {
_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(targetSuffix);
if(!applet)return;
applet.style.width = (percentW ? width * percentW/100 : w)+"px";
applet.style.height = (percentH ? height * percentH/100 : (h ? h : w))+"px";
//title=width + " " + height + " " + (new Date());
}
// 13 Jun 09 -- makes jmolResize() obsolete (kept for backwards compatibility)
function jmolResizeApplet(size,targetSuffix) {
// See _jmolGetAppletSize() for the formats accepted as size [same used by jmolApplet()]
// Special case: an empty value for width or height is accepted, meaning no change in that dimension.
_jmol.alerted = true;
var applet = _jmolGetApplet(targetSuffix);
if(!applet)return;
var sz = _jmolGetAppletSize(size, "px");
sz[0] && (applet.style.width = sz[0]);
sz[1] && (applet.style.height = sz[1]);
}
function _jmolGetAppletSize(size, units) {
/* Accepts single number or 2-value array, each one can be one of:
percent (text string ending %), decimal 0 to 1 (percent/100), number, or text string (interpreted as nr.)
[width, height] array of strings is returned, with units added if specified.
Percent is relative to container div or element (which should have explicitly set size).
*/
var width, height;
if ( (typeof size) == "object" && size != null ) {
width = size[0]; height = size[1];
} else {
width = height = size;
}
return [_jmolFixDim(width, units), _jmolFixDim(height, units)];
}
function _jmolFixDim(x, units) {
var sx = "" + x;
return (sx.length == 0 ? (units ? "" : _jmol.allowedJmolSize[2])
: sx.indexOf("%") == sx.length-1 ? sx
: (x = parseFloat(x)) <= 1 && x > 0 ? x * 100 + "%"
: (isNaN(x = Math.floor(x)) ? _jmol.allowedJmolSize[2]
: x < _jmol.allowedJmolSize[0] ? _jmol.allowedJmolSize[0]
: x > _jmol.allowedJmolSize[1] ? _jmol.allowedJmolSize[1]
: x) + (units ? units : ""));
}