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

  1. /**
  2.  * toolbar.js 
  3.  * by gary smith July 1997
  4.  * for sample code (still under construction)
  5.  * see also menubar.js
  6.  */
  7.  
  8. function ToolBar() {
  9.     this.cToolBarParentLayer = null;
  10.     this.cToolBarBgColor = '#C1CDCD'; //CDB79E 
  11.     this.prev = null;
  12.     this.countItems = 0;
  13.     this.items = new Array();
  14.  
  15.     this.addToolBarItem = addToolBarItem;
  16.     this.moveToolBarItem = moveToolBarItem;
  17.     this.moveToolBar = moveToolBar;
  18.     this.onToolBar = onToolBar;
  19.     this.resizeToolBar = resizeToolBar;
  20.     this.cToolBarShow = cToolBarShow;
  21.     this.setCToolBarLeft = setCToolBarLeft;
  22.     this.setCToolBarTop = setCToolBarTop;
  23.     this.setCToolBarWidth = setCToolBarWidth;
  24.     this.setCToolBarHeight = setCToolBarHeight;
  25.     this.setCToolBarBgColor = setCToolBarBgColor;
  26.     this.setCToolBarParentLayer = setCToolBarParentLayer;
  27. }
  28.  
  29. function cToolBarShow(p, width, height) {
  30.     var p = p || this.cToolBarParentLayer;
  31.     width = width || window.innerWidth || 100;
  32.     height = height || 40;
  33.     this.bar = makeLayer('m', ' ', p, width, height, 0,0, '#000000');
  34.     this.barWidth = this.bar.clip.width;
  35.     this.bar.clip.height += 3;
  36.     this.barHeight = this.bar.clip.height;
  37.     //this.bar.onFocus = resizeToolBar;
  38.     this.bar.shadow = makeLayer('m', ' ', this.bar, this.barWidth -1, this.barHeight -1, 0,0, '#888888');
  39.     this.bar.lite   = makeLayer('m', ' ', this.bar, this.barWidth -2, this.barHeight -2, 0,0, '#EEEEEE');
  40.     this.bar.gray   = makeLayer('m', ' ', this.bar, this.barWidth -3, this.barHeight -3, 1,1, this.cToolBarBgColor);
  41.     this.bar.gray.onFocus = onToolBar;
  42.     this.bar.gray.ToolBar = true;
  43. }
  44.  
  45. function addToolBarItem(label, label_focus, action) {
  46.     if(label_focus.indexOf(" HREF") == -1) label_focus = '<A HREF="#">' + label_focus + '</A>';
  47.     if(label.indexOf("<DIV ID") == -1) {
  48.        label = '<NOBR><DIV ID=sysFont>' + label + '</DIV></NOBR>';
  49.        label_focus = '<NOBR><DIV ID=sysFont>' + label_focus + '</DIV></NOBR>';
  50.     }
  51.     //java.lang.System.out.println("label=" + label);
  52.     var item = makeLayer('label', label, this.bar, 0,0, 1,1, "", "hide");
  53.     item.focus = makeLayer('label_focus', label_focus, this.bar, 0,0, 1,1, "", "hide");
  54.     item.label = label;    
  55.     item.bar = this.bar;    
  56.     item.focus.ref = item;    
  57.     if(this.items[this.countItems -1])
  58.         item.left = this.items[this.countItems -1].left + this.items[this.countItems -1].clip.width +5;
  59.     item.focus.left = item.left;
  60.     item.visibility = 'inherit';
  61.     item.focus.visibility = 'hide';
  62.     item.onMouseOver = onToolBarItem_MouseOver;
  63.     item.focus.onMouseOut = onToolBarItem_MouseOut;
  64.     //item.focus.captureEvents(Event.MOUSEDOWN);
  65.     //item.focus.onmousedown = this.onToolBar;
  66.     item.onFocus = this.onToolBar;
  67.     if(action) item.focus.onFocus = this.onToolBar;
  68.     item.focus.action = action;
  69.     //item.clip.width = document.width || top.width || 100;
  70.     item.ref = this;
  71.     if(item.menuLayer) item.menuLayer = item.menuLayer;
  72.     //this.bar.clip.width += item.clip.width;
  73.     this.items[item] = item;
  74.     this.items[this.countItems] = item;
  75.     this.countItems++;
  76. }
  77.  
  78. function onToolBarItem_MouseOver(e) {
  79.     //if(window.nsToolBarActive) return;
  80.     if(window.activeToolBarItem) window.activeToolBarItem.visibility = "hide";
  81.     //this.visibility = "hide";
  82.     this.focus.visibility = "inherit";
  83.     //this.focus.bgColor = "#0000FF";
  84.     onToolBar(e,this);
  85.     window.activeToolBarItem = this.focus;
  86. }
  87.  
  88. function onToolBarItem_MouseOut(e) {
  89.     //this.bgColor = "#BEBEBE";
  90.     this.visibility = "hide";
  91.     //this.dark.visibility = "inherit";
  92.     //window.activeToolBarItem = this;
  93. }
  94.  
  95. function onToolBar(e,lyr) {
  96.     //java.lang.System.out.println("e.target.name=" + e.target.name);
  97.     //java.lang.System.out.println("lyr=" + lyr);
  98.  
  99.     if(!lyr) {
  100.         var l = this;
  101.         //if(window.nsActiveMenu) window.nsActiveMenu.visibility = 'hide';
  102.         if(window.activeToolBarItem) window.activeToolBarItem.visibility = "hide";
  103.         //l.visibility = 'hide';
  104.         if(l.action) eval( l.action );
  105.         if(l.ToolBar) return;
  106.         //window.nsToolBarActive = true;
  107.     } else {
  108.         var l = lyr;
  109.     }
  110.     if(l.menuLayer) {
  111.         l.menuLayer.left = l.left + l.bar.left;
  112.         l.menuLayer.top = l.top + l.clip.height + l.bar.top;
  113.         l.menuLayer.visibility = 'inherit';
  114.     }
  115.  
  116. }
  117.  
  118.  
  119. function moveToolBarItem(item, x, y) {
  120.     if(typeof(item) == 'string') {
  121.         //alert(this.items[item]);
  122.         item = this.items[item];
  123.     }
  124.     if(x) {
  125.         item.left = x;
  126.         item.focus.left = x;
  127.     }
  128.     if(y) {
  129.        item.top = y;
  130.        item.focus.top = y;
  131.     }
  132. }
  133.  
  134. function moveToolBar(x,y) {
  135.     this.bar.left = x;
  136.     this.bar.top = y;
  137.     //if(l.bar) {
  138.         //java.lang.System.out.println("this=" + this.items.length);
  139.         //l.menuLayer.left = l.bar.left;
  140.         //l.menuLayer.top = l.bar.top;
  141.     //}
  142. }
  143.  
  144. function resizeToolBar(w, h) {
  145.     if(w) {
  146.     this.bar.clip.width = w;
  147.     this.bar.shadow.clip.width = w -1;
  148.     this.bar.lite.clip.width = w -2;
  149.     this.bar.gray.clip.width = w -3;
  150.     }
  151.     if(h) {
  152.     this.bar.clip.height = h;
  153.     this.bar.shadow.clip.height = h -1;
  154.     this.bar.lite.clip.height = h -2;
  155.     this.bar.gray.clip.height = h -3;
  156.     }
  157. }
  158.  
  159. function setCToolBarBgColor(str) {
  160.     this.cToolBarBgColor = str;
  161. }
  162. function setCToolBarParentLayer(l) {
  163.     this.cToolBarParentLayer = l;
  164. }
  165. function setCToolBarLeft(i) {
  166.     this.cToolBarLeft = i;
  167. }
  168. function setCToolBarTop(i) {
  169.     this.cToolBarTop = i;
  170. }
  171. function setCToolBarWidth(i) {
  172.     this.cToolBarWidth = i;
  173. }
  174. function setCToolBarHeight(i) {
  175.     this.cToolBarHeight = i;
  176. }
  177.  
  178. function makeLayer(label, content, parentLyr, width, height, x, y, color, viso) {
  179.     //java.lang.System.out.println(""+ parentLyr);
  180.     if(!content) content = " ";
  181.     if(parentLyr) var l = new Layer(width, parentLyr);
  182.     else var l = new Layer(width);
  183.     l.document.ids.font14.fontSize = 14;
  184.     l.document.ids.sysFont.fontSize = 12;
  185.     l.document.ids.sysFont.fontFamily = "Arial, Espy, sans-serif";
  186.     l.document.open("text/html");
  187.     l.document.writeln(content);
  188.     l.document.close();
  189.     l.label = label;
  190.     l.moveTo(x,y);
  191.     if(color != "") l.bgColor = color;
  192.     if(width) l.clip.width = width;
  193.     if(height) l.clip.height = height;
  194.     if(!viso) l.visibility = "inherit";
  195.     return l;
  196. }