home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 February / PCO_0299.ISO / filesbbs / w9x / visdhtml.exe / visual / components / statusbar / statusbar.js < prev   
Encoding:
JavaScript  |  1998-03-30  |  5.6 KB  |  167 lines

  1. /**
  2.  * statusbar.js 
  3.  * by gary smith July 1997
  4.  * for sample code (still under construction)
  5.  * see also menubar.js
  6.  */
  7.  
  8. function StatusBar(width, height) {
  9.     this.statusBarBgColor = "#C1CDCD"; //CDB79E  
  10.     this.bar = new Layer(0);
  11.     this.bar.document.bgColor = "#000000";
  12.     this.bar.document.writeln(' ');
  13.     this.bar.document.close();
  14.     this.bar.clip.width = width || window.innerWidth || 100;
  15.     this.bar.clip.height = height || 20;
  16.     this.bar.left = 0;
  17.     this.bar.top = window.innerHeight - 20;
  18.     this.barWidth = this.bar.clip.width;
  19.     this.bar.clip.height += 3;
  20.     this.barHeight = this.bar.clip.height;
  21.     this.bar.visibility = 'inherit';
  22.     this.bar.shadow = makeLayer('m', ' ', this.bar, this.barWidth -1, this.barHeight -1, 0,0, '#888888');
  23.     this.bar.lite   = makeLayer('m', ' ', this.bar, this.barWidth -2, this.barHeight -2, 0,0, '#EEEEEE');
  24.     this.bar.body   = makeLayer('m', ' ', this.bar, this.barWidth -3, this.barHeight -3, 1,1, this.statusBarBgColor);
  25.     this.bar.band   = makeLayer('m', ' ', this.bar, this.barWidth -3, 1, 1,3, '#888888');
  26.     this.bar.body.onFocus = onStatusBar;
  27.     this.bar.body.StatusBar = true;
  28.     this.prev = null;
  29.     this.countItems = 0;
  30.     this.items = new Array();
  31.  
  32.     this.addStatusBarItem = addStatusBarItem;
  33.     this.setStatusBarBgColor = setStatusBarBgColor;
  34.     this.moveStatusBarItem = moveStatusBarItem;
  35.     this.moveStatusBar = moveStatusBar;
  36.     this.onStatusBar = onStatusBar;
  37.     this.resizeStatusBar = resizeStatusBar;
  38. }
  39.  
  40. function addStatusBarItem(label, label_focus, action, width,height, x,y) {
  41.     //var label = '<NOBR><DIV ID=sysFont>' + label + '</DIV></NOBR>';
  42.     //var label_focus = '<NOBR><DIV ID=sysFont>' + label_focus + '</DIV></NOBR>';
  43.     if(label_focus.indexOf(" HREF") == -1) label_focus = '<A HREF="#">' + label_focus + '</A>';
  44.     if(label.indexOf("<DIV ID") == -1) {
  45.        label = '<NOBR><DIV ID=sysFont>' + label + '</DIV></NOBR>';
  46.        label_focus = '<NOBR><DIV ID=sysFont>' + label_focus + '</DIV></NOBR>';
  47.     }
  48.     //java.lang.System.out.println("label=" + label_focus);
  49.     var item = makeLayer('label', label, this.bar, 0,0, 1,4, "", "hide");
  50.     item.focus = makeLayer('label_focus', label_focus, this.bar, 0,0, 1,4, "", "hide");
  51.     item.label = label;
  52.     item.bar = this.bar;
  53.     item.focus.ref = item;
  54.     if(x) {
  55.         item.left = x;
  56.     } else if(this.items[this.countItems -1]) {
  57.         item.left = this.items[this.countItems -1].left + this.items[this.countItems -1].clip.width +5;
  58.     }
  59.     if(y) {
  60.         item.top = y;
  61.         item.focus.top = y;
  62.     }
  63.     item.focus.left = item.left;
  64.     item.visibility = 'inherit';
  65.     item.focus.visibility = 'hide';
  66.     item.onMouseOver = onStatusBarItem_MouseOver;
  67.     item.focus.onMouseOut = onStatusBarItem_MouseOut;
  68.     item.onFocus = this.onStatusBar;
  69.     item.focus.onFocus = this.onStatusBar;
  70.     item.focus.action = action;
  71.     item.ref = this;
  72.     if(item.menuLayer) item.menuLayer = item.menuLayer;
  73.     this.items[item] = item;
  74.     this.items[this.countItems] = item;
  75.     this.countItems++;
  76. }
  77.  
  78. function onStatusBarItem_MouseOver(e) {
  79.     if(window.activeStatusBarItem) window.activeStatusBarItem.visibility = "hide";
  80.     this.focus.visibility = "inherit";
  81.     onStatusBar(e,this);
  82.     window.activeStatusBarItem = this.focus;
  83. }
  84.  
  85. function onStatusBarItem_MouseOut(e) {
  86.     //this.bgColor = "#BEBEBE";
  87.     this.visibility = "hide";
  88. }
  89.  
  90. function onStatusBar(e,lyr) {
  91.     //java.lang.System.out.println("e.target.name=" + e.target.name);
  92.  
  93.     if(!lyr) {
  94.         var l = this;
  95.         if(window.activeStatusBarItem) window.activeStatusBarItem.visibility = "hide";
  96.         if(l.action) eval( l.action );
  97.         if(l.StatusBar) return;
  98.     } else {
  99.         var l = lyr;
  100.     }
  101.     if(l.menuLayer) {
  102.         l.menuLayer.left = l.left + l.bar.left;
  103.         l.menuLayer.top = l.top + l.clip.height + l.bar.top;
  104.         l.menuLayer.visibility = 'inherit';
  105.     }
  106.  
  107. }
  108.  
  109. function moveStatusBarItem(item, x, y) {
  110.     if(typeof(item) == 'string') {
  111.         item = this.items[item];
  112.     }
  113.     if(x) {
  114.         item.left = x;
  115.         item.focus.left = x;
  116.     }
  117.     if(y) {
  118.        item.top = y;
  119.        item.focus.top = y;
  120.     }
  121. }
  122.  
  123. function moveStatusBar(x,y) {
  124.     if(x) this.bar.left = x;
  125.     if(y) this.bar.top = y;
  126. }
  127.  
  128. function resizeStatusBar(w, h) {
  129.     if(w) {
  130.     this.bar.clip.width = w;
  131.     this.bar.shadow.clip.width = w -1;
  132.     this.bar.lite.clip.width = w -2;
  133.     this.bar.body.clip.width = w -3;
  134.     this.bar.band.clip.width = w -3;
  135.     }
  136.     if(h) {
  137.     this.bar.clip.height = h;
  138.     this.bar.shadow.clip.height = h -1;
  139.     this.bar.lite.clip.height = h -2;
  140.     this.bar.body.clip.height = h -3;
  141.     this.bar.band.clip.height = h -3;
  142.     }
  143. }
  144.  
  145. function setStatusBarBgColor(str) {
  146.     this.statusBarBgColor = str;
  147. }
  148.  
  149. function makeLayer(label, content, parentLyr, width, height, x, y, color, viso) {
  150.     //java.lang.System.out.println(""+ parentLyr);
  151.     if(!content) content = " ";
  152.     if(parentLyr) var l = new Layer(width, parentLyr);
  153.     else var l = new Layer(width);
  154.     l.document.ids.font14.fontSize = 14;
  155.     l.document.ids.sysFont.fontSize = 12;
  156.     l.document.ids.sysFont.fontFamily = "Arial, Espy, sans-serif";
  157.     l.document.open("text/html");
  158.     l.document.writeln(content);
  159.     l.document.close();
  160.     l.label = label;
  161.     l.moveTo(x,y);
  162.     if(color != "") l.bgColor = color;
  163.     if(width) l.clip.width = width;
  164.     if(height) l.clip.height = height;
  165.     if(!viso) l.visibility = "inherit";
  166.     return l;
  167. }