Difference between revisions of "Recycling Corner"

From Jmol
Jump to navigation Jump to search
(scripts for toggling spin state)
(Reusable scripts)
Line 24: Line 24:
  
 
=== "Basic" spin toggle ===
 
=== "Basic" spin toggle ===
Quite trivial, but compact and useful. However, if other scripts, controls, or the user change the spin status, the checkbox will need to be reset using javascript.  
+
Quite trivial, but compact and useful. However, if other scripts, controls, or the user change the spin status, the checkbox will need to be reset accordingly using javascript. (''To avoid this limitation, see the "foolproof" solution below'')
  
(''To avoid this limitation, see the "universal" solution below'')
+
It will work with any version of Jmol (as long as <code>Jmol.js</code> is being used in the web page).
 
 
Will work with any version of Jmol (as long as <code>Jmol.js</code> is being used in the web page).
 
  
 
<pre>jmolCheckbox("spin on", "spin off", "spin", false)</pre>
 
<pre>jmolCheckbox("spin on", "spin off", "spin", false)</pre>
if the model is initially not spinning (the default)
+
if the model is initially not spinning (the default);
  
 
or
 
or
 
<pre>jmolCheckbox("spin on", "spin off", "spin", true)</pre>
 
<pre>jmolCheckbox("spin on", "spin off", "spin", true)</pre>
if the model is initially spinning (due to another script)
+
if the model is initially spinning (due to another script).
  
 +
(''The word "spin" above can be changed to any other text you like.'')
  
  
=== "Universal" spin toggle ===
+
=== "Foolproof" spin toggle ===
Works by reading the current spin status from the applet and changing it, so it accounts for any other previous change via script, popup menu, page controls, etc.
+
Reads the current spin status from the applet and changes it, so it can cope with any other previous change via script, popup menu, page controls, etc.
  
 
Only compatible with '''Jmol 11.x''' (as long as <code>Jmol.js</code> is being used in the web page).
 
Only compatible with '''Jmol 11.x''' (as long as <code>Jmol.js</code> is being used in the web page).
  
 
<pre>jmolButton("show spin", "toggle spin")</pre>
 
<pre>jmolButton("show spin", "toggle spin")</pre>
 +
(If you prefer <code>jmolLink</code>, it can be used in the same manner.)
 +
 +
(''The words "toggle spin" above can be changed to any other text you like.'')
  
 
You '''must''' include these additional pieces of code:
 
You '''must''' include these additional pieces of code:
Line 66: Line 68:
 
and somewhere between <code>&lt;script&gt;</code> tags, '''after''' the call to <code>jmolInitialize()</code>  '''and before''' the call to <code>jmolApplet()</code>:
 
and somewhere between <code>&lt;script&gt;</code> tags, '''after''' the call to <code>jmolInitialize()</code>  '''and before''' the call to <code>jmolApplet()</code>:
 
<pre>jmolSetCallback("messageCallback", "messageProcess")</pre>
 
<pre>jmolSetCallback("messageCallback", "messageProcess")</pre>
 +
 +
(''The word "messageProcess" above can be changed to any other text you like, as long as it is the same in the above two sections of code.'')

Revision as of 23:41, 17 January 2007

This section intends to collect material by some users that may be useful to other users.

Feel free to add your material!

For example:

Jmol icons

(.ico files cannot be shown on the webpage, but you can download them)

These are not very good-looking, but something for a start.

File:Jmol75x29x8.ico Windows icon, with just "Jm" taken from Jmol logo. 256 colors, transparent background.

File:Jmol 16 32.ico Windows icon, "J" from Jmol logo, together with a ball&sticks small model. 2 resolutions (16, 32px), 256 colors, transparent background.

Jmol images, graphics or logos

on a separate page


Templates for creating Jmol webpages

Reusable scripts

"Basic" spin toggle

Quite trivial, but compact and useful. However, if other scripts, controls, or the user change the spin status, the checkbox will need to be reset accordingly using javascript. (To avoid this limitation, see the "foolproof" solution below)

It will work with any version of Jmol (as long as Jmol.js is being used in the web page).

jmolCheckbox("spin on", "spin off", "spin", false)

if the model is initially not spinning (the default);

or

jmolCheckbox("spin on", "spin off", "spin", true)

if the model is initially spinning (due to another script).

(The word "spin" above can be changed to any other text you like.)


"Foolproof" spin toggle

Reads the current spin status from the applet and changes it, so it can cope with any other previous change via script, popup menu, page controls, etc.

Only compatible with Jmol 11.x (as long as Jmol.js is being used in the web page).

jmolButton("show spin", "toggle spin")

(If you prefer jmolLink, it can be used in the same manner.)

(The words "toggle spin" above can be changed to any other text you like.)

You must include these additional pieces of code:

Somewhere between <script> tags (recommended: within the head section):

function messageProcess(a,b)
{	a = a.substring("jmolApplet".length)	
        // a will start with "jmolApplet": strip and leave just the ID part
	/*  SPIN DETECTION AND TOGGLE */
	if ( b.indexOf("set spin") != -1 )
	{	if ( b.indexOf("spin on") != -1 ) //was spinning
		{	jmolScript("spin off", a) 
		}
		else //was not spinning
		{ 	jmolScript("spin on", a) 
		}
	}
	/*  END of SPIN DETECTION AND TOGGLE  */
}

and somewhere between <script> tags, after the call to jmolInitialize() and before the call to jmolApplet():

jmolSetCallback("messageCallback", "messageProcess")

(The word "messageProcess" above can be changed to any other text you like, as long as it is the same in the above two sections of code.)