home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 February / PCO_0299.ISO / filesbbs / w9x / visdhtml.exe / visual / visual.js < prev   
Encoding:
Text File  |  1998-03-30  |  16.5 KB  |  449 lines

  1. /**
  2.  * visual.js 
  3.  * library for Visual DHTML demo tool
  4.  * by gary smith
  5.  * under construction...
  6.  */
  7.  
  8. if (!window.visual) window.visual = new Object();
  9. window.visual.marqueeAry = new Array();
  10. window.visual.VToolBarItems = new Array();
  11. var ScrollBar = null;  //requires scrollbar.js
  12. var ToolBar = null;    //requires toolbar.js
  13. java.lang.System.out.println("visual.js loaded...");
  14.  
  15. //window.captureEvents(Event.MOUSEOVER|Event.MOUSEDOWN);
  16.  
  17. window.visual.addScrollBars = function(l) {
  18.     if(!l) l = window.visual.ScrollBarsLayer;
  19.     if (ScrollBar) {
  20.         var vsbar = new ScrollBar();
  21.         vsbar.setCScrollBarParentLayer(l.parentLayer);
  22.         vsbar.cScrollBarShow(l);
  23.         var hsbar = new ScrollBar();
  24.         hsbar.cScrollBarLayout='horizontal';
  25.         hsbar.setCScrollBarParentLayer(l.parentLayer);
  26.         hsbar.cScrollBarShow(l);
  27.     } else {
  28.         window.visual.ScrollBarsLayer=l; 
  29.         setTimeout('window.visual.addScrollBars();',5000);
  30.     }
  31. }
  32.  
  33. window.visual.addVToolBar = function(width,height,color) {
  34.     //java.lang.System.out.println("width="+width);
  35.     //java.lang.System.out.println("height="+height);
  36.     //java.lang.System.out.println("color="+color);
  37.     if (ToolBar) {
  38.         var tb = new ToolBar();
  39.             //tb.setCToolBarParentLayer = p;
  40.         if (typeof(width) == "number")
  41.             tb.setCToolBarWidth(width);
  42.         if (height)
  43.             tb.setCToolBarHeight(height);
  44.         if (color)
  45.             tb.setCToolBarBgColor(color);
  46.         window.visual.toolbar = tb;
  47.         setTimeout('window.visual.toolbar.cToolBarShow();',1000);
  48.         setTimeout('window.visual.addVToolBarItems();',4000);
  49.     } else {
  50.         setTimeout('window.visual.addVToolBar('+ width +','+ height +',"'+ color +'");',1000);
  51.     }
  52. }
  53.  
  54. window.visual.storeVToolBarItems = function(img, img2, alt, action) {
  55.     newVToolBarItem = new window.visual.VToolBarItem(img, img2, alt, action);
  56.     window.visual.VToolBarItems[window.visual.VToolBarItems.length] = newVToolBarItem;
  57. }
  58.  
  59. window.visual.VToolBarItem = function(img, img2, alt, action) {
  60.     this.img = img;
  61.     this.img2 = img2;
  62.     this.alt = alt;
  63.     this.action = action;
  64. }
  65.  
  66. window.visual.addVToolBarItems = function(img, img2, alt, action) {
  67.     for (var i in window.visual.VToolBarItems) {
  68.         window.visual.toolbar.addToolBarItem('<IMG SRC="'+ window.visual.VToolBarItems[i].img +'">', '<A HREF="#"><IMG SRC="'+ window.visual.VToolBarItems[i].img2 +'" ALT="'+ window.visual.VToolBarItems[i].alt +'" BORDER=0></A>', window.visual.VToolBarItems[i].action);
  69.     }
  70. }
  71.  
  72.  
  73. /**
  74.  * set visual drag methods
  75.  */
  76. window.visual.setDrag = function(l, exec, blink) {
  77.     if (!window.visual.DragOff) {
  78.         l.captureEvents(Event.CLICK|Event.MOUSEDOWN|Event.MOUSEUP|Event.MOUSEDRAG);
  79.         l.onmousedown  = window.visual.startDrag;
  80.         l.onmouseup    = window.visual.endDrag;
  81.         this.dragLayer = l;
  82.         this.dragExec  = exec;
  83.         window.visual.blink = blink;
  84.     }
  85. }
  86.  
  87. window.visual.unSetDrag = function(l) {
  88.     if (!window.visual.DragOff) {
  89.         l.releaseEvents(Event.MOUSEDOWN|Event.MOUSEUP|Event.MOUSEDRAG);
  90.     }
  91. }
  92.  
  93. window.visual.startDrag = function(e) {
  94.     java.lang.System.out.println("startDrag");
  95.     window.visual.oldLeft = window.visual.dragLayer.left;
  96.     window.visual.oldTop  = window.visual.dragLayer.top;
  97.     if (e.which > 1) { //rightMouse
  98.         window.visual.rightMouse(e);
  99.         window.visual.dragLayer.releaseEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  100.         return false;
  101.     } else if (e) { 
  102.         window.captureEvents(Event.MOUSEMOVE);
  103.         window.onmousemove = window.visual.drag; 
  104.         window.visual.offX=e.pageX;
  105.         window.visual.offY=e.pageY;
  106.         return false;
  107.     } else {
  108.         window.visual.dragLayer.releaseEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  109.         if (window.visual.dragExec) window.visual.dragExec();
  110.         return true;
  111.     }
  112. }
  113.  
  114. window.visual.drag = function(e) {
  115.     window.visual.dragLayer.moveBy(e.pageX - window.visual.offX, e.pageY - window.visual.offY);
  116.     window.visual.offX = e.pageX;
  117.     window.visual.offY = e.pageY;
  118. }
  119.  
  120. window.visual.endDrag = function(e) {
  121.     if (window.visual.blink) {
  122.         window.visual.dragLayer.visibility = "hide";
  123.     }
  124.     window.onmousemove=0; 
  125.     window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEDRAG);
  126.     window.visual.dragLayer.releaseEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  127.     window.visual.newLeft = window.visual.dragLayer.left;
  128.     window.visual.newTop  = window.visual.dragLayer.top;
  129.     if (window.visual.blink) {
  130.         setTimeout('window.visual.dragLayer.visibility = "inherit";',0);
  131.     }
  132.     if (window.visual.newLeft <= window.visual.oldLeft +2 && window.visual.newLeft >= window.visual.oldLeft -2 && window.visual.newTop <= window.visual.oldTop +2 && window.visual.newTop >= window.visual.oldTop -2) {
  133.         if (window.visual.dragExec) window.visual.dragExec();
  134.     } else {
  135.         //if (!window.activeDrawerID) window.visual.tab();
  136.         if (window.activeDrawerID != "undefined") window.visual.tab();
  137.         if (top.window) {
  138.             if (top.window.dev) {
  139.                 top.window.dev.reSet(window.visual.dragLayer);
  140.             }
  141.         }
  142.     }
  143. }
  144.  
  145. window.visual.tab = function() {
  146.     window.drawerTab   = eval('window.drawerTab' + window.activeDrawerID);
  147.     window.drawerLayer = eval('window.drawerLayer' + window.activeDrawerID);
  148.     var loc = eval('window.drawerLoc' + window.activeDrawerID);
  149.     if (!window.drawerTab) return;
  150.     drawerWidth = window.drawerTab.clip.width;
  151.     drawerHeight = window.drawerLayer.clip.height;
  152.  
  153.     if (window.drawerTab.top <= window.drawerTab.left && 
  154.         window.drawerTab.top <= window.innerHeight - window.drawerTab.top && 
  155.         window.drawerTab.top < window.innerWidth - window.drawerTab.clip.width - window.drawerTab.left) 
  156.         loc = 'top';
  157.     else if (window.drawerTab.left <= window.innerHeight - window.drawerTab.top) 
  158.         loc = 'left';
  159.     else if (window.innerHeight - window.drawerTab.top <= window.drawerTab.left && window.innerHeight - window.drawerTab.top <= window.innerWidth - window.drawerTab.left) 
  160.         loc = 'btm';
  161.     else 
  162.         loc = 'right';
  163.     eval(('window.drawerLoc' + window.activeDrawerID) + ' = loc');
  164.  
  165.     window.drawerLayer.top = window.drawerTab.top;
  166.     window.drawerLayer.left = window.drawerTab.left;
  167.  
  168.     if (loc == 'top') {
  169.         window.drawerTab.top = 0;
  170.         window.drawerLayer.top = -drawerHeight;
  171.     } else if (loc == 'btm') {
  172.         window.drawerTab.top = window.innerHeight - window.drawerTab.clip.height;
  173.         window.drawerLayer.top = window.innerHeight;
  174.     } else if (loc == 'right') {
  175.         window.drawerTab.left = window.innerWidth - window.drawerTab.clip.width;
  176.         window.drawerLayer.left = window.innerWidth;
  177.     } else {
  178.         window.drawerTab.left = 0;
  179.         window.drawerLayer.left = -window.drawerLayer.clip.width;
  180.     }
  181.     eval(('window.drawerState' + window.activeDrawerID) + ' = 0');
  182. }
  183.  
  184. window.visual.drawer = function() {
  185.     window.drawerTab   = eval('window.drawerTab' + window.activeDrawerID);
  186.     window.drawerLayer = eval('window.drawerLayer' + window.activeDrawerID);
  187.     var state = eval('window.drawerState' + window.activeDrawerID);
  188.     var loc = eval('window.drawerLoc' + window.activeDrawerID);
  189.     drawerWidth = window.drawerLayer.clip.width;
  190.     drawerHeight = window.drawerLayer.clip.height;
  191.     window.drawerLayer.top = window.drawerTab.top;
  192.     window.drawerLayer.left = window.drawerTab.left;
  193.  
  194.     if (state == 1) {
  195.         if (loc == 'top') {
  196.             window.drawerTab.top = 0;
  197.             window.drawerLayer.top = -drawerHeight;
  198.         } else if (loc == 'btm') {
  199.             window.drawerTab.top = window.innerHeight - window.drawerTab.clip.height;
  200.             window.drawerLayer.top = window.innerHeight;
  201.         } else if (loc == 'right') {
  202.             window.drawerTab.left = window.innerWidth - window.drawerTab.clip.width;
  203.             window.drawerLayer.left = window.innerWidth;
  204.         } else {
  205.             window.drawerTab.left = 0;
  206.             window.drawerLayer.left = -drawerWidth;
  207.         }
  208.         eval(('window.drawerState' + window.activeDrawerID) + ' = 0');
  209.     } else {
  210.         if (loc == 'top') {
  211.             window.drawerTab.top = drawerHeight;
  212.             window.drawerLayer.top = 0;
  213.         } else if (loc == 'btm') {
  214.             window.drawerTab.top = window.innerHeight - drawerHeight - window.drawerTab.clip.height;
  215.             window.drawerLayer.top = window.innerHeight - drawerHeight;
  216.             if (window.drawerTab.top < 0) { window.drawerTab.top = 0; window.drawerLayer.top = window.drawerTab.clip.height; };
  217.  
  218.         } else if (loc == 'right') {
  219.             window.drawerTab.left = window.innerWidth - drawerWidth - window.drawerTab.clip.width;
  220.             window.drawerLayer.left = window.innerWidth - drawerWidth;
  221.             if (window.drawerTab.left < 0) { window.drawerTab.left = 0; window.drawerLayer.left = window.drawerTab.clip.width; }
  222.         } else {
  223.             window.drawerTab.left = drawerWidth;
  224.             window.drawerLayer.left = 0;
  225.             if (window.drawerTab.left + window.drawerTab.clip.width > window.innerWidth) window.drawerTab.left = window.innerWidth - window.drawerTab.clip.width;
  226.         }
  227.         eval(('window.drawerState' + window.activeDrawerID) + ' = 1');
  228.     }
  229.     window.drawerLayer.visibility = 'inherit';
  230. }
  231.  
  232. /**
  233.  * addMyChannel for nc
  234.  */
  235.  
  236. window.visual.addMyChannel = function(name,url) {
  237.     var nc = components["netcaster"];
  238.     nc.activate();
  239.     if (nc.active == true) { 
  240.       if (!nc.getChannelObject) { 
  241.         alert("Please Wait");
  242.       } else {
  243.         import nc.getChannelObject;
  244.         import nc.addChannel;
  245.         channel = getChannelObject();
  246.         channel.url = (url || "URL");    //channel URL
  247.         channel.name = (name || "Name"); //channel Name
  248.         channel.desc = name; //channel description
  249.         channel.intervalTime = -5;
  250.         channel.absoluteTime = 0;
  251.         channel.estCacheSize = -1;
  252.         channel.maxCacheSize = 1024000;
  253.         channel.depth = 3;
  254.         channel.active = 1;
  255.         channel.topHint = screen.availTop;
  256.         channel.leftHint = screen.availLeft;
  257.         channel.widthHint =  600;
  258.         channel.heightHint = 391;
  259.         channel.mode="webtop";
  260.         channel.type=1;  // 1 = HTTP channel; 2 = Castanet channel
  261.         channel.cardURL = '';  //reserved for future use
  262.         addChannel(channel);
  263.       }
  264.     }
  265. }
  266.  
  267. window.visual.mouseLink = function(lyr) {
  268.     if (window.prevlyr) prevlyr.visibility = 'hide';
  269.     lyr.visibility = 'inherit';
  270.     window.prevlyr = lyr;
  271. }
  272.  
  273. window.visual.ticker = function(id,lyrID,tickerWidth,tickerClipWidth) {
  274.     lyr = eval('window.tickerLayer' + lyrID);
  275.     lyr.left -= 1;
  276.     if (lyr.left < -tickerWidth) lyr.left = tickerClipWidth;
  277.     id = setTimeout('window.visual.ticker('+id+','+ lyrID +','+tickerWidth+','+tickerClipWidth+')',100);
  278. }
  279.  
  280. window.visual.marquee = function(id,lyrID,dir) {
  281.     lyr = eval('window.marqueeLayer' + lyrID);
  282.     switch(dir) {
  283.         case 0: //left
  284.             if (window.visual.marqueeAry[lyrID] == null) {
  285.                 lyr.left = window.innerWidth;
  286.             } else if (lyr.left <= (window.innerWidth - lyr.clip.width) ) {
  287.                 lyr.left = window.innerWidth - lyr.clip.width;
  288.                 clearTimeout('+id+');
  289.             } else {
  290.                 lyr.left -= (lyr.clip.width / 10);
  291.             }
  292.             break;
  293.         case 1: //right
  294.             if (window.visual.marqueeAry[lyrID] == null) {
  295.                 lyr.left = -lyr.clip.width;
  296.             } else if (lyr.left >= 0) {
  297.                 lyr.left = 0;
  298.                 clearTimeout('+id+');
  299.             } else { lyr.left += (lyr.clip.width / 10); }
  300.             break;
  301.         case 2: //top
  302.             if (window.visual.marqueeAry[lyrID] == null) {
  303.                 lyr.top = -lyr.clip.height;
  304.             } else if (lyr.top >= 0) {
  305.                 lyr.top = 0;
  306.                 clearTimeout('+id+');
  307.             } else {
  308.                 lyr.top += (lyr.clip.height / 10);
  309.             }
  310.                 break;
  311.         case 3: //btm
  312.             if (window.visual.marqueeAry[lyrID] == null) {
  313.                 lyr.top = window.innerHeight;
  314.             }
  315.             if (lyr.top <= (window.innerHeight - lyr.clip.height) ) {
  316.                 lyr.top = window.innerHeight - lyr.clip.height;
  317.                 clearTimeout('+id+');
  318.             } else {
  319.                 lyr.top -= (lyr.clip.height / 10);
  320.             }
  321.     }
  322.     lyr.visibility = 'inherit';
  323.     window.visual.marqueeAry[lyrID] = lyrID;
  324.     id = setTimeout('window.visual.marquee('+id+','+lyrID+','+ dir +')',100);
  325. }
  326. window.visual.newsBox = function() {
  327.     window.sb.top -= 1;
  328.     if (window.sb.top < -sbHeight) window.sb.top = window.sbClipHeight;
  329.     window.sbID = setTimeout('window.visual.newsBox(window.sb)',100);
  330. }
  331. window.visual.anim = function() {
  332.     if (!window.animCount) window.animCount=1;
  333.     else if (window.animCount >= window.animLength) window.animCount=0;
  334.     var img = eval('window.animImg' + window.animCount);
  335.     var link = eval('window.animLink' + window.animCount);
  336.     with(window.animLayer.document) {
  337.         open();
  338.         writeln('<A HREF="#" onClick="window.open(\''+ link +'\',0); return false;"><IMG SRC="'+ img +'" BORDER=0></A>');
  339.         close();
  340.     }
  341.     window.animCount++;
  342. }
  343. window.visual.simpleDate = function(size) {
  344.     var d = new Date();
  345.     var date = d.toString(); //improve
  346.     with(window.dateLayer) {
  347.         document.open();
  348.         document.writeln('<FONT SIZE="'+ size +'" COLOR="'+ window.dateColor +'">'+ date.substring(0,3) +'. '+ date.substring(3,10) +', 97  </FONT>');
  349.         document.close();
  350.         visibility="inherit";
  351.     }
  352. }
  353.  
  354. window.visual.changeBgColor = function(e) {
  355.     if (this.bgColor == 132) 
  356.         this.bgColor = "#CCCCCC";
  357.     else 
  358.         this.bgColor = 132;
  359. }
  360.  
  361. window.visual.doSearch = function(form) {
  362.     var page=form.page.value;
  363.     var which=form.cp.selectedIndex;
  364.     which=form.cp[which].value;
  365.     var searchstring=form.searchstring.value;
  366.     searchstring=escape(searchstring);
  367.     var newstring="";
  368.     for (var i = 0 ; i <= searchstring.length ; i++) {
  369.         thesub = searchstring.substring(i,i+1);
  370.         if (thesub != "/" && thesub != "+" && thesub != "%") {
  371.             newstring=newstring+thesub;
  372.         } else {
  373.             if (thesub == "/") {
  374.                 newstring=newstring+"%2F";
  375.             } else if (thesub == "+") {
  376.                 newstring=newstring+"%2B";
  377.             } else if (thesub == "%") {
  378.                 if (searchstring.substring(i,i+3) == "%20") {
  379.                     newstring=newstring + "+";
  380.                     i+=2;
  381.                 } else {
  382.                     newstring=newstring+thesub;
  383.                 }
  384.             }
  385.         }
  386.     }
  387.     searchstring=newstring;
  388.     var loc = "";
  389.     if (which=="default") {
  390.         alert("Sorry, but you must select a search\nservice from the pull-down menu before\nconducting a search.  Please try again.");
  391.     } else if (which=="Yahoo") {
  392.         loc = "http://home.netscape.com/misc/redirects/yahoo.html?cp=Yahoo&page="+page+"&searchstring="+searchstring;
  393.     } else if (which=="Lycos") {
  394.         loc = "http://home.netscape.com/misc/redirects/lycos.html?cp=Lycos&page="+page+"&searchstring="+searchstring;
  395.     } else if (which=="Excite") {
  396.         loc = "http://home.netscape.com/misc/redirects/excite.html?cp=Excite&page="+page+"&searchstring="+searchstring;
  397.     } else if (which=="Infoseek") {
  398.         loc = "http://home.netscape.com/misc/redirects/infoseek.html?cp=Infoseek&page="+page+"&searchstring="+searchstring;
  399.     } else if (which=="LookSmart") {
  400.         loc = "http://home.netscape.com/misc/redirects/looksmart.html?cp=LookSmart&page="+page+"&searchstring="+searchstring;
  401.     } else if (which=="WebCrawler") {
  402.         loc = "http://home.netscape.com/misc/redirects/webcrawler.html?cp=WebCrawler&page="+page+"&searchstring="+searchstring;
  403.     } else if (which=="AOL") {
  404.         loc = "http://home.netscape.com/misc/redirects/aol.html?cp=AOL&page="+page+"&searchstring="+searchstring;
  405.     } else if (which=="HotBot") {
  406.         loc = "http://home.netscape.com/misc/redirects/hotbot.html?cp=HotBot&page="+page+"&searchstring="+searchstring;
  407.     } else if (which=="SEARCH.COM") {
  408.         loc = "http://home.netscape.com/misc/redirects/searchcom.html?cp=SEARCH.COM&page="+page+"&searchstring="+searchstring;
  409.     }
  410.     window.open(loc);
  411. }
  412.  
  413. window.visual.rightMouse = function(e) { //under construction...
  414.     java.lang.System.out.println("rightMouseMenu e=" + e);
  415.     var menu = new Object();
  416.     menu.base = makeLayer("rm", "", null, 100,100, e.pageX,e.pageY, '#000000');
  417.     menu.edge = makeLayer("rm", "", menu.base, 99,99, -1,-1, '#DDDDDD');
  418.     menu.dark = makeLayer("rm", "", menu.base, 98,98, 1,1, '#888888');
  419.     menu.lite = makeLayer("rm", "", menu.base, 97,97, 1,1, '#FFFFFF');
  420.     menu.main = makeLayer("rm", "", menu.base, 96,96, 2,2, '#CCCCCC');
  421.     menu.props  = makeLayer('props', '<FONT COLOR="gray"><SPAN ID=font14>  Properties </SPAN></FONT>', menu.base, 94,20, 4,4);
  422.     menu.props.onmouseover = window.visual.changeBgColor;
  423.     menu.props.onmouseout  = window.visual.changeBgColor;
  424.     menu.dupli  = makeLayer('dupli', '<FONT COLOR="gray"><SPAN ID=font14>  Duplicate </SPAN></FONT>', menu.base, 94,20, 4,24);
  425.     menu.delet  = makeLayer('delet', '<FONT COLOR="gray"><SPAN ID=font14>  Delete </SPAN></FONT>', menu.base, 94,20, 4,48);
  426.     window.visual.rightMouseMenu = menu;
  427.     //window.Ndialog = menu;
  428. }
  429.  
  430. function makeLayer(label, content, parentLyr, width, height, x, y, color, viso) {
  431.     //java.lang.System.out.println(""+ parentLyr);
  432.     if (!content) content = " ";
  433.     if (parentLyr) var l = new Layer(width, parentLyr);
  434.     else var l = new Layer(width);
  435.     l.document.ids.font14.fontSize = 14;
  436.     l.document.ids.sysFont.fontSize = 12;
  437.     l.document.ids.sysFont.fontFamily = "Arial, Espy, sans-serif";
  438.     l.document.open("text/html");
  439.     l.document.writeln(content);
  440.     l.document.close();
  441.     l.label = label;
  442.     l.moveTo(x,y);
  443.     if (color && color != "") l.bgColor = color;
  444.     if (width) l.clip.width = width;
  445.     if (height) l.clip.height = height;
  446.     if (!viso) l.visibility = "inherit";
  447.     return l;
  448. }
  449. //window.releaseEvents(Event.MOUSEOVER|Event.MOUSEDOWN);