Reputation: 322
Am trying to add a rel tag to all rels that are empty for jsTree. I have managed to get this to work in jsFiddle, but when trying to apply the same code to the full tree, it does not work (that is, the rel tag still is blank/empty). I grabbed the resulting source code from my tree to use as this example, which is why am confused that the code is not working.
Here is the working jsFiddle version: view here.
Also, would it be possible that if the rel='disabled', to remove or disable the a href so that the link is disabled?
Upvotes: 1
Views: 4940
Reputation: 322
To those curious, I did a couple of things -
I updated in the database for all my links to be specific types (ie, folder) that I wanted disabled. A blank rel tag also worked. If you can't access a database, I also tried the following piece of code that applied to the .bind("before.jstree"):
$('li[rel=""]').attr('rel','disabled');
I applied a bind to the jsTree instance. The following code is what I used,
.bind("before.jstree", function (e, data) {
$('ul li[rel="file"] > a').each(function() {
$(this).contents().unwrap();
});
})
This unwraps the links that have rel="file" (satisfying the need to make nodes unclickable. You can set the rel tag to anything else that you want to have unwrapped.
Edit: I've also made it even simpler, by just disabling single and double-clicking, like so:
.bind("before.jstree", function (e, data) {
$('ul li[rel="file"] > a').each(function() {
$(this).click(false);
$(this).dblclick(false);
});
})
I hope this helps!
Upvotes: 3