// JmolApplet.js -- Jmol._Applet and Jmol._Image
// BH 10/11/2013 7:17:10 AM streamlined and made consistent with JSV and JSME
// BH 7/16/2012 1:50:03 PM adds server-side scripting for image
// BH 8/11/2012 11:00:01 AM adds Jmol._readyCallback for MSIE not in Quirks mode
// BH 8/12/2012 3:56:40 AM allows .min.png to be replaced by .all.png in Image file name
// BH 8/13/2012 6:16:55 PM fix for no-java message not displaying
// BH 11/18/2012 1:06:39 PM adds option ">" in database query box for quick command execution
// BH 12/17/2012 6:25:00 AM change ">" option to "!"
(function (Jmol, document) {
// _Applet -- the main, full-featured, Jmol object
Jmol._Applet = function(id, Info, checkOnly){
window[id] = this;
this._jmolType = "Jmol._Applet" + (Info.isSigned ? " (signed)" : "");
this._isJava = true;
if (checkOnly)
return this;
this._isSigned = Info.isSigned;
this._readyFunction = Info.readyFunction;
this._ready = false;
this._isJava = true;
this._isInfoVisible = false;
this._applet = null;
this._memoryLimit = Info.memoryLimit || 512;
this._canScript = function(script) {return true;};
this._savedOrientations = [];
this._syncKeyword = "Select:";
this._initialize = function(jarPath, jarFile) {
var doReport = false;
if(this._jarFile) {
var f = this._jarFile;
if(f.indexOf("/") >= 0) {
alert("This web page URL is requesting that the applet used be " + f + ". This is a possible security risk, particularly if the applet is signed, because signed applets can read and write files on your local machine or network.");
var ok = prompt("Do you want to use applet " + f + "? ", "yes or no")
if(ok == "yes") {
jarPath = f.substring(0, f.lastIndexOf("/"));
jarFile = f.substring(f.lastIndexOf("/") + 1);
} else {
doReport = true;
}
} else {
jarFile = f;
}
}
this._jarPath = jarPath || ".";
this._jarFile = (typeof(jarFile) == "string" ? jarFile : (jarFile ? "JmolAppletSigned" : "JmolApplet") + "0.jar");
if (doReport)
alert("The web page URL was ignored. Continuing using " + this._jarFile + ' in directory "' + this._jarPath + '"');
Jmol.controls == undefined || Jmol.controls._onloadResetForms();
}
this._create(id, Info);
return this;
}
Jmol._Applet._get = function(id, Info, checkOnly) {
// note that the variable name the return is assigned to MUST match the first parameter in quotes
// applet = Jmol.getApplet("applet", Info)
checkOnly || (checkOnly = false);
Info || (Info = {});
var DefaultInfo = {
color: "#FFFFFF", // applet object background color, as for older jmolSetBackgroundColor(s)
width: 300,
height: 300,
addSelectionOptions: false,
serverURL: "http://chemapps.stolaf.edu/jmol/jsmol/jsmol.php",
defaultModel: "",
script: null,
src: null,
readyFunction: null,
use: "HTML5",//other options include JAVA, WEBGL, and IMAGE
jarPath: "java",
jarFile: "JmolApplet0.jar",
isSigned: false,
j2sPath: "j2s",
coverImage: null, // URL for image to display
coverTitle: "", // tip that is displayed before model starts to load
coverCommand: "", // Jmol command executed upon clicking image
deferApplet: false, // true == the model should not be loaded until the image is clicked
deferUncover: false, // true == the image should remain until command execution is complete
disableJ2SLoadMonitor: false,
disableInitialConsole: false,
debug: false
};
Jmol._addDefaultInfo(Info, DefaultInfo);
Jmol._debugAlert = Info.debug;
if (!Jmol.featureDetection.allowHTML5)Info.use = "JAVA";
//alert(Info.use)
Info.serverURL && (Jmol._serverUrl = Info.serverURL);
var javaAllowed = false;
var applet = null;
var List = Info.use.toUpperCase().split("#")[0].split(" ");
for (var i = 0; i < List.length; i++) {
switch (List[i]) {
case "JAVA":
javaAllowed = true;
if (Jmol.featureDetection.supportsJava())
applet = new Jmol._Applet(id, Info, checkOnly);
break;
case "WEBGL":
applet = Jmol._Applet._getCanvas(id, Info, checkOnly, true);
break;
case "HTML5":
applet = Jmol._Applet._getCanvas(id, Info, checkOnly, false);
break;
case "IMAGE":
applet = new Jmol._Image(id, Info, checkOnly);
break;
}
if (applet != null)
break;
}
if (applet == null) {
if (checkOnly || !javaAllowed)
applet = {_jmolType : "none" };
else if (javaAllowed)
applet = new Jmol._Applet(id, Info);
}
// keyed to both its string id and itself
return (checkOnly ? applet : Jmol._registerApplet(id, applet));
}
Jmol._Applet._getCanvas = function(id, Info, checkOnly, webGL) {
if (webGL && Jmol.featureDetection.supportsWebGL()) {
Jmol._Canvas3D.prototype = Jmol._jsSetPrototype(new Jmol._Applet(id, Info, true));
GLmol.setRefresh(Jmol._Canvas3D.prototype);
return new Jmol._Canvas3D(id, Info, "Jmol", checkOnly);
}
if (!webGL) {
Jmol._Canvas2D.prototype = Jmol._jsSetPrototype(new Jmol._Applet(id, Info, true));
return new Jmol._Canvas2D(id, Info, "Jmol", checkOnly);
}
return null;
};
/* AngelH, mar2007:
By (re)setting these variables in the webpage before calling Jmol.getApplet(),
a custom message can be provided (e.g. localized for user's language) when no Java is installed.
*/
Jmol._Applet._noJavaMsg =
"You do not have Java applets enabled in your web browser, or your browser is blocking this applet. \
Check the warning message from your browser and/or enable Java applets in \
your web browser preferences, or install the Java Runtime Environment from www.java.com";
Jmol._Applet._noJavaMsg2 =
"You do not have the \
Java Runtime Environment \
installed for applet support. \
Visit www.java.com";
Jmol._Applet._setCommonMethods = function(proto) {
proto._showInfo = Jmol._Applet.prototype._showInfo;
proto._search = Jmol._Applet.prototype._search;
proto._readyCallback = Jmol._Applet.prototype._readyCallback;
}
Jmol._Applet._createApplet = function(applet, Info, params, myClass) {
if (Jmol._syncedApplets.length)
params.synccallback = "Jmol._mySyncCallback";
params.java_arguments = "-Xmx" + Math.round(Info.memoryLimit || applet._memoryLimit) + "m";
applet._initialize(Info.jarPath, Info.jarFile);
// size is set to 100% of containers' size, but only if resizable.
// Note that resizability in MSIE requires:
//
var w = (applet._containerWidth.indexOf("px") >= 0 ? applet._containerWidth : "100%");
var h = (applet._containerHeight.indexOf("px") >= 0 ? applet._containerHeight : "100%");
var widthAndHeight = " style=\"width:" + w + ";height:" + h + "\" ";
var tHeader, tFooter;
if (Jmol.featureDetection.useIEObject || Jmol.featureDetection.useHtml4Object) {
params.archive = applet._jarFile;
if (applet._startupScript)
params.script = applet._startupScript;
params.mayscript = 'true';
params.codebase = applet._jarPath;
params.code = myClass + ".class";
tHeader =
"