Prof. Robert John Lancashire wrote:

Hi all,

may be this is noted somewhere but being new to the list I have not
seen the details....

I want to display 2 different applets on a page and have callbacks to both
of them.
It is suggested that we use jmol.js to handle calls to Jmol but I don't see
where this case is covered anywhere.

It's a closely held secret.

Should I ignore jmol.js and write my own functions or is this something
that will come out in a future release?

No, please don't ingore jmol.js. For the time being, what you need to do
is one of:

(a) modify Jmol.js to your liking, adding the callback parameters you need,

(b) copy _jmolApplet() into a new .js file, modify that, and have the page load that .js file after Jmol.js

(c) use the jmolSetDocument(0) functionality and adjust the returned jmolApplet code yourself. What I do is the following, which ADDS a callback to whatever is returned by jmolApplet()

function getapplet(name, model, codebase, height, width, script, msgcallback,animcallback,pickcallback,loadstructcallback) {
 if (!isinitialized)jmolInitialize(".")
 isinitialized = 1
 jmolSetDocument(0)
 if (model)script = "load " + model + ";" + script
 var s = jmolApplet([width,height], script)
 var sext = ""
 if (msgcallback) {
   sext = "\n<param name='MessageCallback' value='" + msgcallback + "' />"
   s = s.replace(/\<param/, sext + "\n<param")
 }
 if (animcallback) {
sext = "\n<param name='AnimFrameCallback' value='" + animcallback + "' />"
   s = s.replace(/\<param/, sext + "\n<param")
 }
 if (pickcallback) {
   sext = "\n<param name='PickCallback' value='" + pickcallback + "' />"
   s = s.replace(/\<param/, sext + "\n<param")
 }
 if (loadstructcallback) {
sext = "\n<param name='LoadStructCallback' value='" + loadstructcallback + "' />"
   s = s.replace(/\<param/, sext + "\n<param")
 }
 return s
}

As for using multiple applets, the messageCallbacks, for example, will all come to one function. The first parameter returned is the applet name, so your code can respond accordingly. Things to remember:

1) That first parameter returned to your function LOOKS like a string but is NOT A string. It's a Java "String", not a JavaScript "string". ALWAYS ALWAYS add "" to anything you get back from an applet IMMEDIATELY.

function myCallback(appname, message) {
appname=""+appname
message=""+message
}

For example, "appname.indexOf()" may NOT work.

2) There's a minor bug in the current Jmol.js that assigns "null" to the applet name for IE and Opera. This must be fixed if you plan to have callbacks arriving from two Jmol applets, otherwise you won't know which applet sent the callback.
I'm using the (unofficial) Jmol.js version in

http://www.stolaf.edu/people/hansonr/jmol/test/json

to get around this. The only change is the addition of the line:

       "  <param name='name' value='jmolApplet" + nameSuffix + "' />\n" +

in the

   if (useIEObject)

section. It must be that IE does not pass on the <object> name parameter to the applet the way Firefox does. I suppose it treats that one in some special way, like id.

3) callbacks can cause unintended browser crashes and can be platform-dependent. Use at your own risk!

Bob



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to