Bob Hanson wrote:

> I should point out, though, that neither of these really checks the
> validation for this page. In this case the page is produced by
> browser-based JavaScript, so true validation requires validating the
> FINAL "rendered" HTML, not just the <script> tags. (This is mentioned in
> the XHTML specs.)

I've mentioned this on the list before; but in general, if
you're trying to move onto XHTML (which I thoroughly
approve of) then Jmol.js is no use. (This is not intended as
a complaint, just a warning to anyone considering heading
in that direction)

If you're using Jmol.js currently & it's working for you, then
your browser is still working in "tag-soup" HTML mode, and
not XHTML (even if your source is fully xhtml strict and 
declared). Try changing the mime-type you're serving the pages
with to "application/xhtml+xml", and you'll find everything
fails.

This is because if the browser is working in xhtml mode, you
*cannot* use document.write() to add to the page (if you did,
how could the browser ensure that everything you fed it was
well-formed?). Any document.write() calls will cause JS 
exceptions.

Instead, you must append tags as DOM nodes using the javascript 
DOM interface. (This causes complications if you're trying to
output static html as Jmol.js does, since there may not be a 
complete DOM tree available at that point.)

What I do for my pages is the following: where I want a jmol
applet to be available, I have this:

<div id="parent_id">
  <input type="button" value="Activate Jmol viewer" 
onclick="javascript:toggleJmol([400,400],&quot;parent_id&quot;)">
  <applet style="display:none;"/>
</div>

with toggleJmol defined as:

      function toggleJmol(sz, parentId) {
        // Grab parent node of structure we'll manipulate
        var parentNode = document.getElementById(parentId);
        // Find the applet & div nodes to be used.
        for (child = parentNode.firstChild; child != null; child = 
child.nextSibling) {
          switch(child.localName) {
            case 'input' :
              var inputNode = child;
              break;
            case 'applet' :
              var appNode = child;
              break;
          }
        }
        // and toggle:
        if (appNode.hasChildNodes()) {
          var newAppNode = 
document.createElementNS('http://www.w3.org/1999/xhtml','applet');
          var newMessage = 'Activate Jmol viewer';
        }
        else {
          cmlNode.setAttribute('xmlns:cml', 
'http://www.xml-cml.org/schema/CML2/Core');
          var newAppNode = jmolAppletNew(sz, filename, nameSuffix=parentId);
          var newMessage = 'Deactivate Jmol viewer';
        }
        parentNode.replaceChild(newAppNode, appNode);
        inputNode.setAttribute('value', newMessage);
      }

where jmolAppletNew works through the DOM interface, so instead
of document.write() calls, the following sort of thing is done:

    var app; 
    var p;
    app = document.createElementNS('http://www.w3.org/1999/xhtml','applet');
    app.setAttribute('name', 'jmolApplet' + nameSuffix);
    app.setAttribute('id', 'jmolApplet' + nameSuffix);
    app.setAttribute('code', 'JmolApplet');
    app.setAttribute('archive', archivePath);
    app.setAttribute('codebase', codebase);
    app.setAttribute('width', sz[0]);
    app.setAttribute('height', sz[1]);
    app.setAttribute('mayscript', true);
    p = document.createElementNS('http://www.w3.org/1999/xhtml','param');
    p.setAttribute('name', 'progressbar');
    p.setAttribute('value', 'true');
    app.appendChild(p);

etc., etc.



-- 
Dr. Toby White 
Dept. of Earth Sciences, Downing Street, Cambridge CB2 3EQ. UK
Email: <[EMAIL PROTECTED]>
Tel: +44 1223 333464
Fax: +44 1223 333450


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to