On Thu, Jul 19, 2012 at 11:51 AM, Gusts Kaksis <gusts.kaksis@gmail.com> wrote:
Hi, Bob!

I put together a little example on the same development PC (http://dev.gusc.lv/code/jmol/simple2.html) and documented it in the source. It's not a JmolApi.js replacement yet, but there are some new ideas I wanted you to look at and give me some feedback.

Basically, there is a Jmol class, that can be initialized like this var my_jmol = new Jmol(placeholder, options); Where placeholder can be anything - either jQuery selector or document.getElementById('some_div'); And then you can call those other methods on my_jmol. Like my_jmol.addScript(element, script_source); This gives the same opportunity of multiple instances as your solution, except for the need of bringing jmol reference all around as it's stored already internally.

How does one then specify which applet of several is being targeted? Is that part of the initialization with the placeholder, basically? What's the role of the placeholder, exactly? Not where the applet is to appear, or is it?

Method summary:

1st level methods - for hardcore developers :)

addEventListener(event_name, callback) - add a listener to Jmol  events (currently: hover, pick, measure, load, animate, resize)
removeEventListener(event_name, callback) - remove listener

So then these transmit the appropriate set xxxCallback calls to Jmol via applet.script()? Presumably now you can have multiple functions instead of just one that is a listener? Or is it still 1:1?

script(script_source) - execute a script. Same as Jmol.script() in your solution

2nd level methods - abstract jQuery bind() methods and some element type checkings

bindClickScript(element, options) - bind a script to some element that can receive click events. Options here can be many things:
  a) a script source as a string
  b) a callback funciton that returns script source as a string (I followed your advice and added those 2 parameters - Jmol object and the clicked element itself - in that order)

And the function parameters. Third parameter, perhaps. This is very useful, because it allows one function to process clicks from a variety of elements and conditions.

  c) nothing - in that case if it's a link and it has a href attribute, that is not '#' or does not start with 'javascript:' will perform as a script loader.

"script loader"? To me "script" and "load" are apples and oranges. You mean it will load a model or set of models with parameters, or run a script?

If it's not a link, then data-script attribute will be used.

What's the significance of the difference there? Say, between a button and an anchor?
bindChangeScript(element, options, options_off) - used for checkboxes, radio buttons and selects. options_off is only for checkbox and if it's not specified data-script-reset will be looked up in attributes

good -- where options can be a script or a function call, with parameters, right?

3rd level methods - shorthand methods abstracting over bindClickScript()

addScript(element, script_source) - simply add a script on click for an element
addCallbackScript(element, callback) - same, just with a callback method

"callback" meaning from jQuery or from Jmol?
addDataScript(element) - read href or data-script (same as bindClickScript)
addURLLoader(element) - load model data from a file specified in a href attribute

Are all these distinctions necessary? A simple script in each case should be able to handle any of this.
addAJAXLoader(element) - same as previous, just use AJAX and call "load inline" in Jmol - actually this might be a great alternative for signed applet. Just a thought.

Well, not really. The thing is, we can't depend upon XHR2 because it's just not out there reliably and won't be for several years, probably. So one needs either a server-side app (jmolcd2.php) or the signed applet.

By "load inline" you probably mean the LOAD DATA statement. You should never call applet.loadInline() anymore. It's not thread-safe.
Sorry,  I meant <select> elements.
I think, jQuery has nothing under the hood for that - just plain-default behavior. Or do you have some specific needs, then, I think, something can be done (probably).

I mean moving up and down a selection set using the up/down arrow keys. If that isn't handled properly, the selection box gets out of sync, because it's not a click. I'm pretty sure Jmol handles this properly; at least I do it on my pages usually, but I have to resort to timeouts to do it right. I was wondering if that had been handled gracefully in jQuery.


One thing I can see useful with jQuery is that we often have use for form resets. Very annoying when a page is reloaded and the controls are not reset.
Umm ... $('input, select, textarea').val(''); should do the trick.

That's too specific. The way it "used" to be done is


This is what Jmol does right now automatically if you have included your objects in a <form> wrapper. I know that sounds terribly antiquated, but form.reset() is particularly useful.
And form resets thing in jQuery can be done like this:
$('form').each(function(i, item){

Why not just do



With this demo I've made it would look like this:

var my_jmol = new Jmol(...something something...);
my_jmol.addScript('#link1', 'wireframe 0');
my_jmol.addScript('#link1', 'script myscript.spt');
my_jmol.addScript('#link1', function(jmol, el){
  return 'echo "yes!"';


Yes, that sounds good. In my implementation, where you can have 

jmol = Jmol.getApplet("jmol",....)

jmol is a new Jmol._applet(), so that's basically the same thing, I think.

Some of the more sophisticated aspects of Jmol objects, such as linked 2D rendering and information panels would be nice to plug in here. As well as all the 2D and WebGL options. If you could build from JmolCore and mostly provide a new jQuery-based interface (replacing JmolApi but not all the Jmol objects), that would be more sensible, it seems to me. Can't we do that? I hate to see you recreate all this from scratch.

Still not sure how that would work for selects or check boxes...

Q: Is it pretty simple to set up checkbox groups in jQuery? JmolApi makes that relatively easy.
Not sure what you mean by that. Do you have some demo, that I could look at, to see it in real world situation?

Angél Herráez probably does.  It's been a while since I looked at that. Basically you click one "master" box off and all its boxes in sub-levels are unchecked as well. Hierarchically.


Robert M. Hanson
Larson-Anderson Professor of Chemistry
Chair, Chemistry Department
St. Olaf College
Northfield, MN

If nature does not answer first what we want,
it is better to take what answer we get.

-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900