[+] BO : Adding Tree Helper
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
var Tree = function (element, options)
|
||||
{
|
||||
this.$element = $(element);
|
||||
this.options = $.extend({}, $.fn.tree.defaults, options);
|
||||
this.init();
|
||||
};
|
||||
|
||||
Tree.prototype =
|
||||
{
|
||||
constructor: Tree,
|
||||
|
||||
init: function ()
|
||||
{
|
||||
this.$element.find("label.tree-toggler").click(
|
||||
function ()
|
||||
{
|
||||
if ($(this).parent().children("ul.tree").is(":visible"))
|
||||
$(this).parent().children(".icon-folder-open")
|
||||
.removeClass("icon-folder-open")
|
||||
.addClass("icon-folder-close");
|
||||
else
|
||||
$(this).parent().children(".icon-folder-close")
|
||||
.removeClass("icon-folder-close")
|
||||
.addClass("icon-folder-open");
|
||||
|
||||
$(this).parent().children("ul.tree").toggle(300);
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
collapseAll : function($speed)
|
||||
{
|
||||
this.$element.find("label.tree-toggler").each(
|
||||
function()
|
||||
{
|
||||
$(this).parent().children(".icon-folder-open")
|
||||
.removeClass("icon-folder-open")
|
||||
.addClass("icon-folder-close");
|
||||
$(this).parent().children("ul.tree").hide($speed);
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
expandAll : function($speed)
|
||||
{
|
||||
this.$element.find("label.tree-toggler").each(
|
||||
function()
|
||||
{
|
||||
$(this).parent().children(".icon-folder-close")
|
||||
.removeClass("icon-folder-close")
|
||||
.addClass("icon-folder-open");
|
||||
$(this).parent().children("ul.tree").show($speed);
|
||||
}
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
$.fn.tree = function (option, value)
|
||||
{
|
||||
var methodReturn;
|
||||
var $set = this.each(
|
||||
function ()
|
||||
{
|
||||
var $this = $(this);
|
||||
var data = $this.data('tree');
|
||||
var options = typeof option === 'object' && option;
|
||||
|
||||
if (!data) $this.data('tree', (data = new Tree(this, options)));
|
||||
if (typeof option === 'string') methodReturn = data[option](value);
|
||||
}
|
||||
);
|
||||
|
||||
return (methodReturn === undefined) ? $set : methodReturn;
|
||||
};
|
||||
|
||||
$.fn.tree.Constructor = Tree;
|
||||
Reference in New Issue
Block a user