2 var stpicopen = '../../../../images/slimtree/folder.gif';
3 var stpicclose = '../../../../images/slimtree/folderopen.gif';
5 var stpicopen = '../opac/images/slimtree/folder2.gif';
6 var stpicclose = '../opac/images/slimtree/folderopen2.gif';
7 var stpicblank = '../opac/images/slimtree/page.gif';
8 var stpicline = '../opac/images/slimtree/line.gif';
9 var stpicjoin = '../opac/images/slimtree/join.gif';
10 var stpicjoinb = '../opac/images/slimtree/joinbottom.gif';
13 var stimgopen = elem('img',{src:stpicopen,border:0});
14 var stimgclose = elem('img',{src:stpicclose,border:0});
15 var stimgblank = elem('img',{src:stpicblank,border:0});
16 var stimgline = elem('img',{src:stpicline,border:0});
17 var stimgjoin = elem('img',{src:stpicjoin,border:0, style:'display:inline;'});
19 function _apc(root,node) { root.appendChild(node); }
21 function SlimTree(context, handle, rootimg) {
22 this.context = context;
24 this.cache = new Object();
26 this.rootimg = elem('img',
27 {src:rootimg,border:0,style:'padding-right: 4px;'});
30 SlimTree.prototype.addCachedChildren = function(pid) {
32 while( child = this.cache[pid].shift() )
33 this.addNode( child.id, child.pid,
34 child.name, child.action, child.title );
35 this.cache[pid] = null;
38 SlimTree.prototype.addNode = function( id, pid, name, action, title, cls ) {
40 if( pid != -1 && !$(pid)) {
41 if(!this.cache[pid]) this.cache[pid] = new Array();
43 {id:id,pid:pid,name:name,action:action,title:title });
48 action='javascript:'+this.handle+'.toggle("'+id+'");';
50 var div = elem('div',{id:id});
51 var topdiv = elem('div',{style:'vertical-align:middle'});
52 var link = elem('a', {id:'stlink_' + id});
53 var actionref = elem('a',{href:action}, name);
54 var contdiv = elem('div',{id:'stcont_' + id});
56 if(cls) addCSSClass(actionref, cls);
58 actionref.setAttribute('href',action);
59 if(title) actionref.setAttribute('title',title);
60 else actionref.setAttribute('title',name);
63 _apc(topdiv,actionref);
70 _apc(this.context,div);
71 if(this.rootimg) _apc(link,this.rootimg.cloneNode(true));
72 else _apc(link,stimgblank.cloneNode(true));
76 if(pid == this.rootid) this.open(pid);
78 $(pid).setAttribute('haschild','1');
79 _apc(link,stimgblank.cloneNode(true));
80 div.style.paddingLeft = '18px';
81 div.style.backgroundImage = 'url('+stpicjoinb+')';
82 div.style.backgroundRepeat = 'no-repeat';
83 _apc($('stcont_' + pid), div);
84 if (div.previousSibling) stMakePaths(div);
86 if(this.cache[id]) this.addCachedChildren(id);
89 function stMakePaths(div) {
90 _apc(div.previousSibling.firstChild,stimgjoin.cloneNode(true));
91 _apc(div.previousSibling.firstChild,div.previousSibling.firstChild.firstChild);
92 _apc(div.previousSibling.firstChild,div.previousSibling.firstChild.firstChild);
93 div.previousSibling.firstChild.firstChild.style.marginLeft = '-18px';
94 div.previousSibling.style.backgroundImage = 'url('+stpicline+')';
95 div.previousSibling.style.backgroundRepeat = 'repeat-y';
98 SlimTree.prototype.expandAll = function() { this.flex(this.rootid, 'open'); }
99 SlimTree.prototype.closeAll = function() { this.flex(this.rootid,'close'); }
100 SlimTree.prototype.flex = function(id, type) {
101 if(type=='open') this.open(id);
102 else { if (id != this.rootid) this.close(id); }
103 var n = $('stcont_' + id);
104 for( var c = 0; c != n.childNodes.length; c++ ) {
105 var ch = n.childNodes[c];
106 if(ch.nodeName.toLowerCase() == 'div') {
107 if($(ch.id).getAttribute('haschild') == '1')
108 this.flex(ch.id, type);
113 SlimTree.prototype.toggle = function(id) {
114 if($(id).getAttribute('ostate') == '1') this.open(id);
115 else if($(id).getAttribute('ostate') == '2') this.close(id);
118 SlimTree.prototype.open = function(id) {
119 if($(id).getAttribute('ostate') == '2') return;
120 var link = $('stlink_' + id);
121 if(id != this.rootid || !this.rootimg) {
122 removeChildren(link);
123 _apc(link,stimgclose.cloneNode(true));
125 link.setAttribute('href','javascript:' + this.handle + '.close("'+id+'");');
126 unHideMe($('stcont_' + id));
127 $(id).setAttribute('ostate','2');
130 SlimTree.prototype.close = function(id) {
131 var link = $('stlink_' + id);
132 if(id != this.rootid || !this.rootimg) {
133 removeChildren(link);
134 _apc(link,stimgopen.cloneNode(true));
136 link.setAttribute('href','javascript:' + this.handle + '.open("'+id+'");');
137 hideMe($('stcont_' + id));
138 $(id).setAttribute('ostate','1');