I have a JSP page that creates a treeview using jQuery treeview plugin. Now I want to make the single files selectable, that means I want to open a url when a file is clicked. I tried several example but non of them worked. This is an example html page:
<ul id="browser" class="filetree">
<li><span class="folder">Folder 1</span>
<ul>
<li><span class="file">Item 1.1</span></li>
</ul>
</li>
<li><span class="folder">Folder 2</span>
<ul>
<li><span class="folder">Subfolder 2.1</span>
<ul id="folder21">
<li><span class="file">File 2.1.1</span></li>
<li><span class="file">File 2.1.2</span></li>
</ul>
</li>
<li><span class="file">File 2.2</span></li>
</ul>
</li>
<li class="closed"><span class="folder">Folder 3 (closed at start)</span>
<ul>
<li><span class="file">File 3.1</span></li>
</ul>
</li>
<li><span class="file">File 4</span></li>
</ul>
JavaScript:
<script type="text/javascript">
$(document).ready(function(){
$("#browser").treeview({
toggle: function() {
console.log("%s was toggled.", $(this).find(">span").text());
alert("do something");
}
});
// fourth example
$("#black, #gray").treeview({
control: "#treecontrol",
persist: "cookie",
//cookieId: "treeview-black"
});
});
</script>
How can I implement this?
Hiya demo here : ) http://jsfiddle.net/yeMy9/1/ && http://jsfiddle.net/yeMy9/2/ (only triggers when you click items not the folders. or http://jsfiddle.net/yeMy9/3/
Now I have put the alert when you click the items inside the folder like Item 1.1 etc… and you can use conditional statement to decide base on where to fwd it.
Cheers and I am sure this will helps!
Jquery Code
HTML