home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / browser / ns405lyc / netcast.z / ncjs10.jar / tab.js < prev    next >
Encoding:
JavaScript  |  1998-03-06  |  11.1 KB  |  429 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('', 'Netcaster_Splash','');
  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.     var useFocusToggle = GetNetscapePrefBool("netcaster.autoFocus", false, false);
  193.     if (useFocusToggle) {
  194.         window.onFocus = autoFocus;
  195.     }
  196.  
  197.     return true;
  198. }
  199.  
  200. /**********************************************************************
  201.  * ToggleSelector, ShowSelector, HideSelector
  202.  *
  203.  * The selector gets created offscreen initially, then moved by PositionSelector();
  204.  *
  205.  * Only one selector can be active at a time, so if another one exits, there's something
  206.  * wrong.  Rather than simply trust the other one (which might be a spoof), we explicitly
  207.  * close the other one, then create our own.  Therefore, THIS FUNCTION MUST BE CALLED
  208.  * EXACTLY ONCE DURING THE EXECUTION OF THE PROGRAM 
  209.  *
  210.  */
  211.  
  212. /* Functions that toggle the state of the drawer */
  213.  
  214. function ToggleSelector()
  215. {
  216.     if (selectorVisible == 0) {
  217.         ShowSelector();
  218.     } else {
  219.         if (focusToggle == 0)
  220.         HideSelector();
  221.         else
  222.         focusToggle = 0;
  223.     }
  224. }
  225.  
  226. function ShowSelector()
  227. {
  228.     if (selectorVisible) {
  229.         return;
  230.     }
  231.  
  232.     if (selectorDock == "left") {
  233.  
  234.         if (drawer != null) {
  235.             for (i = (screen.availLeft - selectorWidth); i < screen.availLeft; i += animateSteps)
  236.             {
  237.                 SecureMoveWindow(drawer, i, screen.availTop);
  238.             }
  239.             SecureMoveWindow(drawer, screen.availLeft, screen.availTop);
  240.         }
  241.  
  242.         SecureMoveWindow(selectorTab, screen.availLeft + selectorWidth, tabVPos);
  243.  
  244.         document.layers["right"].visibility = "show";
  245.         document.layers["left"].visibility = "hide";
  246.  
  247.     } else  {
  248.         /* if (selectorDock == "right") */
  249.         
  250.         var availRight = screen.availLeft + screen.availWidth
  251.         var selectorPos = availRight - selectorWidth;
  252.  
  253.         if (drawer != null) {
  254.             for (i = availRight; i > selectorPos; i -= animateSteps)
  255.             {
  256.                 SecureMoveWindow(drawer, i, screen.availTop);
  257.             }
  258.  
  259.             SecureMoveWindow(drawer, selectorPos, screen.availTop);
  260.         }
  261.  
  262.         SecureMoveWindow(selectorTab, selectorPos - tabWidth, tabVPos);
  263.  
  264.         document.layers["right"].visibility = "hide";
  265.         document.layers["left"].visibility = "show";
  266.     }
  267.  
  268.     selectorVisible = 1;
  269. }
  270.  
  271. function HideSelector()
  272. {
  273.     if (selectorVisible == 0)
  274.         return;
  275.  
  276.     if (drawer.fullyLoaded == 1) {
  277.         drawer.selector.hideMenu();
  278.     }
  279.  
  280.     if (selectorDock == "left") 
  281.     {
  282.         SecureMoveWindow(selectorTab, screen.availLeft, tabVPos);
  283.  
  284.         if (drawer != null) 
  285.         {
  286.             for (i = screen.availLeft; i > screen.availLeft-selectorWidth; i -= animateSteps) 
  287.                 SecureMoveWindow(drawer, i, screen.availTop);
  288.  
  289.             SecureMoveWindow(drawer, screen.availLeft-selectorWidth, screen.availTop);
  290.         }
  291.  
  292.         document.layers["right"].visibility = "hide";
  293.         document.layers["left"].visibility = "show";
  294.     } 
  295.     else 
  296.     {
  297.         /* if (selectorDock == "right") */
  298.         
  299.         var availRight = screen.availLeft + screen.availWidth
  300.         var selectorPos = availRight - selectorWidth;
  301.  
  302.         SecureMoveWindow(selectorTab, availRight - tabWidth, tabVPos);
  303.  
  304.         if (drawer != null) 
  305.         {
  306.             for (i = (availRight - selectorWidth); i < availRight; i += animateSteps)
  307.                 SecureMoveWindow(drawer, i, screen.availTop);
  308.  
  309.             SecureMoveWindow(drawer, availRight, screen.availTop);
  310.         }
  311.  
  312.         document.layers["right"].visibility = "show";
  313.         document.layers["left"].visibility = "hide";
  314.     }
  315.     
  316.     selectorVisible = 0;
  317.  
  318. }
  319.  
  320. function FocusTimeout() 
  321. {
  322.     //The only real way we can differentiate between a focus event
  323.     //due to switching tasks to the window and clicking on the window
  324.     //is whether the focus event is followed quickly by a click.
  325.     focusToggle = 0;
  326. }
  327.  
  328. /* Slide selector out when tab window gains focus */
  329. function autoFocus() 
  330. {
  331.     if ( (drawer != null && selectorVisible == 0)
  332.         && ((drawer.fullyLoaded == 1)
  333.         && (drawer.titlebar.getFinishedLoading() == 1))) {
  334.     ShowSelector();
  335.     // Bool to indicate if window toggle was by focus event to prevent
  336.     // second toggle command from click event.
  337.     focusToggle = 1;
  338.     }
  339.     setTimeout(FocusTimeout, 500);
  340. }
  341.  
  342. /* This is the global quit us method */
  343.  
  344.  
  345. function closeNetCast()
  346. {
  347.     removeSplash();
  348.  
  349.     netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite"); 
  350.  
  351.     // nettop.close();
  352.     drawer.close();
  353.     selectorTab.close();
  354. }
  355.  
  356. function forceCloseNetcaster()
  357. {
  358.     removeSplash();
  359.  
  360.     if (drawer) {    
  361.         drawer.close();
  362.     }
  363.  
  364.     if (selectorTab) {
  365.         selectorTab.close();
  366.     }
  367. }
  368.  
  369. function closeNetCast()
  370. {
  371.     netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite"); 
  372.  
  373.     drawer.close();
  374.     selectorTab.close();
  375. }
  376.  
  377. // These functions are called from public APIs
  378.  
  379. function getChannelObject()
  380. {
  381.     return new ChannelObject();
  382. }
  383.  
  384. function addChannel(chanObj)
  385. {
  386.     drawer.titlebar.document.demo.AddChannel(chanObj);
  387.  
  388. }
  389.  
  390. function addInfoblock(infoblockObj)
  391. {
  392.     drawer.titlebar.document.demo.AddInfoblock(infoblockObj);
  393.  
  394. }
  395.  
  396. function setVersion()
  397. {
  398.     componentVersion = drawer.titlebar.document.demo.getNetcasterVersion();
  399. }
  400.  
  401. // Compatibility functions 
  402. var GetChannelObject = getChannelObject;
  403. var AddChannelObject = addChannel;
  404.  
  405. export GetChannelObject;
  406. export getChannelObject;
  407. export AddChannelObject;
  408. export addChannel;
  409. export addInfoblock;
  410. export componentVersion;
  411. export componentName;
  412.  
  413. // Perform all initial operations which do not require us to be fully loaded.
  414.  
  415. compromisePrincipals();
  416. window.onMouseDown = SupressRightMouse;
  417. window.onerror = SupressError;
  418. window.onDragDrop = SupressDrag;
  419. window.captureEvents(Event.MOUSEDOWN | Event.ERROR | Event.DRAGDROP);
  420.  
  421. // The last thing we do is to create the selector
  422.  
  423. ShowSplash();
  424. if (CreateSelector()) {
  425.     PositionSelector(); 
  426. }
  427.  
  428. void(0);
  429.