simonexmachina / jquery-bonsai

Super lightweight jQuery tree plugin
http://simonwade.me/jquery-bonsai
MIT License
148 stars 42 forks source link

Pre-processing hook or event? #27

Open deenfoxx opened 8 years ago

deenfoxx commented 8 years ago

Thank you for the lightweight solution for trees... jsTree was just way too bloated for what we need.

However, is there an easy way to hook when a node is clicked? I DID make it work, by hard-coding the following into qubit, but is there a better way? The following is what I am currently doing:

At line 10, in the "Qubit" constructor, after "this.scope = $(el);"...

// Required to keep track of the key-state since key state is not sent to "change" event.
this.multiple = false;
$(document.body).on('keyup keydown', function(e) {
    self.multiple = e.shiftKey || e.ctrlKey || e.altKey || e.metaKey;
});

At (what was originally) line 30, in the "process" method/function, after "this.suspendListeners = true;"...

// If it is not a multiple and we checked the box, clear all checkboxes, then put back this check.
if (!self.multiple && checkbox.prop('checked')) {
    this.scope.find('input[type=checkbox]').each(function() {
        self.setChecked($(this), false);
    });
    self.setChecked(checkbox, true);
}