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.

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
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)
  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. If it's not a link, then data-script attribute will be used.
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

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
addDataScript(element) - read href or data-script (same as bindClickScript)
addURLLoader(element) - load model data from a file specified in a href attribute
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.


On 2012.07.19. 16:50, Robert Hanson wrote:


for example. It think that's basically what you are implementing with your click events.

In menus, how does jQuery handle use of the up/down arrows?
Umm, what menus? I think jQuery has nothing to do with them.

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).



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

form.reset()

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){
    item.reset();
});
This will definitely call reset() on any form element (as in DOM element) that jQuery can find.

Sounding better and better,

If you could work with JmolApi.js and just (for now) create new jQuery implementations of those, it would be great. Then we could make sure they have the same functionality and not have to go through all this again this way. Could you do that? Any reason not to? Why  not just have the very basic essence in the page:


<a id="link1" class="jmol-link">Perform some actions</a>


and then in the onload event one of the following?

Jmol.setScript(jmolApplet0, "link1", "wireframe 0")
Jmol.setScript(jmolApplet0, "link1", "script myscript.spt")
Jmol.setScript(jmolApplet0, "link1", [myfunc, myparam1, myparam2,...])
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!"';
});

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?

Bob

-- 
Gusts Kaksis