📄 jmol.js
字号:
szX + ";" + szY + ";" +
// why doesn't this vertical-align work?
"text-align:center;vertical-align:middle;'>\n" +
noJavaMsg +
"</p>";
} else {
visitJava =
"<table bgcolor='yellow'><tr>" +
"<td align='center' valign='middle' " + widthAndHeight + "><font color='black'>\n" +
noJavaMsg2 +
"</font></td></tr></table>";
}
params.loadInline = (inlineModel ? inlineModel : "");
params.script = (script ? _jmolSterilizeScript(script) : "");
var t = tHeader + _jmolParams() + visitJava + tFooter;
jmolSetTarget(nameSuffix);
ready["jmolApplet" + nameSuffix] = false;
if (_jmol.debugAlert)
alert(t);
return _jmolDocumentWrite(t);
}
}
function _jmolParams() {
var t = "";
for (i in _jmol.params)
if(_jmol.params[i]!="")
t+=" <param name='"+i+"' value='"+_jmol.params[i]+"' />\n";
return t
}
function _jmolInitCheck() {
if (_jmol.initChecked)
return;
_jmol.initChecked = true;
jmolInitialize(defaultdir, defaultjar)
}
function _jmolCheckBrowser() {
with (_jmol) {
if (browserChecked)
return;
browserChecked = true;
if (isFullyCompliant)
return true;
if (checkBrowserAction == "redirect")
location.href = checkBrowserUrlOrMessage;
else if (checkBrowserAction == "popup")
_jmolPopup(checkBrowserUrlOrMessage);
else {
var msg = checkBrowserUrlOrMessage;
if (msg == null)
msg = "Your web browser is not fully compatible with Jmol\n\n" +
"browser: " + browser +
" version: " + browserVersion +
" os: " + os +
"\n\n" + ua;
alert(msg);
}
}
return false;
}
function _jmolDocumentWrite(text) {
if (_jmol.currentDocument)
_jmol.currentDocument.write(text);
return text;
}
function _jmolPopup(url) {
var popup = window.open(url, "JmolPopup",
"left=150,top=150,height=400,width=600," +
"directories=yes,location=yes,menubar=yes," +
"toolbar=yes," +
"resizable=yes,scrollbars=yes,status=yes");
if (popup.focus)
poup.focus();
}
function _jmolReadyCallback(name) {
if (_jmol.debugAlert)
alert(name + " is ready");
_jmol.ready["" + name] = true;
}
function _jmolSterilizeScript(script) {
var inlineScript = script.replace(/'/g, "'");
if (_jmol.debugAlert)
alert("script:\n" + inlineScript);
return inlineScript;
}
function _jmolSterilizeInline(model) {
var inlineModel =
model.replace(/\r|\n|\r\n/g, "|").replace(/'/g, "'");
if (_jmol.debugAlert)
alert("inline model:\n" + inlineModel);
return inlineModel;
}
/* AngelH, mar2007:
By (re)setting this variable in the webpage before calling jmolApplet(), limits for applet size can be overriden.
*/
/* hansonr, jun2007:
2048 standard for GeoWall (http://geowall.geo.lsa.umich.edu/home.html)
*/
if (allowedJmolSize==undefined) var allowedJmolSize = [1, 2048, 300] // min, max, default (pixels)
function _jmolGetAppletSize(size) {
/* AngelH, mar2007
Accepts single number or 2-value array, each one can be either:
percent (text string ending %), decimal 0 to 1 (percent/100), number, or text string (interpreted as nr.)
Size is now returned as string or number, no "px".
*/
var width, height;
if ( (typeof size) == "object" && size != null ) {
width = size[0]; height = size[1];
} else {
width = height = size;
}
// if percent, leave it as it is:
if ( width.toString().charAt(width.toString().length-1) != "%" ) {
width = parseFloat(width); // convert to nr., or strip text, or make zero
if ( width <= 1 && width > 0 ) { width = (width*100)+"%" } // decimal: convert to percent and quit
else if ( width >= allowedJmolSize[0] && width <= allowedJmolSize[1] ) { width = parseInt(width) } // accept only that range (pixels)
else { width = allowedJmolSize[2] } // default size 300 pixels
}
if ( height.toString().charAt(height.toString().length-1) != "%" ) {
height = parseFloat(height);
if ( height <= 1 && height > 0 ) { height = (height*100)+"%" }
else if ( height >= allowedJmolSize[0] && height <= allowedJmolSize[1] ) { height = parseInt(height) }
else { height = allowedJmolSize[2] }
}
return [width, height];
}
function _jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
++_jmol.radioCount;
if (groupName == undefined || groupName == null)
groupName = "jmolRadioGroup" + (_jmol.radioGroupCount - 1);
if (!script)
return "";
if (labelHtml == undefined || labelHtml == null)
labelHtml = script.substring(0, 32);
if (! separatorHtml)
separatorHtml = "";
var scriptIndex = _jmolAddScript(script);
var eospan = "</span>"
var t = "<span id=\"span_"+id+"\""+(title ? " title =\"" + title + "\"":"")+"><input name='"
+ groupName + "' id='"+id+"' type='radio' onClick='_jmolClick(" +
scriptIndex + _jmol.targetText + ");return true;' onMouseover='_jmolMouseOver(" +
scriptIndex + ");return true;' onMouseout='_jmolMouseOut()' " +
(isChecked ? "checked " : "") + _jmol.radioCssText + "/>"
if (labelHtml.toLowerCase().indexOf("<td>")>=0) {
t += eospan
eospan = "";
}
t += "<label for=\"" + id + "\">" + labelHtml + "</label>" +eospan + separatorHtml;
return t;
}
function _jmolFindApplet(target) {
// first look for the target in the current window
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);
// 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
try{
for (var i = 0; i < frames.length; ++i) {
applet = _jmolSearchFrames(frames[i], target);
if (applet)
return applet;
}
}catch(e) {
if (_jmol.debugAlert)
alert("Jmol.js _jmolSearchFrames cannot access " + win.name + ".frame[" + i + "] consider using jmolSetAppletWindow()")
}
}
return applet = _jmolFindAppletInWindow(win, target)
}
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, elementClicked) {
_jmol.element = elementClicked;
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 = {};
_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] = {};
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])
}
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) {
_jmol.control = ckbox
_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() {
// must be evaluated ONLY once
_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+"=[]"
for(var i=0;i<A.length;i++){
sout+="\n"
if(typeof(A[i]) == "object"||typeof(A[i]) == "array"){
sout+=_jmolEnumerateObject(A[i],key+"["+i+"]")
}else{
sout+=key+"["+i+"]="+(typeof(A[i]) == "string" && A[i]!="null"?"\""+A[i].replace(/\"/g,"\\\"")+"\"":A[i])
}
}
}else{
if(key != ""){
sout+=key+"={}"
key+="."
}
for(var i in A){
sout+="\n"
if(typeof(A[i]) == "object"||typeof(A[i]) == "array"){
sout+=_jmolEnumerateObject(A[i],key+i)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -