// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
wn.ui.IconBar = Class.extend({
init: function(parent, n_groups) {
this.parent = parent;
this.buttons = {};
this.make(n_groups);
},
make: function(n_groups) {
this.$wrapper = $('
').appendTo(this.parent);
for(var i=0; i')
.appendTo(this.$wrapper).find("ul");
return $ul;
},
add_btn: function(group, icon, label, click) {
var $ul = this.get_group(group);
var $li = $('')
.appendTo($ul)
.on("click", function() {
click.apply(this);
return false;
});
$li.find("i").attr("title", label).tooltip();
this.$wrapper.find(".iconbar-" + group).removeClass("hide")
this.show();
return $li;
},
hide: function(group) {
if(group) {
this.$wrapper.find(".iconbar-" + group).addClass("hide");
this.check_if_all_hidden();
} else {
this.$wrapper.addClass("hide").trigger("hidden");
}
},
show: function(group) {
if(group) {
this.$wrapper.find(".iconbar-" + group).removeClass("hide");
this.show();
} else {
if(this.$wrapper.hasClass("hide"))
this.$wrapper.removeClass("hide").trigger("shown");
}
},
clear: function(group) {
var me = this;
this.$wrapper.find(".iconbar-" + group).addClass("hide").find("ul").empty();
this.check_if_all_hidden();
},
check_if_all_hidden: function() {
if(!this.$wrapper.find(".iconbar:visible").length) {
this.hide();
}
}
})