I think I got it, although it has less to do with Jmol than 
HTML/JavaScrip in general. My approach for tree based checkbox groups 
usually consists of list elements, though when a checkbox gets checked, 
I search for parent -> find input of type checkbox and set them as 
checked like this:

HTML:

<ul id="checkboxgroup">
   <li><input type="checkbox" id="someoption" value="1" /><label 
for="someoption">This is master</label>
     <ul>
       <li><input type="checkbox" id="child1" value="2" /><label 
for="child1">This is child 1</label></li>
       <li><input type="checkbox" id="child2" value="3" /><label 
for="child2">This is child 2</label></li>
     </ul></li>
</ul>

jQuery way:

$('#checkboxgroup :checkbox').change(function(e){
   var is_checked = $(this).is(':checked');
   $(this).parent().find(':checkbox').each(function(i, input){
     $(input).attr('checked', 'checked');
   });
});

native JavaScript approach would be one hell of a long source code :)

So I think if it's properly built in HTML, it would be easy to implement 
a method in my Jmol.js library. Of course the other approach is also 
possible:

function setCheckboxGroup(master, childs){
   $(master).change(function(e){
     $(childs).each(function(i, input){
       $(input).attr('checked', 'checked');
     });
   });
}

That way, it does not matter where those checkboxes are placed in DOM 
tree. Also, i didn't add any code here that would perform default 
checkbox scripting actions on Jmol.

On 2012.08.06. 13:17, Angel Herráez wrote:
> (following a specific isuue of [Jmol-developers] new jQuery plug-in )
>
> Hi Gusts
>
> Sorry I'm not being able to closely follow the discussion on this jQuery 
> plugin
> development. Too deep for me ;)
>
> Regarding the use of checkbox groups, I don't think I have a proper sample
> page. This was implemented by Sergio Ceroni and then included in Jmol.js,
> but I think it really has no big mistery, it's simple javascript for a 
> convenience.
>
> Documentation is at
> http://jmol.sourceforge.net/jslibrary/#jmolSetCheckboxGroup
>
> and the source is in Jmol.js
>
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Jmol-developers mailing list
> Jmol-developers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jmol-developers


-- 
Gusts Kaksis


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Jmol-developers mailing list
Jmol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-developers

Reply via email to