home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 May / CHIPCD200305.iso / super / altn / md_en.exe / LIST.JS < prev    next >
Encoding:
Text File  |  2001-07-31  |  7.1 KB  |  215 lines

  1. var _id = 0, _pid = 0, _lid = 0, _pLayer;
  2. var _mLists = new Array();
  3. document.lists = _mLists;
  4. var isNav4, isIE4;
  5. if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
  6.   isNav4 = (navigator.appName == "Netscape") ? true : false;
  7.   isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;
  8. }
  9. function List(visible, width, height, bgColor) {
  10.   this.setIndent = setIndent;
  11.   this.addItem = addItem;
  12.   this.addList = addList;
  13.   this.build = build;
  14.   this.rebuild = rebuild;
  15.   this.setFont = _listSetFont;
  16.   this._writeList = _writeList;
  17.   this._showList = _showList;
  18.   this._updateList = _updateList;
  19.   this._updateParent = _updateParent;
  20.   this.onexpand = null; this.postexpand = null;
  21.   this.lists = new Array(); // sublists
  22.   this.items = new Array(); // layers
  23.   this.types = new Array(); // type
  24.   this.strs = new Array();  // content
  25.   this.x = 0;
  26.   this.y = 0;
  27.   this.visible = visible;
  28.   this.id = _id;
  29.   this.i = 18;
  30.   this.space = true;
  31.   this.pid = 0;
  32.   this.fontIntro = false;
  33.   this.fontOutro = false;
  34.   this.width = width || 350;
  35.   this.height = height || 22;
  36.   this.parLayer = false;
  37.   this.built = false;
  38.   this.shown = false;
  39.   this.needsUpdate = false;
  40.   this.needsRewrite = false;
  41.   this.parent = null;
  42.   this.l = 0;
  43.   if(bgColor) this.bgColor = bgColor;
  44.   else this.bgColor = null;
  45.   _mLists[_id++] = this;
  46. }
  47. function _listSetFont(i,j) {
  48.   this.fontIntro = i;
  49.   this.fontOutro = j;
  50. }
  51. function setIndent(indent) { this.i = indent; if(this.i < 0) { this.i = 0; this.space = false; } }
  52. function setClip(layer, l, r, t, b) {
  53.   if(isNav4) {
  54.     layer.clip.left = l; layer.clip.right = r;
  55.     layer.clip.top = t;  layer.clip.bottom = b;
  56.   } else {
  57.     layer.style.pixelWidth = r-l;
  58.     layer.style.pixelHeight = b-t;
  59.     layer.style.clip = "rect("+t+","+r+","+b+","+l+")";
  60.   }
  61. }
  62. function _writeList() {
  63.   self.status = "List: Writing list...";
  64.   var layer, str, clip;
  65.   for(var i = 0; i < this.types.length; i++) { 
  66.     layer = this.items[i];
  67.     if(isNav4) layer.visibility = "hidden";
  68.     else layer.style.visibility = "hidden";
  69.     str = "";
  70.     if(isNav4) layer.document.open();
  71.     str += "<TABLE WIDTH="+this.width+" NOWRAP BORDER=0 CELLPADDING=0 CELLSPACING=0><TR>";
  72.     if(this.types[i] == "list") {
  73.       str += "<TD WIDTH=15 NOWRAP VALIGN=MIDDLE><A TARGET='_self' HREF=\"javascript:expand("+this.lists[i].id+");\"><IMG BORDER=0 SRC=\"RedLine/true.gif\" NAME=\"_img"+this.lists[i].id+"\"></A></TD>";
  74.       _pid++;
  75.     } else if(this.space)
  76.       str += "<TD WIDTH=15 NOWRAP> </TD>";
  77.     if(this.l>0 && this.i>0) str += "<TD WIDTH="+this.l*this.i+" NOWRAP> </TD>";
  78.     str += "<TD HEIGHT="+(this.height-3)+" WIDTH="+(this.width-15-this.l*this.i)+" VALIGN=MIDDLE ALIGN=LEFT>";
  79.     if(this.fontIntro) str += this.fontIntro;
  80.     str += this.strs[i];
  81.     if(this.fontOutro) str += this.fontOutro;
  82.     str += "</TD></TABLE>";
  83.     if(isNav4) {
  84.       layer.document.writeln(str);
  85.       layer.document.close();
  86.     } else layer.innerHTML = str;
  87.     if(this.types[i] == "list" && this.lists[i].visible)
  88.       this.lists[i]._writeList();
  89.   }
  90.   this.built = true;
  91.   this.needsRewrite = false;
  92.   self.status = '';
  93. }
  94. function _showList() {
  95.   var layer;
  96.   for(var i = 0; i < this.types.length; i++) { 
  97.     layer = this.items[i];
  98.     setClip(layer, 0, this.width, 0, this.height-1);
  99.     var bg = layer.oBgColor || this.bgColor;
  100.     if(isIE4) {
  101.       if((bg == null) || (bg == "null")) bg = "";
  102.       layer.style.backgroundColor = bg;
  103.     } else layer.document.bgColor = bg;
  104.     if(this.types[i] == "list" && this.lists[i].visible)
  105.       this.lists[i]._showList();
  106.   }
  107.   this.shown = true;
  108.   this.needsUpdate = false;
  109. }
  110. function _updateList(pVis, x, y) {
  111.   var currTop = y, layer;
  112.   for(var i = 0; i < this.types.length; i++) { 
  113.     layer = this.items[i];
  114.     if(this.visible && pVis) {
  115.       if(isNav4) {
  116.         layer.visibility = "visible";
  117.         layer.top = currTop;
  118.         layer.left = x;
  119.       } else {
  120.         layer.style.visibility = "visible";
  121.         layer.style.pixelTop = currTop;
  122.         layer.style.pixelLeft = x;
  123.       }
  124.       currTop += this.height;
  125.     } else {
  126.       if(isNav4) layer.visibility = "hidden";
  127.       else layer.style.visibility = "hidden";
  128.     }
  129.     if(this.types[i] == "list") {
  130.       if(this.lists[i].visible) {
  131.         if(!this.lists[i].built || this.lists[i].needsRewrite) this.lists[i]._writeList();
  132.         if(!this.lists[i].shown || this.lists[i].needsUpdate) this.lists[i]._showList();
  133.         if(isNav4) layer.document.images[0].src = "RedLine/true.gif";
  134.         else eval('document.images._img'+this.lists[i].id+'.src = "RedLine/true.gif"');
  135.       } else {
  136.         if(isNav4) layer.document.images[0].src = "RedLine/false.gif";
  137.         else eval('document.images._img'+this.lists[i].id+'.src = "RedLine/false.gif"');
  138.       }
  139.       if(this.lists[i].built)
  140.         currTop = this.lists[i]._updateList(this.visible && pVis, x, currTop);
  141.     }
  142.   }
  143.   return currTop;
  144. }
  145. function _updateParent(pid, l) {
  146.   var layer;
  147.   if(!l) l = 0;
  148.   this.pid = pid;
  149.   this.l = l;
  150.   for(var i = 0; i < this.types.length; i++)
  151.     if(this.types[i] == "list")
  152.       this.lists[i]._updateParent(pid, l+1);
  153. }
  154. function expand(i) {
  155.   _mLists[i].visible = !_mLists[i].visible;
  156.   if(_mLists[i].onexpand != null) _mLists[i].onexpand(_mLists[i].id);
  157.   _mLists[_mLists[i].pid].rebuild();
  158.   if(_mLists[i].postexpand != null) _mLists[i].postexpand(_mLists[i].id);
  159. }
  160. function build(x, y) {
  161.   this._updateParent(this.id);
  162.   this._writeList();
  163.   this._showList();
  164.   this._updateList(true, x, y);
  165.   this.x = x; this.y = y;
  166. }
  167. function rebuild() { this._updateList(true, this.x, this.y); }
  168. function addItem(str, bgColor, layer) {
  169.   var testLayer = false;
  170.   if(!document.all) document.all = document.layers;
  171.   if(!layer) {
  172.     if(isIE4 || !this.parLayer) testLayer = eval('document.all.lItem'+_lid);
  173.     else {
  174.       _pLayer = this.parLayer;
  175.       testLayer = eval('_pLayer.document.layers.lItem'+_lid);
  176.     }
  177.     if(testLayer) layer = testLayer;
  178.     else {
  179.       if(isNav4) {
  180.         if(this.parLayer) layer = new Layer(this.width, this.parLayer);
  181.         else layer = new Layer(this.width);
  182.       } else return;
  183.     }
  184.   }
  185.   if(bgColor) layer.oBgColor = bgColor;
  186.   this.items[this.items.length] = layer;
  187.   this.types[this.types.length] = "item";
  188.   this.strs[this.strs.length] = str;
  189.   _lid++;
  190. }
  191. function addList(list, str, bgColor, layer) {
  192.   var testLayer = false;
  193.   if(!document.all) document.all = document.layers;
  194.   if(!layer) {
  195.     if(isIE4 || !this.parLayer) testLayer = eval('document.all.lItem'+_lid);
  196.     else {
  197.       _pLayer = this.parLayer;
  198.       testLayer = eval('_pLayer.document.layers.lItem'+_lid);
  199.     }
  200.     if(testLayer) layer = testLayer;
  201.     else {
  202.       if(isNav4) {
  203.         if(this.parLayer) layer = new Layer(this.width, this.parLayer);
  204.         else layer = new Layer(this.width);
  205.       } else return;
  206.     }
  207.   }
  208.   if(bgColor) layer.oBgColor = bgColor;
  209.   this.lists[this.items.length] = list;
  210.   this.items[this.items.length] = layer;
  211.   this.types[this.types.length] = "list";
  212.   this.strs[this.strs.length] = str;
  213.   list.parent = this;
  214.   _lid++;
  215. }