$.fn.extend({
treed: function (o) {
var openedClass = 'fa-folder-open';
var closedClass = 'fa-folder';
if (typeof o != 'undefined'){
if (typeof o.openedClass != 'undefined'){
openedClass = o.openedClass;
}
if (typeof o.closedClass != 'undefined'){
closedClass = o.closedClass;
}
};
var tree = $(this);
tree.addClass("tree");
tree.find('li').has("ul").each(function () {
var branch = $(this);
var classes = openedClass + " " + closedClass;
branch.prepend("<i class='indicator fa " + closedClass + "'></i>");
if(branch.find('li').hasClass('active')){
$(this).toggleFolder(classes);
}
branch.addClass('branch');
branch.on('click', function (e) {
if (this == e.target) {
$(this).toggleFolder(classes);
}
})
branch.children().children().toggle();
});
tree.find('.branch .indicator').each(function(){
$(this).on('click', function () {
$(this).closest('li').click();