--- loncom/html/adm/jmol/Jmol.js 2007/10/11 00:42:00 1.3 +++ loncom/html/adm/jmol/Jmol.js 2014/08/22 17:57:54 1.4 @@ -1,7 +1,15 @@ +/* Jmol 12.0 script library Jmol.js 5/20/2013 7:34:08 AM Bob Hanson -/* 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 +NOTE: THIS LIBRARY IS DEPRECATED STARTING WITH Jmol 13.0. + IT STILL WORKS (AND ALWAYS WILL, PROBABLY). + PLEASE USE the set JmolCore.js/JmolApplet.js/JmolControls.js/JmolApi.js + WITH OPTIONAL JmolCD.js (ChemDoodle Canvas and Canvas2D options) and JmolJSV.js (JSpecView) + + SEE http://chemapps.stolaf.edu/jmol/files/JmolCore.js for details + SEE http://chemapps.stolaf.edu/jmol/examples-12/simple2.htm for an example + + checkbox heirarchy -- see http://chemapps.stolaf.edu/jmol/docs/examples-11/check.htm based on: * @@ -30,8 +38,10 @@ 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 @@ -45,21 +55,65 @@ try{if(typeof(_jmol)!="undefined")exit() // 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() +// 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 +// 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 "; if (_jmol.debugAlert) alert(t); return _jmolDocumentWrite(t); @@ -151,8 +210,7 @@ function jmolButton(script, label, id, t function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked, labelHtml, isChecked, id, title) { _jmolInitCheck(); - if (id == undefined || id == null) - id = "jmolCheckbox" + _jmol.checkboxCount; + id != undefined && id != null || (id = "jmolCheckbox" + _jmol.checkboxCount); ++_jmol.checkboxCount; if (scriptWhenChecked == undefined || scriptWhenChecked == null || scriptWhenUnchecked == undefined || scriptWhenUnchecked == null) { @@ -166,18 +224,18 @@ function jmolCheckbox(scriptWhenChecked, var indexChecked = _jmolAddScript(scriptWhenChecked); var indexUnchecked = _jmolAddScript(scriptWhenUnchecked); var eospan = "" - var t = "" + ");return true' onmouseout='_jmolMouseOut()' " + + (isChecked ? "checked='true' " : "")+ _jmol.checkboxCssText + " />" if (labelHtml.toLowerCase().indexOf("")>=0) { - t += eospan - eospan = ""; + t += eospan + eospan = ""; } - t += labelHtml +eospan; + t += "" +eospan; if (_jmol.debugAlert) alert(t); return _jmolDocumentWrite(t); @@ -201,12 +259,10 @@ function jmolRadioGroup(arrayOfRadioButt alert("invalid arrayOfRadioButtons"); return; } - if (separatorHtml == undefined || separatorHtml == null) - separatorHtml = "  "; + separatorHtml != undefined && separatorHtml != null || (separatorHtml = "  "); var len = arrayOfRadioButtons.length; jmolStartNewRadioGroup(); - if (!groupName) - groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1); + groupName || (groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1)); var t = ""; for (var i = 0; i < len; ++i) { if (i == len - 1) @@ -238,15 +294,13 @@ function jmolRadio(script, labelHtml, is 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); + id != undefined && id != null || (id = "jmolLink" + _jmol.linkCount); + label != undefined && label != null || (label = script.substring(0, 32)); ++_jmol.linkCount; var scriptIndex = _jmolAddScript(script); - var t = "" + label + ""; if (_jmol.debugAlert) alert(t); @@ -255,24 +309,37 @@ function jmolLink(script, label, id, tit 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; + id != undefined && id != null || (id = "jmolCmd" + _jmol.cmdCount); + label != undefined && label != null || (label = "Execute"); + size != undefined && !isNaN(size) || (size = 60); ++_jmol.cmdCount; - var t = ""; + 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) { + var inputBox = document.getElementById(id) + _jmolScriptExecute(inputBox, inputBox.value, target) + } +} + +function _jmolScriptExecute(element,script,target) { + if (typeof(script) == "object") + script[0](element, script, target) + else if (typeof(script) == "function") + script(target); + else + jmolScript(script, target) +} + function jmolMenu(arrayOfMenuItems, size, id, title) { _jmolInitCheck(); - if (id == undefined || id == null) - id = "jmolMenu" + _jmol.menuCount; + id != undefined && id != null || (id = "jmolMenu" + _jmol.menuCount); ++_jmol.menuCount; var type = typeof arrayOfMenuItems; if (type != null && type == "object" && arrayOfMenuItems.length) { @@ -282,7 +349,7 @@ function jmolMenu(arrayOfMenuItems, size else if (size < 0) size = len; var sizeText = size ? " size='" + size + "' " : ""; - var t = "" + var t = "" if (labelHtml.toLowerCase().indexOf("")>=0) { - t += eospan - eospan = ""; + t += eospan + eospan = ""; } - t += labelHtml +eospan + separatorHtml; + t += "" +eospan + separatorHtml; + return t; } function _jmolFindApplet(target) { // first look for the target in the current window - var applet = _jmolFindAppletInWindow(window, target); + var applet = _jmolFindAppletInWindow(_jmol.appletWindow != null ? _jmol.appletWindow : window, target); // THEN look for the target in child frames if (applet == undefined) applet = _jmolSearchFrames(window, target); @@ -867,7 +1046,7 @@ 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 || alert("could not find applet " + target); _jmol.alerted = true; return null } @@ -876,52 +1055,54 @@ function _jmolSearchFrames(win, target) var applet; var frames = win.frames; if (frames && frames.length) { // look in all the frames below this window + try{ for (var i = 0; i < frames.length; ++i) { applet = _jmolSearchFrames(frames[i], target); if (applet) - break; + return applet; } - } else { // look for the applet in this window - applet = _jmolFindAppletInWindow(win, target) + }catch(e) { + if (_jmol.debugAlert) + alert("Jmol.js _jmolSearchFrames cannot access " + win.name + ".frame[" + i + "] consider using jmolSetAppletWindow()") + } } - return applet; + return applet = _jmolFindAppletInWindow(win, target) } function _jmolFindAppletInWindow(win, target) { var doc = win.document; - // getElementById fails on MacOSX Safari & Mozilla - if (_jmol.useHtml4Object || _jmol.useIEObject) + if (doc.getElementById(target)) return doc.getElementById(target); - else if (doc.applets) + if (doc.applets) return doc.applets[target]; - else - return doc[target]; + return doc[target]; } function _jmolAddScript(script) { - if (! 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 _jmolClick(elementClicked, scriptIndex, targetSuffix) { + _jmol.element = elementClicked; + _jmolScriptExecute(elementClicked, _jmol.scripts[scriptIndex], targetSuffix); } function _jmolMenuSelected(menuObject, targetSuffix) { var scriptIndex = menuObject.value; if (scriptIndex != undefined) { - jmolScript(_jmol.scripts[scriptIndex], targetSuffix); + _jmolScriptExecute(menuObject, _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; + _jmolClick(menuObject[i], menuObject[i].value, targetSuffix); + return; } } } @@ -929,59 +1110,61 @@ function _jmolMenuSelected(menuObject, t } -_jmol.checkboxMasters = new Array(); -_jmol.checkboxItems = new Array(); +_jmol.checkboxMasters = {}; +_jmol.checkboxItems = {}; 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; - } + 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] = {}; + m.chkMaster = chkMaster; + m.chkGroup = {}; + 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]) + //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) - } + //called when a master item is checked + for (var chkBox in m.chkGroup){ + var item = m.chkGroup[chkBox] + if (item.checked != isOn) + item.click(); + if (_jmol.checkboxMasters[item.id]) + _jmolNotifyGroup(_jmol.checkboxMasters[item.id], isOn) + } } function _jmolCbClick(ckbox, whenChecked, whenUnchecked, targetSuffix) { - _jmolClick(ckbox.checked ? whenChecked : whenUnchecked, targetSuffix); + _jmol.control = ckbox + _jmolClick(ckbox, ckbox.checked ? whenChecked : whenUnchecked, targetSuffix); if(_jmol.checkboxMasters[ckbox.id]) - _jmolNotifyGroup(_jmol.checkboxMasters[ckbox.id], ckbox.checked) + _jmolNotifyGroup(_jmol.checkboxMasters[ckbox.id], ckbox.checked) if(_jmol.checkboxItems[ckbox.id]) - _jmolNotifyMaster(_jmol.checkboxItems[ckbox.id]) + _jmolNotifyMaster(_jmol.checkboxItems[ckbox.id]) } function _jmolCbOver(ckbox, whenChecked, whenUnchecked) { @@ -1004,6 +1187,7 @@ function _jmolSetCodebase(codebase) { } function _jmolOnloadResetForms() { + // must be evaluated ONLY once _jmol.previousOnloadHandler = window.onload; window.onload = function() { @@ -1026,10 +1210,11 @@ function _jmolOnloadResetForms() { function _jmolEvalJSON(s,key){ s=s+"" + if(!s)return [] if(s.charAt(0)!="{"){ - if(s.indexOf(" | ")>=0)s=s.replace(/\ \|\ /g, "\n") - return s + if(s.indexOf(" | ")>=0)s=s.replace(/\ \|\ /g, "\n") + return s } var A = eval("("+s+")") if(!A)return @@ -1040,34 +1225,34 @@ function _jmolEvalJSON(s,key){ function _jmolEnumerateObject(A,key){ var sout="" if(typeof(A) == "string" && A!="null"){ - sout+="\n"+key+"=\""+A+"\"" + sout+="\n"+key+"=\""+A+"\"" }else if(!isNaN(A)||A==null){ - sout+="\n"+key+"="+(A+""==""?"null":A) + sout+="\n"+key+"="+(A+""==""?"null":A) }else if(A.length){ - sout+=key+"=new Array()" + sout+=key+"=[]" for(var i=0;i=0;i--)for(var j=0;j=0;) - for(j=0;j< Ret[i].length;j++) - s+=Ret[i][j]+"\n" + for(var i=Ret.length;--i>=0;) + for(var j=0;j< Ret[i].length;j++) + s+=Ret[i][j]+"\n" return s } +function jmolScriptWaitOutput(script, targetSuffix) { + targetSuffix == undefined && (targetSuffix="0") + var ret = "" + try{ + if (script) { + _jmolCheckBrowser(); + var applet=_jmolGetApplet(targetSuffix); + if (applet) ret += applet.scriptWaitOutput(script); + } + }catch(e){ + } + return ret; +} + function jmolEvaluate(molecularMath, targetSuffix) { //carries out molecular math on a model - if(!targetSuffix)targetSuffix="0" + targetSuffix == undefined && (targetSuffix="0") var result = "" + jmolGetPropertyAsJavaObject("evaluate", molecularMath, targetSuffix); var s = result.replace(/\-*\d+/,"") if (s == "" && !isNaN(parseInt(result)))return parseInt(result); @@ -1192,11 +1391,11 @@ function jmolEvaluate(molecularMath, tar function jmolScriptEcho(script, targetSuffix) { // returns a newline-separated list of all echos from a script - if(!targetSuffix)targetSuffix="0" + targetSuffix == undefined && (targetSuffix="0") var Ret=jmolScriptWaitAsArray(script, targetSuffix) var s = "" - for(i=Ret.length;--i>=0;) - for(j=Ret[i].length;--j>=0;) + for(var i=Ret.length;--i>=0;) + for(var j=Ret[i].length;--j>=0;) if (Ret[i][j][1] == "scriptEcho")s+=Ret[i][j][3]+"\n" return s.replace(/ \| /g, "\n") } @@ -1204,11 +1403,11 @@ function jmolScriptEcho(script, targetSu function jmolScriptMessage(script, targetSuffix) { // returns a newline-separated list of all messages from a script, ending with "script completed\n" - if(!targetSuffix)targetSuffix="0" + targetSuffix == undefined && (targetSuffix="0") var Ret=jmolScriptWaitAsArray(script, targetSuffix) var s = "" - for(i=Ret.length;--i>=0;) - for(j=Ret[i].length;--j>=0;) + for(var i=Ret.length;--i>=0;) + for(var j=Ret[i].length;--j>=0;) if (Ret[i][j][1] == "scriptStatus")s+=Ret[i][j][3]+"\n" return s.replace(/ \| /g, "\n") } @@ -1224,7 +1423,7 @@ function jmolScriptWaitAsArray(script, t if (applet) ret += applet.scriptWait(script); ret = _jmolEvalJSON(ret,"jmolStatus") if(typeof ret == "object") - return ret + return ret } }catch(e){ } @@ -1235,13 +1434,13 @@ function jmolScriptWaitAsArray(script, t //////////// save/restore orientation ///////////// -function jmolSaveOrientation(id, targetSuffix) { - if(!targetSuffix)targetSuffix="0" - return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo +function jmolSaveOrientation(id, targetSuffix) { + targetSuffix == undefined && (targetSuffix="0") + return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo } function jmolRestoreOrientation(id, targetSuffix) { - if(!targetSuffix)targetSuffix="0" + targetSuffix == undefined && (targetSuffix="0") var s=_jmol["savedOrientation"+id] if (!s || s == "")return s=s.replace(/1\.0/,"0") @@ -1249,8 +1448,8 @@ function jmolRestoreOrientation(id, targ } function jmolRestoreOrientationDelayed(id, delay, targetSuffix) { - if(arguments.length < 2)delay=1; - if(!targetSuffix)targetSuffix="0" + arguments.length < 2 && (delay=1) + targetSuffix == undefined && (targetSuffix="0") var s=_jmol["savedOrientation"+id] if (!s || s == "")return s=s.replace(/1\.0/,delay) @@ -1266,34 +1465,33 @@ function jmolRestoreOrientationDelayed(i 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\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} - } +if(_jmol.useNoApplet){ + 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) { + // 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) + 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; @@ -1422,10 +1625,50 @@ function jmolResize(w,h) { var width=window.innerWidth - netscapeScrollWidth; var height=window.innerHeight-netscapeScrollWidth; } - var applet = _jmolGetApplet(0); + 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; - applet.style.width = (percentW ? width * percentW/100 : w)+"px" - applet.style.height = (percentH ? height * percentH/100 : h)+"px" - title=width + " " + height + " " + (new Date()) + 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 : "")); } + +