home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 April / VPR9804B.ISO / Netscape / NETCAST.Z / ncjs10.jar / tab.js < prev    next >
Text File  |  1997-09-03  |  11KB  |  424 lines

  1. /*
  2.  * tab.js
  3.  * 
  4.  * Copyright (c) 1997 Netscape Communications Corporation, All Rights Reserved
  5.  * 
  6.  * Tab functions
  7.  */
  8.  
  9. // utils.js must have been previously included
  10.  
  11. // Calculate the correct selector height for this platform.
  12. function calcSelectorHeight() {
  13.   var h=screen.availHeight;
  14.  
  15.   // AIX (or maybe Dogbert for AIX) has trouble showing a window
  16.   // greater than 1000 pixels high.  No, I don't know why 1000.
  17.   //  -- francis.
  18.   if (   (h>1000)
  19.       && (navigator.platform.indexOf('AIX4')==0)
  20.       )
  21.     h=1000;
  22.  
  23.   return h;
  24. }
  25.  
  26. var selectorVisible     = 0;
  27. var selectorWidth       = 200;
  28. var selectorHeight        = calcSelectorHeight();
  29. var tabVPos                = screen.availHeight - 250;
  30. var tabWidth            = 20;
  31. var animateSteps        = 200;
  32. var selectorTab         = this;
  33. var splashScreen        = null;
  34. var drawer                = null;
  35. var selectorDock;
  36. var focusToggle        = 0;
  37. var componentVersion    = "unknown";
  38. var componentName        = "Netscape Netcaster";
  39.  
  40. // This window is already open, we just need to get a handle to it.
  41. function ShowSplash() {
  42.  
  43.     splashScreen = window.open('ncsplash.htm', 'Netcaster_Splash','top=100,width=450,height=150,hotkeys=no');
  44. }
  45.  
  46. function setSplashText(textIndex) {
  47.     if ((splashScreen != null) && (splashScreen.closed == false)) {
  48.         if (splashScreen.changeSplashText) {
  49.             splashScreen.changeSplashText(textIndex);
  50.         }
  51.     }
  52. }
  53.  
  54. function removeSplash() {
  55.     if ((splashScreen != null) && (splashScreen.closed == false)) {
  56.         splashScreen.close();
  57.         splashScreen = null;
  58.     }
  59. }
  60.  
  61.  
  62. /**********************************************************************
  63.  * PositionSelector
  64.  *
  65.  * positionSelector moves the selector tab and drawer depending on the
  66.  * available screen size and docking preference(s).
  67.  *
  68.  */
  69. function PositionSelector() {
  70.  
  71.     selectorDock = GetNetscapePref("netcaster.drawer.dock", "right", false);
  72.  
  73.     if (selectorDock == "left") {
  74.         
  75.         // if the container is open, move it first
  76.         
  77.         if (drawer != null) {
  78.             if (selectorVisible) {
  79.                 SecureMoveWindow(drawer, screen.availLeft, screen.availTop);
  80.             } else {
  81.                 SecureMoveWindow(drawer, screen.availLeft-selectorWidth, screen.availTop);
  82.             }
  83.  
  84.         }
  85.  
  86.         if (selectorTab != null) {
  87.             tabVPos = GetNetscapePref("netcaster.tabPosition", tabVPos, false);
  88.  
  89.             // make sure that the arrow is showing the right directionality
  90.  
  91.             if (selectorVisible) {
  92.                 SecureMoveWindow(selectorTab, screen.availLeft + selectorWidth, tabVPos);
  93.  
  94.                 document.layers["right"].visibility = "hide";
  95.                 document.layers["left"].visibility = "show";
  96.             } else {
  97.                 SecureMoveWindow(selectorTab, screen.availLeft, tabVPos);
  98.     
  99.                 document.layers["right"].visibility = "show";
  100.                 document.layers["left"].visibility = "hide";
  101.             }
  102.         }
  103.  
  104.     } else {
  105.         // the default is right
  106.         var selectorPos = screen.availLeft + screen.availWidth - selectorWidth;
  107.  
  108.         if (drawer != null) {
  109.             if (selectorVisible) {
  110.                 SecureMoveWindow(drawer, selectorPos, screen.availTop);            
  111.             } else {
  112.                 var availRight = screen.availLeft + screen.availWidth
  113.                 SecureMoveWindow(drawer, availRight, screen.availTop);
  114.             }
  115.         }
  116.  
  117.         if (selectorTab != null) {
  118.             tabVPos = GetNetscapePref("netcaster.tabPosition", tabVPos, false);
  119.  
  120.             // make sure that the arrow is showing the right directionality
  121.  
  122.             if (selectorVisible) {
  123.                 SecureMoveWindow(selectorTab, selectorPos - tabWidth, tabVPos);
  124.                 document.layers["right"].visibility = "show";
  125.                 document.layers["left"].visibility = "hide";
  126.             } else {
  127.                 SecureMoveWindow(selectorTab, screen.availLeft + screen.availWidth - tabWidth, tabVPos);
  128.                 document.layers["right"].visibility = "hide";
  129.                 document.layers["left"].visibility = "show";
  130.             }
  131.         }
  132.     }
  133.  
  134.     // then, resize the drawer
  135.     
  136.     if (drawer != null) {
  137.         selectorHeight = calcSelectorHeight();
  138.         drawer.resizeTo(selectorWidth, selectorHeight, true);
  139.  
  140.     }
  141.  
  142.     return;
  143. }
  144.  
  145.  
  146. /**********************************************************************
  147.  * CreateSelector
  148.  *
  149.  * The selector gets created offscreen initially, then moved by PositionSelector();
  150.  *
  151.  * Only one selector can be active at a time, so if another one exits, there's something
  152.  * wrong.  Rather than simply trust the other one (which might be a spoof), we explicitly
  153.  * close the other one, then create our own.  Therefore, THIS FUNCTION MUST BE CALLED
  154.  * EXACTLY ONCE DURING THE EXECUTION OF THE PROGRAM 
  155.  *
  156.  */
  157.  
  158. function CreateSelector()
  159. {
  160.     setSplashText(2);
  161.  
  162.     // Yes, the enablePrivilege below asks for far more than it needs, but we want
  163.     // the user to accept the Netcaster privilege now so we have all of the
  164.     // component pieces which the macro target references later on.
  165.  
  166.     netscape.security.PrivilegeManager.enablePrivilege("Netcaster"); 
  167.  
  168.     var loadImages = GetNetscapePrefBool("general.always_load_images", true, false);
  169.  
  170.     if (!loadImages) {
  171.         if (!confirm("Because Netcaster and Netcaster channels are graphically intensive, Netscape recommends you " +
  172.             "leave checked the Automatically Load Images item in the Advanced preferences pane.  If you continue " +
  173.             "without doing so, Netcaster will load, but some graphical elements may be missing or incomplete.  Continue?")) {
  174.             components["netcaster"].forceCloseNetcaster();
  175.             return false;
  176.         }
  177.     }
  178.  
  179.  
  180.     if (drawer != null) {
  181.         drawer.close();
  182.     }
  183.  
  184.     var options = "left=-15000,top=-15000,width="+selectorWidth+",height="+selectorHeight+",titlebar=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,dependent=yes,hotkeys=no";
  185.  
  186.     if ("true" == GetNetscapePref("netcaster.alwaysTop", "true", false)) {
  187.         options = options  + ',alwaysRaised=yes,z-lock=yes'
  188.     }
  189.  
  190.     drawer = SecureWindowOpen(self,'netcast.htm', 'Netscape_Netcaster_Drawer', options);
  191.  
  192.     return true;
  193. }
  194.  
  195. /**********************************************************************
  196.  * ToggleSelector, ShowSelector, HideSelector
  197.  *
  198.  * The selector gets created offscreen initially, then moved by PositionSelector();
  199.  *
  200.  * Only one selector can be active at a time, so if another one exits, there's something
  201.  * wrong.  Rather than simply trust the other one (which might be a spoof), we explicitly
  202.  * close the other one, then create our own.  Therefore, THIS FUNCTION MUST BE CALLED
  203.  * EXACTLY ONCE DURING THE EXECUTION OF THE PROGRAM 
  204.  *
  205.  */
  206.  
  207. /* Functions that toggle the state of the drawer */
  208.  
  209. function ToggleSelector()
  210. {
  211.     if (selectorVisible == 0) {
  212.         ShowSelector();
  213.     } else {
  214.         if (focusToggle == 0)
  215.         HideSelector();
  216.         else
  217.         focusToggle = 0;
  218.     }
  219. }
  220.  
  221. function ShowSelector()
  222. {
  223.     if (selectorVisible) {
  224.         return;
  225.     }
  226.  
  227.     if (selectorDock == "left") {
  228.  
  229.         if (drawer != null) {
  230.             for (i = (screen.availLeft - selectorWidth); i < screen.availLeft; i += animateSteps)
  231.             {
  232.                 SecureMoveWindow(drawer, i, screen.availTop);
  233.             }
  234.             SecureMoveWindow(drawer, screen.availLeft, screen.availTop);
  235.         }
  236.  
  237.         SecureMoveWindow(selectorTab, screen.availLeft + selectorWidth, tabVPos);
  238.  
  239.         document.layers["right"].visibility = "show";
  240.         document.layers["left"].visibility = "hide";
  241.  
  242.     } else  {
  243.         /* if (selectorDock == "right") */
  244.         
  245.         var availRight = screen.availLeft + screen.availWidth
  246.         var selectorPos = availRight - selectorWidth;
  247.  
  248.         if (drawer != null) {
  249.             for (i = availRight; i > selectorPos; i -= animateSteps)
  250.             {
  251.                 SecureMoveWindow(drawer, i, screen.availTop);
  252.             }
  253.  
  254.             SecureMoveWindow(drawer, selectorPos, screen.availTop);
  255.         }
  256.  
  257.         SecureMoveWindow(selectorTab, selectorPos - tabWidth, tabVPos);
  258.  
  259.         document.layers["right"].visibility = "hide";
  260.         document.layers["left"].visibility = "show";
  261.     }
  262.  
  263.     selectorVisible = 1;
  264. }
  265.  
  266. function HideSelector()
  267. {
  268.     if (selectorVisible == 0)
  269.         return;
  270.  
  271.     if (drawer.fullyLoaded == 1) {
  272.         drawer.selector.hideMenu();
  273.     }
  274.  
  275.     if (selectorDock == "left") 
  276.     {
  277.         SecureMoveWindow(selectorTab, screen.availLeft, tabVPos);
  278.  
  279.         if (drawer != null) 
  280.         {
  281.             for (i = screen.availLeft; i > screen.availLeft-selectorWidth; i -= animateSteps) 
  282.                 SecureMoveWindow(drawer, i, screen.availTop);
  283.  
  284.             SecureMoveWindow(drawer, screen.availLeft-selectorWidth, screen.availTop);
  285.         }
  286.  
  287.         document.layers["right"].visibility = "hide";
  288.         document.layers["left"].visibility = "show";
  289.     } 
  290.     else 
  291.     {
  292.         /* if (selectorDock == "right") */
  293.         
  294.         var availRight = screen.availLeft + screen.availWidth
  295.         var selectorPos = availRight - selectorWidth;
  296.  
  297.         SecureMoveWindow(selectorTab, availRight - tabWidth, tabVPos);
  298.  
  299.         if (drawer != null) 
  300.         {
  301.             for (i = (availRight - selectorWidth); i < availRight; i += animateSteps)
  302.                 SecureMoveWindow(drawer, i, screen.availTop);
  303.  
  304.             SecureMoveWindow(drawer, availRight, screen.availTop);
  305.         }
  306.  
  307.         document.layers["right"].visibility = "show";
  308.         document.layers["left"].visibility = "hide";
  309.     }
  310.     
  311.     selectorVisible = 0;
  312.  
  313. }
  314.  
  315. function FocusTimeout() 
  316. {
  317.     //The only real way we can differentiate between a focus event
  318.     //due to switching tasks to the window and clicking on the window
  319.     //is whether the focus event is followed quickly by a click.
  320.     focusToggle = 0;
  321. }
  322.  
  323. /* Slide selector out when tab window gains focus */
  324. function onfocus() 
  325. {
  326.     if ( (drawer != null && selectorVisible == 0)
  327.         && ((drawer.fullyLoaded == 1)
  328.         && (drawer.titlebar.getFinishedLoading() == 1))) {
  329.     ShowSelector();
  330.     // Bool to indicate if window toggle was by focus event to prevent
  331.     // second toggle command from click event.
  332.     focusToggle = 1;
  333.     }
  334.     setTimeout(FocusTimeout, 500);
  335. }
  336.  
  337. /* This is the global quit us method */
  338.  
  339.  
  340. function closeNetCast()
  341. {
  342.     removeSplash();
  343.  
  344.     netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite"); 
  345.  
  346.     // nettop.close();
  347.     drawer.close();
  348.     selectorTab.close();
  349. }
  350.  
  351. function forceCloseNetcaster()
  352. {
  353.     removeSplash();
  354.  
  355.     if (drawer) {    
  356.         drawer.close();
  357.     }
  358.  
  359.     if (selectorTab) {
  360.         selectorTab.close();
  361.     }
  362. }
  363.  
  364. function closeNetCast()
  365. {
  366.     netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite"); 
  367.  
  368.     drawer.close();
  369.     selectorTab.close();
  370. }
  371.  
  372. // These functions are called from public APIs
  373.  
  374. function getChannelObject()
  375. {
  376.     return new ChannelObject();
  377. }
  378.  
  379. function addChannel(chanObj)
  380. {
  381.     drawer.titlebar.document.demo.AddChannel(chanObj);
  382.  
  383. }
  384.  
  385. function addInfoblock(infoblockObj)
  386. {
  387.     drawer.titlebar.document.demo.AddInfoblock(infoblockObj);
  388.  
  389. }
  390.  
  391. function setVersion()
  392. {
  393.     componentVersion = drawer.titlebar.document.demo.getNetcasterVersion();
  394. }
  395.  
  396. // Compatibility functions 
  397. var GetChannelObject = getChannelObject;
  398. var AddChannelObject = addChannel;
  399.  
  400. export GetChannelObject;
  401. export getChannelObject;
  402. export AddChannelObject;
  403. export addChannel;
  404. export addInfoblock;
  405. export componentVersion;
  406. export componentName;
  407.  
  408. // Perform all initial operations which do not require us to be fully loaded.
  409.  
  410. compromisePrincipals();
  411. window.onMouseDown = SupressRightMouse;
  412. window.onerror = SupressError;
  413. window.onDragDrop = SupressDrag;
  414. window.captureEvents(Event.MOUSEDOWN | Event.ERROR | Event.DRAGDROP);
  415.  
  416. // The last thing we do is to create the selector
  417.  
  418. ShowSplash();
  419. if (CreateSelector()) {
  420.     PositionSelector(); 
  421. }
  422.  
  423. void(0);
  424.