var GreenTreeOpener = Class.create({ initialize: function(nodeId, overlayClass, tree) { this.tree = tree; this.opener = $(nodeId + '_node'); this.plus = $(nodeId + '_plus'); this.minus = $(nodeId + '_minus'); this.children = $(nodeId + '_children'); this.opener.observe('mousedown', this.OnClick.bind(this)); this.open = false; this.Animate(); }, Animate: function() { if (this.open) { this.children.show(); this.minus.show(); this.plus.hide(); } else { this.children.hide(); this.plus.show(); this.minus.hide(); } }, OnClick: function(evt) { this.open = !this.open; this.Animate(); if (this.tree && this.tree.UpdateWidth) this.tree.UpdateWidth(); if (evt && evt.stop) evt.stop(); return false; } }); var GreenTree = Class.create(Tree, { initialize: function($super, nodeId) { this.treeId = nodeId; this.OpenerClass = GreenTreeOpener; $super(nodeId); }, OnResize: function() { this.tree.setStyle({ height: '0px', overflowY: 'hidden' }); var eBF = AControl.GetBoundingFrame(this.tree); // 8px is for margins + 2px is for padding (TODO: remove those spikes) if (eBF) this.tree.setStyle({height: (eBF.offsetHeight<10 ? 0 :eBF.offsetHeight-10) + 'px', overflowY: 'auto'}); this.UpdateWidth(); }, UpdateWidth: function() { for (var i = 0; i < this.nodes.length; ++i) { this.CountWidth(this.nodes[i]); } }, CountWidth: function(id) { var div = $(this.treeId + '_div'); var lbl = $(id + '_label'); var ndiv = $(id); if (!lbl) return; var text = (ndiv.readAttribute("title") || lbl.readAttribute("title")); lbl.innerHTML = text; while (lbl.offsetWidth + lbl.offsetLeft > div.offsetLeft + div.offsetWidth) { if (text.length < 5) break; text = text.substr(0, text.length - 4) + "..."; lbl.innerHTML = text; } }, Select: function(n, selected) { if (selected) $(n).addClassName('Green_treeline_sel'); else $(n).removeClassName('Green_treeline_sel'); for (var i = 0; i < this.nodes.length; ++i) { $(this.nodes[i]).removeClassName('Green_treeline_hover'); } } });