Here are steps one could follow to create a Chime tutorial about a
different molecule, using a nonlinear button structure similar to that in
DNATut2. DNATut2 was actually written in a much less organized fashion,
and went through several different approaches before arriving at version 2.
After the fact, I have tried to envision a more organized series of steps
leading to a new tutorial. However I have not tested this method. If you
try it, please let me know where these instructions need improvement.
Each button is defined in dnapairs.htm, but the
scripts for most are generated in b_pairs.js using the
ButtonCallback mechanism described in the section below on implementation.
When debug mode is off, the Strands page does not need the
'immediate button' mechanism (see below) to send to Chime a variable
Chime-script dynamically-generated by javascript. Therefore it does not
need a 'dummy' frame (see below) and hence uses no frames. This page
consists of ordinary HTML including one <embed ...> tag to invoke
Chime, plus one for each button.
The page on Ends (file dna53.htm) was as simple as that
on Strands, but has been modified just enough to support the debug mode.
This required the addition of certain javascript controls. By searching
for the word javascript in this file, you can find all such
instances. With debug mode on, this page needs the 'immediate button'
mechanism, and hence frames are present.
With the exception of this section, the remainder of this document
is unchanged since the original implementation of version 2 of the DNA
tutorial (1997). This section was added in June, 2002, for version 3.
Chime is a Netscape Plugin. This DNA tutorial (and all of my other
Chime Resources) was
originally designed to work in Netscape (Windows or Macintosh).
Later, MDL
adapted Chime to work in Internet Explorer (IE, Windows only). Chime's operation in IE
suffers from a number of bugs and idiosyncracies that differ from
its behavior in Netscape. These are documented in
Protein Explorer (see release
notes under version history for version 1.922), and
those relevant to this DNA tutorial are explained below.
The simple design in dnabones.htm works in IE. That is, embed tags
that specify buttons containing invariant command scripts work in IE, provided
that none of the command scripts reference PDB or script files (see below).
Command scripts can be placed in javascript strings (as explained below)
and sent to Chime. When the DNA tutorial was written in 1996, there was only
one method for doing this, the "immediate-mode button/dummy frame" (IMBIF)
method (see chiimmed.js). Subsequently, a method called LiveConnect was introduced, but this
only worked with Netscape. The IMBIF method used here
works with both Netscape and IE.
The major bug in Chime (2.0.3 or 2.6SP3) in IE is that command script execution
is halted whenever a command references a disk file, e.g. on every "load filename.pdb"
or "script filename.spt" command. Execution of script disk files (filename.spt)
also fails whenever a delay or move command is encountered.
If the only file reference is a "script"
command as the very last command in a script (and if the script file has
no load nor script commands within it), execution may work. However,
subsequent scripts may trigger re-execution of commands from previous scripts.
The safest workaround is to put all scripts into javascript string
variables, and use scriptToChime(script) [defined in chiimmed.js]
to send then to Chime. Delay and move commands work in such scripts;
however, "load" or "script" commands still halt execution.
Therefore, when the PDB file needs to be changed
by some scripts, a special mechanism is required that sends 2 scripts,
one load the PDB file, and a second to render and color the molecule.
This is handled by loadscript(pdbfile, script) defined in chiimmed.js.
In summary, most .spt files were eliminated in version 3. Scripts
converted to javascript strings will be found in files s_pairs.js and
s_code.js. (The original reset.spt is still used in b_pairs.js; this
one didn't seem to cause any problems in IE.)
Some scripts in b_pairs.js are handled differently in IE than in
Netscape (search for isIE), but for the most part, the changes required
for IE are compatible with both Netscape and IE. File n4c2.js was added
to detect IE and set the value of the boolean isIE.
The page on DNA Code (file dnacode.htm) uses the 2X zoom and
1/2X unzoom buttons. In order to prevent these from generating extreme
excursions (which cause various undesirable anomalies), the maximum zoom is
1600% and the minimum, 100%. Maintainence of these limits requires a
javascript variable so that when the button is pushed, the current size is
known. Since the Chime-script (move command) sent to Chime is dynamically
generated by javascript according to the preceding state, the 'immediate
button' mechanism (see below) is needed, and this in turn requires a
'dummy' frame (see below).
The 'zoom' example is only one of several places where javascript is needed
in this page. When this page displays a single base pair, the buttons
labeled End and Replicate must issue different Chime-scripts
than when the DNA helix is displayed. Also, in order for the Reset
button to interrupt a slow movement, an interrupt must be sent to
Chime via the 'immediate mode' (an interrupt fails via the ordinary embed
button mechanism). These requirements necessitate the use of javascript to
generate and send scripts to Chime in the DNA Code page. See the sections
below on
the immediate button mechanism and on
more complex pages for more explanation of how this
works.
The method for sending the dynamically-constructed Chime-script, as a character
string variable, to Chime is as follows. Javascript is used to to write a
new document into a 'dummy' frame which is specified as size 0% of the
window, therefore invisible. (See file fs_code.htm for a definition
of the frameset for the dnacode.htm page.) The new document
contains an <embed...> tag which creates a button for sending a
Chime-script to Chime. This button is very like the many buttons visible in
the tutorial, each of which, when clicked, sends a Chime-script to Chime.
But this button differs in one crucial respect. The embed-tag contains the
parameter immediate=true. This causes the Chime-script to be sent
to Chime immediately, without waiting for the button to be clicked. In
fact, not only is the frame containing this button too small to be
noticable, but the button itself is also hidden. See chiimmed.js, which
creates this embedded button.
Because the Chime-scripts vary, the HTML <embed...> tags,
which create the Chime-script-sending buttons, do not themselves
contain the Chime-scripts. Rather, when a Chime-plugin-targeted
button is clicked, Chime sends the name of the button to
javascript by calling a ButtonCallback function. The name of this
function is specified in the <embed...> tag which creates the
button (see button.js). This function, designed by the user, takes
appropriate action; in this tutorial, it constructs the appropriate
Chime-script and sends it to Chime via an immediate button mechanism. The
ButtonCallback function is bcb() defined in the file
button.js. It is called twice per button-push*. On the second
call, bcb() passes the button name to
bcb_action(), which is defined in the file b_pairs.js. This is
where the variable Chime-scripts are generated for each button.
*The first call is before execution of the Chime-script, if any,
given in the <embed...> tag which created the button.
The second call is afterwards. In NLCS2, the embed tags contain no
Chime-scripts, so the two calls are equivalent. A boolean ButtonCallback
parameter indicates whether the call is before or after; this is used to
avoid issuing each javascript-constructed Chime-script twice. See bcb() in
button.js.
Simpler pages
The page on Strands (file dnabone.htm) has intentionally been
left as simple as possible, to serve as an example. (This required that
the debug mode not be implemented for this page.) In this simplest page,
all the button-invoked Chime-scripts are invariant ones. That is, they
perform exactly the same function regardless of the sequence of button
pushes which preceded them. Therefore, they do not need javascript
conditional tests of state variables, so they are included in-line directly
in the html file. Note the complete absence of javascript in this file. It
so happens that the Chime-scripts in the file dnabone.htm call no
subscript files, another simplification, albeit coincidental.
Internet Explorer Compatibility
Simple Javascript
Chime's 'immediate button' mechanism
The ability to construct a Chime-script dynamically from
javascript code is a powerful one. It allows the Chime-script to be tailored
to the state of the tutorial (see for example
zoom limits above).
More Complex Pages
The page on Base pairs (file dnapairs.htm), is more complex
because both the invocation of Chime and nearly all the button-issued
Chime-scripts are generated by state-variable dependent javascript. The
invocation of Chime depends on whether or not debug-mode has been enabled.
The Chime-scripts issued by most of the buttons change according to the
previous buttons which were clicked, as recorded by javascript state
variables.