Difference between revisions of "Jmol JavaScript Object/Legacy"

From Jmol
Jump to navigation Jump to search
(Converting legacy web pages -> new subpage)
 
m (Converting the oldest Jmol pages that used the <applet> syntax)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Converting legacy web pages to JSmol ==
 
== Converting legacy web pages to JSmol ==
 +
__TOC__
  
=== Converting pages from Jmol to JSmol ===
+
=== Overview ===
 
It is not hard to convert pages that used the Jmol Applet to use the HTML5 versions of JSmol. The basic sequence includes:
 
It is not hard to convert pages that used the Jmol Applet to use the HTML5 versions of JSmol. The basic sequence includes:
  
Line 16: Line 17:
 
Or you can modify your page source code to use the new format. Or, easiest solution, use the 'adapter' library described below.
 
Or you can modify your page source code to use the new format. Or, easiest solution, use the 'adapter' library described below.
  
 +
=== Table of equivalence old vs. new functions ===
 
The main methods formerly implemented in {{file|Jmol.js}} (and more!) have now [[Jmol_JavaScript_Object/Functions|equivalent functions]] that can be found in [{{SVN JSmol Trunk}}jsmoljs/JSmolApi.js JSmolApi.js]
 
The main methods formerly implemented in {{file|Jmol.js}} (and more!) have now [[Jmol_JavaScript_Object/Functions|equivalent functions]] that can be found in [{{SVN JSmol Trunk}}jsmoljs/JSmolApi.js JSmolApi.js]
 
-- also included in the distribution: {{file|jsmol.zip}} > {{folder|js}} > {{file|JSmolApi.js}}
 
-- also included in the distribution: {{file|jsmol.zip}} > {{folder|js}} > {{file|JSmolApi.js}}
You might consider taking this opportunity to find out how jQuery works, if you are not familiar with it, and work more with those functions.
+
 
 +
{| class="wikitable"
 +
|-
 +
! Legacy (Jmol.js) !! New (JSmol.min.js)
 +
|- style="text-align:center; font-style:italic;"
 +
| [[Jmol_JavaScript_Object/Legacy/Jmol_Js|documentation]] || [[Jmol_JavaScript_Object/Functions|documentation]]
 +
|-
 +
| jmolInitialize || properties of the <code>Info</code> variable
 +
|-
 +
| jmolApplet || Jmol.getApplet or Jmol.getAppletHtml
 +
|-
 +
| jmolButton || Jmol.jmolButton
 +
|-
 +
| jmolLink || Jmol.jmolLink
 +
|-
 +
| jmolCheckbox || Jmol.jmolCheckbox
 +
|-
 +
| jmolRadioGroup || Jmol.jmolRadioGroup or Jmol.jmolRadio
 +
|-
 +
| jmolMenu || Jmol.jmolMenu
 +
|-
 +
| jmolSetAppletColor || <code>color</code> property of the <code>Info</code> variable, or use the <code>background</code> command in a script
 +
|-
 +
| jmolResizeApplet || Jmol.resizeApplet
 +
|-
 +
| jmolHtml || Jmol.jmolHtml
 +
|-
 +
| jmolBr || Jmol.jmolBr
 +
|-
 +
| jmolScript || Jmol.script
 +
|-
 +
| jmolScriptWait || Jmol.scriptWait, but you should consider using Jmol.evaluateVar instead
 +
|-
 +
| jmolScriptWaitAsArray || Jmol.scriptWaitAsArray
 +
|-
 +
| jmolCommandInput || Jmol.jmolCommandInput
 +
|-
 +
| jmolSaveOrientation || use Jmol.script with <code>save orientation</code> command
 +
|-
 +
| jmolRestoreOrientation || use Jmol.script with <code>restore orientation</code> command
 +
|-
 +
| jmolRestoreOrientationDelayed || use Jmol.script with <code>restore orientation</code> command
 +
|-
 +
| jmolSetDocument || Jmol.setDocument, usually in combination with Jmol.getAppletHtml
 +
|}
  
 
=== Conversion using the Jmol2.js 'adapter' library ===
 
=== Conversion using the Jmol2.js 'adapter' library ===
 
What has been just described (i.e., writing custom functions that allow to keep using the old calls as used with Jmol.js) has been implemented in a special new Jmol2.js 'adapter' library. If you use this, you can leave your existing calls to jmolApplet(), jmolButton(), jmolLink() etc. You just need to:
 
What has been just described (i.e., writing custom functions that allow to keep using the old calls as used with Jmol.js) has been implemented in a special new Jmol2.js 'adapter' library. If you use this, you can leave your existing calls to jmolApplet(), jmolButton(), jmolLink() etc. You just need to:
  
<table>
+
{|
<tr>
+
|-
<th>method A:
+
! method A: !! method B:
</th>
+
|- style="vertical-align: top;"
<th>method B:
+
|
</th>
+
* ''Step 1:''
</tr>
 
<tr>
 
<td>
 
* ''Step 1''
 
 
** In all your pages, add a call to {{file|JSmol.min.js}}
 
** In all your pages, add a call to {{file|JSmol.min.js}}
 
** In all your pages, change the existing call to {{file|Jmol.js}} into {{file|Jmol2.js}}
 
** In all your pages, change the existing call to {{file|Jmol.js}} into {{file|Jmol2.js}}
</td>
+
|
<td>
+
* ''Step 1:''
* ''Step 1''
 
 
** Open in a text editor both {{file|JSmol.min.js}}, {{file|Jmol2.js}} and a new blank document. Combine in this document the contents of {{file|JSmol.min.js}} followed by the contents of {{file|Jmol2.js}}. Save this new document as {{file|Jmol.js}}  
 
** Open in a text editor both {{file|JSmol.min.js}}, {{file|Jmol2.js}} and a new blank document. Combine in this document the contents of {{file|JSmol.min.js}} followed by the contents of {{file|Jmol2.js}}. Save this new document as {{file|Jmol.js}}  
 
** Do not change your pages, keep the existing call to {{file|Jmol.js}}
 
** Do not change your pages, keep the existing call to {{file|Jmol.js}}
</td>
+
|- style="vertical-align: top;"
</tr>
+
|
<tr>
 
<td>
 
 
* ''Step 2:''
 
* ''Step 2:''
 
** Add the JSmol files and folders as appropriate &dagger;
 
** Add the JSmol files and folders as appropriate &dagger;
</td>
+
|
<td>
 
 
* ''Step 2:''
 
* ''Step 2:''
 
** Add the JSmol files and folders as appropriate &dagger;
 
** Add the JSmol files and folders as appropriate &dagger;
</td>
+
|}
</tr>
+
 
</table>
+
(&dagger;) That is described in the Installation and Initialization sections of [[Jmol JavaScript Object|this page]].
(&dagger;) That is described in the Installation and Initialization sections of this page.
 
  
 
For more details, read inside the Jmol2.js file itself.
 
For more details, read inside the Jmol2.js file itself.
Line 63: Line 100:
  
 
=== Upgrading Jmol without using JSmol ===
 
=== Upgrading Jmol without using JSmol ===
 +
''Note: since suport for Java applets is being removed from all major browsers, this procedure will most likely not work any more.''
  
If you have a "legacy" site that uses Jmol.js, and you would prefer to stick with Java and just upgrade your site so that it still works, then all you have to do is the following:
+
If you have a legacy site that uses Jmol.js, and you would prefer to stick with Java and just upgrade your site so that it still works, then all you have to do is the following:
  
 
* Download the latest [http://sourceforge.net/projects/jmol/files Jmol ZIP file distribution].
 
* Download the latest [http://sourceforge.net/projects/jmol/files Jmol ZIP file distribution].
Line 72: Line 110:
  
 
Everything should work as before, but users will see a much kinder, more welcoming warning message the first time they access the new applet. Of course they will still have to give permission for the applet to be run, maybe in several dialogs. Please be aware that most users will not be able to see Jmol applets in their browser.
 
Everything should work as before, but users will see a much kinder, more welcoming warning message the first time they access the new applet. Of course they will still have to give permission for the applet to be run, maybe in several dialogs. Please be aware that most users will not be able to see Jmol applets in their browser.
 +
 +
== Converting the oldest Jmol pages that used the &lt;applet&gt; syntax ==
 +
 +
The very ancient syntax (dating up to 2006 at least) for including Jmol Java applets in web pages used the html <code><applet></code> tag for both the Jmol panels and the buttons acting on them.
 +
Both were embedded in the page by using just the JmolApplet.jar file and specific applet tags.
 +
:[[Jmol JavaScript Object/Legacy/Applet Tags|A description of the old applet syntax]].
 +
 +
Of course, with time web browsers abandoned the use of embedded Java applets and hence Jmol, then JSmol, evolved to new syntaxes, first with the use of the <code>Jmol.js</code> library (to facilitate the insertion of applets as such or as embed tags) and later with the <code>JSmol.min.js</code> library and its accessory files (to switch to fully html5-compliant objects instead of applets).
 +
 +
So there are old pages that used the <code><applet></code> tags, and here is a method to resuscitate them without rewriting all their code to new JSmol syntax, just by adding calls to two JavaScript files. You only need the standard files composing the JSmol library (included in downloadable Jmol distribution) and an additional adapter file: {{file|convertJmolApplets.js}}.
 +
 +
'''Instructions:'''
 +
 +
In the folder that contains your pages (or elsewhere if you adjust the paths), add these items extracted from the {{file|jsmol.zip}} package which is, in turn, contained in the downloaded distribution of Jmol:
 +
* the whole {{folder|j2s}} folder
 +
* the whole {{folder|php}} folder
 +
* the {{file|JSmol.min.js}} file
 +
* the 'adapter' library, {{file|convertJmolApplets.js}} (extracted from [[:File:ConvertJmolApplets.zip|this zipfile]])
 +
 +
Then, in the <code>head</code> section of your page, include the calls to both js files, something like this:
 +
<script src="JSmol.min.js"></script>
 +
<script src="convertJmolApplets.js"></script>
 +
 +
That's all ! <br>Save the modified page and test it in the web browser.
 +
If you need help, do not hesitate to contact the jmol-users list or [[User:AngelHerraez|AngelHerraez]] ([[User talk:AngelHerraez|talk]])

Latest revision as of 08:44, 28 August 2022

Converting legacy web pages to JSmol

Overview

It is not hard to convert pages that used the Jmol Applet to use the HTML5 versions of JSmol. The basic sequence includes:

  • Switching from File icon.gifJmol.js to File icon.gifJSmol.min.js
  • Adding the Folder icon.gifj2s folder/directory to your website.
  • Setting parameters in the Info variable.
  • Modifying function calls from the format jmolXxxx(..., appletExtension) to Jmol.jmolXxxx(appletID, ...) (see below). Depending upon the magnitude of the problem, you may want to write (but read the next section first!) a set of JavaScript functions that allow you to keep your page source code unchanged. For example, if you use the simplest form of jmolButton, the converting function would be:
function jmolButton(script, label) {
  Jmol.jmolButton(myJmol, script, label)
}

Or you can modify your page source code to use the new format. Or, easiest solution, use the 'adapter' library described below.

Table of equivalence old vs. new functions

The main methods formerly implemented in File icon.gifJmol.js (and more!) have now equivalent functions that can be found in JSmolApi.js -- also included in the distribution: File icon.gifjsmol.zip > Folder icon.gifjs > File icon.gifJSmolApi.js

Legacy (Jmol.js) New (JSmol.min.js)
documentation documentation
jmolInitialize properties of the Info variable
jmolApplet Jmol.getApplet or Jmol.getAppletHtml
jmolButton Jmol.jmolButton
jmolLink Jmol.jmolLink
jmolCheckbox Jmol.jmolCheckbox
jmolRadioGroup Jmol.jmolRadioGroup or Jmol.jmolRadio
jmolMenu Jmol.jmolMenu
jmolSetAppletColor color property of the Info variable, or use the background command in a script
jmolResizeApplet Jmol.resizeApplet
jmolHtml Jmol.jmolHtml
jmolBr Jmol.jmolBr
jmolScript Jmol.script
jmolScriptWait Jmol.scriptWait, but you should consider using Jmol.evaluateVar instead
jmolScriptWaitAsArray Jmol.scriptWaitAsArray
jmolCommandInput Jmol.jmolCommandInput
jmolSaveOrientation use Jmol.script with save orientation command
jmolRestoreOrientation use Jmol.script with restore orientation command
jmolRestoreOrientationDelayed use Jmol.script with restore orientation command
jmolSetDocument Jmol.setDocument, usually in combination with Jmol.getAppletHtml

Conversion using the Jmol2.js 'adapter' library

What has been just described (i.e., writing custom functions that allow to keep using the old calls as used with Jmol.js) has been implemented in a special new Jmol2.js 'adapter' library. If you use this, you can leave your existing calls to jmolApplet(), jmolButton(), jmolLink() etc. You just need to:

method A: method B:
  • Step 1:
    • In all your pages, add a call to File icon.gifJSmol.min.js
    • In all your pages, change the existing call to File icon.gifJmol.js into File icon.gifJmol2.js
  • Step 1:
    • Open in a text editor both File icon.gifJSmol.min.js, File icon.gifJmol2.js and a new blank document. Combine in this document the contents of File icon.gifJSmol.min.js followed by the contents of File icon.gifJmol2.js. Save this new document as File icon.gifJmol.js
    • Do not change your pages, keep the existing call to File icon.gifJmol.js
  • Step 2:
    • Add the JSmol files and folders as appropriate †
  • Step 2:
    • Add the JSmol files and folders as appropriate †

(†) That is described in the Installation and Initialization sections of this page.

For more details, read inside the Jmol2.js file itself.

Locations to get File icon.gifJmol2.js :

Upgrading Jmol without using JSmol

Note: since suport for Java applets is being removed from all major browsers, this procedure will most likely not work any more.

If you have a legacy site that uses Jmol.js, and you would prefer to stick with Java and just upgrade your site so that it still works, then all you have to do is the following:

  • Download the latest Jmol ZIP file distribution.
  • Extract all the File icon.gifJmolAppletSigned0*.jar files in the Folder icon.gifapplet directory (you should not be using the File icon.gifJmolApplet0*.jar files any more, unless you are certain what you are doing, since the unsigned applet will be blocked in browsers).
  • Use the most recent version of Jmol.js that you have, or retrieve it from St. Olaf.
  • Upgrade your site's Jmol.js and your JAR files with the files you have extracted.

Everything should work as before, but users will see a much kinder, more welcoming warning message the first time they access the new applet. Of course they will still have to give permission for the applet to be run, maybe in several dialogs. Please be aware that most users will not be able to see Jmol applets in their browser.

Converting the oldest Jmol pages that used the <applet> syntax

The very ancient syntax (dating up to 2006 at least) for including Jmol Java applets in web pages used the html <applet> tag for both the Jmol panels and the buttons acting on them. Both were embedded in the page by using just the JmolApplet.jar file and specific applet tags.

A description of the old applet syntax.

Of course, with time web browsers abandoned the use of embedded Java applets and hence Jmol, then JSmol, evolved to new syntaxes, first with the use of the Jmol.js library (to facilitate the insertion of applets as such or as embed tags) and later with the JSmol.min.js library and its accessory files (to switch to fully html5-compliant objects instead of applets).

So there are old pages that used the <applet> tags, and here is a method to resuscitate them without rewriting all their code to new JSmol syntax, just by adding calls to two JavaScript files. You only need the standard files composing the JSmol library (included in downloadable Jmol distribution) and an additional adapter file: File icon.gifconvertJmolApplets.js.

Instructions:

In the folder that contains your pages (or elsewhere if you adjust the paths), add these items extracted from the File icon.gifjsmol.zip package which is, in turn, contained in the downloaded distribution of Jmol:

  • the whole Folder icon.gifj2s folder
  • the whole Folder icon.gifphp folder
  • the File icon.gifJSmol.min.js file
  • the 'adapter' library, File icon.gifconvertJmolApplets.js (extracted from this zipfile)

Then, in the head section of your page, include the calls to both js files, something like this:

<script src="JSmol.min.js"></script>
<script src="convertJmolApplets.js"></script>

That's all !
Save the modified page and test it in the web browser. If you need help, do not hesitate to contact the jmol-users list or AngelHerraez (talk)

Contributors

AngelHerraez