I am using the jQuery Treeview plugin. Have a look to the "Sample 1 - default" provided on the demo page of the plugin http://jquery.bassistance.de/treeview/demo/. In my case all folders and files are links. If I click for example on the expanded "Folder 2" it will first collapse and then follow to the link location. The behaviour I would like to is, that only collapsed ones w开发者_如何转开发ill expand first and if it already expanded it will stay like this.
The code in the plugin (jquery.treeview.js) which toggle the behaviour is the following:
66 this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(event) {
67 toggler.apply($(this).next());
68 }).add( $("a", this) ).hoverClass();
I already figured out how to get all the links, which should be changed:
$('a').parent().parent().filter('.collapsable')
The result will be a array of all li which are currently collapsable (expanded): [li., li.collapsable]
But I don't know how to proceed from there :-( Hopefully someone could help me along...
I already changed sucessfully the linkbehavior for the current selected (class=selected) link with this code:
$(".current").click(function(e){
e.preventDefault();
});
Many thanks in advance!
maybe it was not clear what I really want to do so I will try to improve my verbalization next time ;-)
The answer to my own question is:
$('li').filter('.collapsable').find('a:first:not(.current)').click(function(e){
e.stopImmediatePropagation();
});
Maybe it helps someone who is looking for something similar.
Best regards!!
UPDATE (the posted solution above does not work if the user expanded a node without reloading the page after)
$('a').click(function(e){
if ($(this).is('.current')) {
e.preventDefault();
} else if ($(this).parent().parent().is('.collapsable')) {
e.stopImmediatePropagation();
};
});
This one works as it it supposed to. :-)
精彩评论