2 xbCollapsibleLists.js 2001-02-26
4 Contributor(s): Michael Bostock, Netscape Communications, Copyright 1997
5 Bob Clary, Netscape Communications, Copyright 2001
6 Seth Dillingham, Macrobyte Resources, Copyright 2001
7 Mark Filanowicz, Amdahl IT Services, Copyright 2002
9 Netscape grants you a royalty free license to use, modify or
10 distribute this software provided that this copyright notice
11 appears on all copies. This software is provided "AS IS,"
12 without a warranty of any kind.
14 See xbCollapsibleLists.js.changelog.html for details of changes.
20 var xbcl_mLists = new Array();
21 var xbcl_parentElement = null;
23 document.lists = xbcl_mLists;
25 function List(visible, width, height, bgColor, collapsedImageURL, expandedImageURL)
27 this.lists = new Array(); // sublists
28 this.items = new Array(); // layers
29 this.types = new Array(); // type
30 this.strs = new Array(); // content
31 this.visible = visible;
33 this.width = width || 350;
34 this.height = height || 22;
36 this.collapsedImageURL = collapsedImageURL || 'false.gif';
37 this.expandedImageURL = expandedImageURL || 'true.gif';
40 this.bgColor = bgColor;
42 xbcl_mLists[xbcl__id++] = this;
45 function xbcl_SetFont(i,j)
51 function xbcl_GetFont()
53 return [this.fontIntro, this.fontOutro];
56 function xbcl_setIndent(indent)
68 function xbcl_getIndent(indent)
73 function xbcl_writeItemDOMHTML( obj, s, flList, listObj )
76 var outerDiv, innerLeft, innerRight;
80 styleObj = new xbStyle(obj);
81 styleObj.setVisibility('hidden');
82 outerDiv = document.createElement( "DIV" );
83 outerDiv.id = "DIV_" + obj.id;
84 styleObj = new xbStyle( outerDiv );
85 styleObj.setWidth( this.width );
89 innerLeft = document.createElement( "DIV" );
90 innerLeft.style.position = "absolute";
91 innerLeft.style.valign = "middle";
94 styleObj = new xbStyle( innerLeft );
95 styleObj.setWidth( 15 );
96 styleObj.setBackgroundColor( "transparent" );
98 if ( listObj.visible )
99 str = '<A TARGET="_self" HREF="javascript:xbcl_expand(' + listObj.id + ');"><IMG BORDER="0" SRC="' + this.expandedImageURL + '" ID="_img' + listObj.id + '" NAME="_img' + listObj.id + '"></A>';
101 str = '<A TARGET="_self" HREF="javascript:xbcl_expand(' + listObj.id + ');"><IMG BORDER="0" SRC="' + this.collapsedImageURL + '" ID="_img' + listObj.id + '" NAME="_img' + listObj.id + '"></A>';
103 innerLeft.innerHTML = str;
104 outerDiv.appendChild( innerLeft );
106 else if ( this.space )
109 innerRight = document.createElement( "DIV" );
110 innerRight.noWrap = true;
111 innerRight.style.position = "absolute";
113 styleObj = new xbStyle( innerRight );
114 styleObj.setLeft( leftEdge + ( this.l * this.i ) );
115 styleObj.setWidth( this.width - 15 - this.l * this.i );
116 styleObj.setBackgroundColor( "transparent" );
118 // start of change by Mark Filanowicz 02-22-2002
121 s = this.fontIntro + '<A TARGET="_self" STYLE="text-decoration: none;" HREF="javascript:xbcl_expand(' + listObj.id + ');">' + s + this.fontOutro;
125 s = this.fontIntro + s + this.fontOutro;
127 // end of change by Mark Filanowicz 02-22-2002
130 innerRight.innerHTML = s;
131 outerDiv.appendChild( innerRight );
133 obj.appendChild( outerDiv );
138 function xbcl_writeItem( obj, s, flList, listObj )
142 var styleObj = new xbStyle( obj );
144 styleObj.setVisibility( 'hidden' );
146 if ( document.body && document.body.style )
147 cellStyle = ' style="background-color: transparent;"';
149 str += '<TABLE WIDTH='+this.width+' NOWRAP BORDER="0" CELLPADDING="0" CELLSPACING="0"><TR>';
153 str += '<TD WIDTH="15" NOWRAP VALIGN="MIDDLE"' + cellStyle + '>';
154 str += '<A TARGET="_self" HREF="javascript:xbcl_expand(' + listObj.id + ');">';
156 if ( listObj.visible )
157 str += '<IMG BORDER="0" SRC="' + this.expandedImageURL + '" ID="_img' + listObj.id + '" NAME="_img' + listObj.id + '">';
159 str += '<IMG BORDER="0" SRC="' + this.collapsedImageURL + '" ID="_img' + listObj.id + '" NAME="_img' + listObj.id + '">';
164 str += '<TD WIDTH="15" NOWRAP' + cellStyle + '> </TD>';
166 if (this.l>0 && this.i>0)
167 str += '<TD WIDTH="' + this.l*this.i+ '" NOWRAP' + cellStyle + '> </TD>';
169 str += '<TD HEIGHT="' + ( this.height - 3) + '" WIDTH="' + ( this.width - 15 - this.l * this.i ) + '" VALIGN="MIDDLE" ALIGN="LEFT"' + cellStyle + '>';
171 // start of change by Mark Filanowicz 02-22-2002
174 str += this.fontIntro + '<A TARGET="_self" STYLE="text-decoration: none;" HREF="javascript:xbcl_expand(' + listObj.id + ');">' + s + this.fontOutro;
178 str += this.fontIntro + s + this.fontOutro;
180 // end of change by Mark Filanowicz 02-22-2002
182 str += '</TD></TR></TABLE>';
184 styleObj.setInnerHTML( str );
189 function xbcl_writeList()
195 for ( i = 0; i < this.types.length; i++ )
197 item = this.items[ i ];
198 flList = ( this.types[ i ] == 'list' );
200 this._writeItem( item, this.strs[ i ], flList, this.lists[ i ] );
202 if ( flList && this.lists[ i ].visible )
203 this.lists[ i ]._writeList();
207 this.needsRewrite = false;
211 function xbcl_showList()
217 for (i = 0; i < this.types.length; i++)
219 item = this.items[i];
220 styleObj = new xbStyle(item);
221 styleObj.setClipLeft(0);
222 styleObj.setClipRight(this.width);
223 styleObj.setClipTop(0);
226 styleObj.setClipBottom(item.height);
227 styleObj.setHeight(item.height);
231 styleObj.setClipBottom(this.height);
232 styleObj.setHeight(this.height);
236 styleObj.setVisibility( 'visible' );
238 var bg = item.oBgColor || this.bgColor;
239 if ((bg == null) || (bg == 'null'))
242 styleObj.setBackgroundColor(bg);
244 if (this.types[i] == 'list' && this.lists[i].visible)
245 this.lists[i]._showList();
248 this.needsUpdate = false;
251 function xbcl_setImage(list, item, file)
253 var id = '_img' + list.id;
256 // for DOMHTML or IE4 use cross browser getElementById from xbStyle
257 // can't use it for NN4 since it only works for layers in NN4
259 img = item.document.images[0];
261 img = xbGetElementById(id);
267 function xbcl_getHeight()
275 for (i = 0; i < this.types.length; i++)
277 if (this.items[i].height)
278 totalHeight += this.items[i].height;
280 totalHeight += this.height;
282 if ((this.types[i] == 'list') && this.lists[i].visible)
284 totalHeight += this.lists[i].getHeight();
291 function xbcl_updateList(pVis, x, y)
298 for (i = 0; i < this.types.length; i++)
300 item = this.items[i];
301 styleObj = new xbStyle(item);
303 if (this.visible && pVis)
305 styleObj.moveTo(x, currTop);
306 if (item.height) // allow custom heights for each item
307 currTop += item.height;
309 currTop += this.height;
311 styleObj.setVisibility('visible');
315 styleObj.setVisibility('hidden');
318 if (this.types[i] == 'list')
320 if (this.lists[i].visible)
322 if (!this.lists[i].built || this.lists[i].needsRewrite)
323 this.lists[i]._writeList();
325 if (!this.lists[i].shown || this.lists[i].needsUpdate)
326 this.lists[i]._showList();
328 xbcl_setImage(this.lists[i], item, this.expandedImageURL );
331 xbcl_setImage(this.lists[i], item, this.collapsedImageURL );
333 if (this.lists[i].built)
334 currTop = this.lists[i]._updateList(this.visible && pVis, x, currTop);
340 function xbcl_updateParent( pid, l )
350 for ( i = 0; i < this.types.length; i++ )
352 if ( this.types[ i ] == 'list' )
354 this.lists[ i ]._updateParent( pid, l + 1 );
359 function xbcl_expand(i)
361 xbcl_mLists[i].visible = !xbcl_mLists[i].visible;
363 if (xbcl_mLists[i].onexpand != null)
364 xbcl_mLists[i].onexpand(xbcl_mLists[i].id);
366 xbcl_mLists[xbcl_mLists[i].pid].rebuild();
368 if (xbcl_mLists[i].postexpand != null)
369 xbcl_mLists[i].postexpand(xbcl_mLists[i].id);
372 function xbcl_build(x, y)
374 this._updateParent(this.id);
377 this._updateList(true, x, y);
382 function xbcl_rebuild()
384 this._updateList(true, this.x, this.y);
387 function xbcl_getNewItem()
391 newItem = xbGetElementById('lItem' + xbcl_item_id);
395 if (document.all && !document.getElementById)
397 var parentElement = this.parentElement;
399 parentElement = document.body;
401 parentElement.insertAdjacentHTML('beforeEnd', '<div id="lItem' + xbcl_item_id + '" style="position:absolute;"></div>');
402 newItem = xbGetElementById('lItem' + xbcl_item_id);
404 else if (document.layers)
406 if (this.parentElement)
407 newItem = new Layer(this.width, this.parentElement);
409 newItem = new Layer(this.width);
411 else if (document.createElement)
413 newItem = document.createElement('div');
414 newItem.id= 'lItem' + xbcl_item_id;
415 newItem.style.position = 'absolute';
417 if (this.parentElement)
418 this.parentElement.appendChild(newItem);
420 document.body.appendChild(newItem);
427 function xbcl_addItem(str, bgColor, item)
430 item = this._getNewItem();
436 item.oBgColor = bgColor;
438 this.items[this.items.length] = item;
439 this.types[this.types.length] = 'item';
440 this.strs[this.strs.length] = str;
445 this._writeItem( item, str, false );
446 xbcl_mLists[this.pid].rebuild();
450 this.needsUpdate = true;
456 function xbcl_addList(list, str, bgColor, item)
459 item = this._getNewItem();
465 item.oBgColor = bgColor;
467 this.lists[this.items.length] = list;
468 this.items[this.items.length] = item;
469 this.types[this.types.length] = 'list';
470 this.strs[this.strs.length] = str;
473 list.parentList = this;
480 this._writeItem( item, str, true, list );
481 xbcl_mLists[ this.pid ].rebuild();
485 this.needsUpdate = true;
491 List.prototype.setIndent = xbcl_setIndent;
492 List.prototype.getIndent = xbcl_getIndent;
493 List.prototype.addItem = xbcl_addItem;
494 List.prototype.addList = xbcl_addList;
495 List.prototype.build = xbcl_build;
496 List.prototype.rebuild = xbcl_rebuild;
497 List.prototype.setFont = xbcl_SetFont;
498 List.prototype.getFont = xbcl_GetFont;
499 List.prototype.getHeight = xbcl_getHeight;
501 List.prototype._writeList = xbcl_writeList;
502 List.prototype._getNewItem = xbcl_getNewItem;
504 if ( document.getElementById && document.createElement )
505 List.prototype._writeItem = xbcl_writeItemDOMHTML;
507 List.prototype._writeItem = xbcl_writeItem;
509 List.prototype._showList = xbcl_showList;
510 List.prototype._updateList = xbcl_updateList;
511 List.prototype._updateParent = xbcl_updateParent;
513 List.prototype.onexpand = null;
514 List.prototype.postexpand = null;
515 List.prototype.lists = null; // sublists
516 List.prototype.items = null; // layers
517 List.prototype.types = null; // type
518 List.prototype.strs = null; // content
519 List.prototype.x = 0;
520 List.prototype.y = 0;
521 List.prototype.visible = false;
522 List.prototype.id = -1;
523 List.prototype.i = 18;
524 List.prototype.space = true;
525 List.prototype.pid = 0;
526 List.prototype.fontIntro = '';
527 List.prototype.fontOutro = '';
528 List.prototype.width = 350;
529 List.prototype.height = 22;
530 List.prototype.built = false;
531 List.prototype.shown = false;
532 List.prototype.needsUpdate = false;
533 List.prototype.needsRewrite = false;
534 List.prototype.l = 0;
535 List.prototype.bgColor = null;
536 List.prototype.parentList = null;
537 List.prototype.parentElement = null;