3 Jmol2.js (JSmol version)
\r
4 author: Bob Hanson hansonr@stolaf.edu 5/24/2013 12:06:25 PM
\r
6 Script replacement for legacy Jmol.js that uses JSmol instead.
\r
7 Can be used to turn most legacy Jmol.js-based sites to JSmol.
\r
9 BH 1/16/2014 10:33:46 PM adding serverURL indication, more notes
\r
10 BH 1/13/2014 11:14:12 AM incorrect default for missing jmolInitialize() (should be ".")
\r
11 BH 1/8/2014 5:56:15 AM simplified instructions; removed option for self.Info
\r
12 BH 11/12/2013 6:34:22 AM adds jmolAppletInline()
\r
13 BH 9/23/2013 10:07:16 PM adds set of loadInline functions
\r
14 BH 9/19/2013 7:09:41 AM fixed jmolSetTarget() to accept "0" as a suffix; use of undefined --> null
\r
18 You should not have to change any of your HTML pages.
\r
19 You are going to replace Jmol.js, wherever that is, with this file.
\r
20 You are going to replace all your JAR file with the ones in this distribution.
\r
21 You are going to add about 1000 files in the jsmol/j2s directory to your website.
\r
22 Don't worry; only a few will be called. But you won't know which ones.
\r
23 You will be able to switch from HTML5 to JAVA using ?_USE=SIGNED in the URL
\r
27 1a) If you want to use HTML5, copy all jsmol/j2s/* files into a j2s subdirectory
\r
28 in the directory that contains Jmol.js and your old Jmol jar files.
\r
30 1b) If you are not using HTML5, change the "use" parameter below from "HTML5" to "JAVA" and save this file.
\r
31 Copy all the jsmol/java/* files into the directory containing your current JAR files. This adds
\r
32 four JNLP files as well and will replace all your JAR files.
\r
34 2) Rename your current Jmol.js file Jmol_old.js in case you want to undo this.
\r
36 3) Concatenate Jmol.min.js if you are not using jQuery (or Jmol.min.nojq.js if you are)
\r
37 with this file to form a new file (Jmol.min.js first, then Jmol2.js) and replace your
\r
38 current Jmol.js with it. Note that if you are using your own version of jQuery, it
\r
39 must be version 1.9 or higher, and note that 2.0 or higher will not work with MSIE
\r
40 used locally but accessing remote resources. See http://bugs.jquery.com/ticket/14876
\r
42 4) Try your page and see how it goes. You may still have some problems, because not all of the
\r
43 methods in the original Jmol.js are included here. Let me know if that's the case.
\r
45 If you wish to change the directories your j2s or JAR files and override the default settings
\r
46 (old JAR file location; j2s directory in the directory of those JAR files) and thus override
\r
47 your current settings in your HTML files, then you can to that three ways:
\r
49 a) You can change the parameters below to override what your pages already use by uncommenting
\r
50 one or the other of the jarPath and j2sPath definitions. This will override jmolInitialize
\r
51 in ALL your HTML files.
\r
53 b) You can change your jmolInitialization call in an individual HTML file. This sets both
\r
54 the JAR path and the j2s path (as [jarPath]/j2s) together.
\r
56 c) You can add lines to an individual HTML file along the lines of:
\r
58 Jmol.Info.jarPath = "../../Jmol"
\r
59 Jmol.Info.j2sPath = "../../JSmol"
\r
61 or whatever. This will override jmolInitialize in that specific HTML file only.
\r
65 -- FireFox works great. You will be able to read binary files from your local machine
\r
66 -- Chrome can only read local files if started with the --allow-file-access-from-files flag
\r
67 and even then the files must be ASCII, not binary.
\r
68 -- MSIE and Safari cannot work with local pages
\r
73 // uncomment one or more of these next lines only if you want to override jmolInitialize()
\r
75 //jarFile: "JmolAppletSigned0.jar",
\r
77 use: "HTML5", // could be JAVA or HTML5
\r
78 // the serverURL path is only used to load binary files in Safari, Chrome, and MSIE
\r
79 serverURL: "http://your.server.here/jsmol.php", // required for binary file loading (Spartan, .gz, .map, etc.)
\r
80 disableJ2SLoadMonitor: false,
\r
81 disableInitialConsole: true
\r
85 ////////// private functions /////////////
\r
90 allowedJmolSize: [25, 2048, 300], // min, max, default (pixels)
\r
93 target: "jmolApplet0",
\r
100 radioGroupCount: 0,
\r
101 initialized: false,
\r
102 initChecked: false,
\r
103 archivePath: "JmolAppletSigned0.jar"
\r
106 function _jmolApplet(size, inlineModel, script, nameSuffix) {
\r
107 nameSuffix == null && (nameSuffix = _jmol.appletCount);
\r
108 var id = "jmolApplet" + nameSuffix;
\r
109 jmolSetTarget(nameSuffix);
\r
110 ++_jmol.appletCount;
\r
111 script || (script = "select *");
\r
112 inlineModel && (script = 'load DATA "inline"\n' + inlineModel + '\nEND "inline";' + script);
\r
114 for (var i in Jmol.Info)
\r
115 Info[i] = Jmol.Info[i]
\r
116 Info.jarFile || (Info.jarFile = _jmol.archivePath);
\r
117 Info.jarPath || (Info.jarPath = _jmol.codebase);
\r
118 Info.j2sPath || (Info.j2sPath = Info.jarPath + "/j2s");
\r
119 var sz = _jmolGetAppletSize(size);
\r
120 Info.width || (Info.width = sz[0]);
\r
121 Info.height || (Info.height = sz[1]);
\r
122 Info.script || (Info.script = script);
\r
123 Info.isSigned == null && (Info.isSigned = (Info.jarFile.indexOf("Signed") >= 0));
\r
124 for (var i in _jmol.params)
\r
125 if(_jmol.params[i]!="")
\r
126 Info[i] || (Info[i] = _jmol.params[i]);
\r
127 // alert(JSON.stringify(Info).replace(/\,/g,"\n\n\n\n"))
\r
128 return _jmol.applets[id] = Jmol.getApplet(id, Info)
\r
131 function _jmolGetJarFilename(fileNameOrFlag) {
\r
132 _jmol.archivePath =
\r
133 (typeof(fileNameOrFlag) == "string" ? fileNameOrFlag : (fileNameOrFlag ? "JmolAppletSigned" : "JmolApplet") + "0.jar");
\r
136 ////////////////////////////////////////////////////////////////
\r
137 // Legacy Scripting API
\r
138 ////////////////////////////////////////////////////////////////
\r
140 function jmolSetParameter(key,value) {
\r
141 Jmol.Info[key] = value;
\r
144 function jmolSetXHTML(id) {
\r
148 function jmolSetTranslation(TF) {
\r
152 function jmolInitialize(codebaseDirectory, fileNameOrUseSignedApplet) {
\r
153 if (_jmol.initialized)
\r
155 _jmol.initialized = true;
\r
156 if(_jmol.jmoljar) {
\r
157 var f = _jmol.jmoljar;
\r
158 if (f.indexOf("/") >= 0) {
\r
159 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.")
\r
160 var ok = prompt("Do you want to use applet " + f + "? ","yes or no")
\r
162 codebaseDirectory = f.substring(0, f.lastIndexOf("/"));
\r
163 fileNameOrUseSignedApplet = f.substring(f.lastIndexOf("/") + 1);
\r
165 _jmolGetJarFilename(fileNameOrUseSignedApplet);
\r
166 alert("The web page URL was ignored. Continuing using " + _jmol.archivePath + ' in directory "' + codebaseDirectory + '"');
\r
169 fileNameOrUseSignedApplet = f;
\r
172 _jmol.codebase = codebaseDirectory;
\r
173 _jmolGetJarFilename(fileNameOrUseSignedApplet);
\r
176 function jmolSetDocument(doc) {
\r
177 _jmol.currentDocument = doc;
\r
180 function jmolSetAppletColor(boxbgcolor, boxfgcolor, progresscolor) {
\r
181 Jmol.Info.color = boxbgcolor ? boxbgcolor : "black";
\r
184 function jmolSetAppletWindow(w) {
\r
185 _jmol.appletWindow = w;
\r
188 function jmolApplet(size, script, nameSuffix) {
\r
189 return _jmolApplet(size, null, script, nameSuffix);
\r
192 function jmolAppletInline(size, inlineModel, script, nameSuffix) {
\r
193 return _jmolApplet(size, inlineModel, script, nameSuffix);
\r
198 ////////////////////////////////////////////////////////////////
\r
200 ////////////////////////////////////////////////////////////////
\r
202 function jmolButton(script, label, id, title) {
\r
203 return Jmol.jmolButton(_jmol.target, script, label, id, title);
\r
206 function jmolCheckbox(scriptWhenChecked, scriptWhenUnchecked, labelHtml, isChecked, id, title) {
\r
207 return Jmol.jmolCheckbox(_jmol.target, scriptWhenChecked, scriptWhenUnchecked, labelHtml, isChecked, id, title)
\r
210 function jmolRadioGroup(arrayOfRadioButtons, separatorHtml, groupName, id, title) {
\r
211 return Jmol.jmolRadioGroup(_jmol.target, arrayOfRadioButtons, separatorHtml, groupName, id, title)
\r
215 function jmolRadio(script, labelHtml, isChecked, separatorHtml, groupName, id, title) {
\r
216 return Jmol.jmolRadio(_jmol.target, script, labelHtml, isChecked, separatorHtml, groupName, id, title)
\r
219 function jmolLink(script, label, id, title) {
\r
220 return Jmol.jmolLink(_jmol.target, script, label, id, title)
\r
223 function jmolCommandInput(label, size, id, title) {
\r
224 return Jmol.jmolCommandInput(_jmol.target, label, size, id, title);
\r
227 function jmolMenu(arrayOfMenuItems, size, id, title) {
\r
228 return Jmol.jmolMenu(_jmol.target, arrayOfMenuItems, size, id, title);
\r
231 function jmolHtml(html) {
\r
232 return Jmol._documentWrite(html);
\r
235 function jmolBr() {
\r
236 return Jmol._documentWrite("<br />");
\r
239 ////////////////////////////////////////////////////////////////
\r
240 // advanced scripting functions
\r
241 ////////////////////////////////////////////////////////////////
\r
243 function jmolDebugAlert(enableAlerts) {
\r
248 function jmolLoadInline(model, targetSuffix) {
\r
249 return jmolLoadInlineScript(model, null, targetSuffix, false)
\r
252 function jmolLoadInlineArray(ModelArray, script, targetSuffix) {
\r
253 return jmolLoadInlineScript(ModelArray.join("\n"), script, targetSuffix, false)
\r
256 function jmolAppendInlineArray(ModelArray, script, targetSuffix) {
\r
257 return jmolLoadInlineScript(ModelArray.join("\n"), script, targetSuffix, true)
\r
260 function jmolAppendInlineScript(model, script, targetSuffix) {
\r
261 return jmolLoadInlineScript(model, script, targetSuffix, true)
\r
264 function jmolLoadInlineScript(model, script, targetSuffix, isAppend) {
\r
265 Jmol.script(jmolFindTarget(targetSuffix),
\r
267 + (isAppend ? "APPEND " : "")
\r
268 + "DATA 'mydata'\n" + model.replace(/\"/g,'\\"') + "\nEND 'mydata'\n")
\r
271 function jmolSetTarget(targetSuffix) {
\r
272 targetSuffix == null || (_jmol.targetSuffix = targetSuffix);
\r
273 return _jmol.target = "jmolApplet" + _jmol.targetSuffix;
\r
276 function jmolFindTarget(targetSuffix) {
\r
277 return _jmol.applets[jmolSetTarget(targetSuffix)];
\r
280 function jmolScript(script, targetSuffix) {
\r
281 Jmol.script(jmolFindTarget(targetSuffix), script)
\r
284 function jmolCheckBrowser(action, urlOrMessage, nowOrLater) {
\r
288 ////////////////////////////////////////////////////////////////
\r
289 // Cascading Style Sheet Class support
\r
290 ////////////////////////////////////////////////////////////////
\r
292 function jmolSetAppletCssClass(appletCssClass) {
\r
293 Jmol.setAppletCss(appletCssClass)
\r
296 function jmolSetButtonCssClass(s) {
\r
297 Jmol.setButtonCss(s)
\r
300 function jmolSetCheckboxCssClass(s) {
\r
301 Jmol.setCheckboxCss(s)
\r
304 function jmolSetRadioCssClass(s) {
\r
305 Jmol.setRadioCss(s)
\r
308 function jmolSetLinkCssClass(s) {
\r
312 function jmolSetMenuCssClass(s) {
\r
316 function jmolSetMemoryMb(nMb) {
\r
321 function jmolSetCallback(callbackName,funcName) {
\r
322 //if(!self[funcName])alert(funcName + " is not defined yet in jmolSetCallback")
\r
323 Jmol.Info[callbackName] = funcName
\r
324 //document.title=("jmolSetCallback " + callbackName + "/" + funcName + " must be included in Info definition")
\r
327 function jmolSetSyncId(n) {
\r
328 alert("jmolSetSyncId " + n + " must be included in Info definition")
\r
331 function jmolSetLogLevel(n) {
\r
332 Jmol.script(_jmol.target, "set loglevel " + n)
\r
335 function _jmolGetAppletSize(size, units) {
\r
337 if ( (typeof size) == "object" && size != null ) {
\r
338 width = size[0]; height = size[1];
\r
340 width = height = size;
\r
342 return [_jmolFixDim(width, units), _jmolFixDim(height, units)];
\r
345 function _jmolFixDim(x, units) {
\r
347 return (sx.length == 0 ? (units ? "" : _jmol.allowedJmolSize[2])
\r
348 : sx.indexOf("%") == sx.length-1 ? sx
\r
349 : (x = parseFloat(x)) <= 1 && x > 0 ? x * 100 + "%"
\r
350 : (isNaN(x = Math.floor(x)) ? _jmol.allowedJmolSize[2]
\r
351 : x < _jmol.allowedJmolSize[0] ? _jmol.allowedJmolSize[0]
\r
352 : x > _jmol.allowedJmolSize[1] ? _jmol.allowedJmolSize[1]
\r
353 : x) + (units ? units : ""));
\r
356 //////////user property/status functions/////////
\r
358 function jmolGetStatus(strStatus,targetSuffix){
\r
359 return Jmol.getStatus(jmolFindTarget(targetSuffix), strStatus)
\r
362 function jmolGetPropertyAsArray(sKey,sValue,targetSuffix) {
\r
363 return Jmol.getPropertyAsArray(jmolFindTarget(targetSuffix), sKey, sValue)
\r
366 function jmolGetPropertyAsString(sKey,sValue,targetSuffix) {
\r
367 return Jmol.getPropertyAsString(jmolFindTarget(targetSuffix), sKey, sValue)
\r
370 function jmolGetPropertyAsJSON(sKey,sValue,targetSuffix) {
\r
371 return Jmol.getPropertyAsJSON(jmolFindTarget(targetSuffix), sKey, sValue)
\r
374 function jmolGetPropertyAsJavaObject(sKey,sValue,targetSuffix) {
\r
375 return Jmol.getPropertyAsJavaObject(jmolFindTarget(targetSuffix), sKey, sValue)
\r
378 ///////// synchronous scripting ////////
\r
380 function jmolScriptWait(script, targetSuffix) {
\r
381 return Jmol.scriptWait(jmolFindTarget(targetSuffix), script)
\r
384 function jmolScriptWaitOutput(script, targetSuffix) {
\r
385 return Jmol.scriptWaitOutput(jmolFindTarget(targetSuffix), script)
\r
388 function jmolEvaluate(molecularMath, targetSuffix) {
\r
389 return Jmol.evaluate(jmolFindTarget(targetSuffix), molecularMath)
\r
392 function jmolScriptEcho(script, targetSuffix) {
\r
393 return Jmol.scriptEcho(jmolFindTarget(targetSuffix), script)
\r
397 function jmolScriptMessage(script, targetSuffix) {
\r
398 return Jmol.scriptMessage(jmolFindTarget(targetSuffix), script)
\r
402 function jmolScriptWaitAsArray(script, targetSuffix) {
\r
403 return Jmol.scriptWait(jmolFindTarget(targetSuffix), script)
\r
408 //////////// save/restore orientation /////////////
\r
410 function jmolSaveOrientation(id, targetSuffix) {
\r
411 return Jmol.saveOrientation(jmolFindTarget(targetSuffix), id)
\r
414 function jmolRestoreOrientation(id, targetSuffix) {
\r
415 return Jmol.restoreOrientation(jmolFindTarget(targetSuffix), id)
\r
418 function jmolRestoreOrientationDelayed(id, delay, targetSuffix) {
\r
419 return Jmol.restoreOrientationDelayed(jmolFindTarget(targetSuffix), id, delay)
\r
422 function jmolResizeApplet(size, targetSuffix) {
\r
423 return Jmol.resizeApplet(jmolFindTarget(targetSuffix), size);
\r
427 //////////// add parameter /////////////
\r
429 function jmolAppletAddParam(appletCode,name,value){
\r
430 alert ("use Info to add a parameter: " + name + "/" + value)
\r