home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / 05_02.iso / software / netscape6 / nim.xpi / bin / chrome / aim.jar / content / aim / contextMenu.js < prev    next >
Encoding:
JavaScript  |  2001-04-05  |  7.1 KB  |  224 lines

  1. /*------------------------------ nsContextMenu ---------------------------------
  2. |   This JavaScript "class" is used to implement the IM standalon's            |
  3. |   content-area context menu.                                                 |
  4. |                                                                              |
  5. |   For usage, see references to this class in contextMenu.xul.                |
  6. |                                                                              |
  7. ------------------------------------------------------------------------------*/
  8. // global context menu
  9. //var contextMenu = null;
  10.  
  11. function nsContextMenu( xulMenu ) {
  12.   this.menu                  = null;
  13.   this.onlineTab        = false;
  14.   this.listSetupTab     = false;
  15.   this.sidebar          = false;
  16.   this.screenName       = "";
  17.   this.target           = null;
  18.  
  19.   // Initialize new menu.
  20.   this.initMenu( xulMenu );
  21. }
  22.  
  23. // Prototype for nsContextMenu "class."
  24. nsContextMenu.prototype = {
  25.  
  26.     // onDestroy is a no-op at this point.
  27.     onDestroy : function () {
  28.     },
  29.  
  30.     // Initialize context menu.
  31.     initMenu : function ( popup, event ) {
  32.         
  33.         this.menu = popup;
  34.  
  35.         // Get contextual info.
  36.         this.setTarget( document.popupNode );
  37.     
  38.         // Initialize (disable/remove) menu items.
  39.         this.initItems();
  40.     },
  41.  
  42.     initItems : function () {
  43.         this.initOnlineItems();
  44.         this.initListSetupItems();
  45.     },
  46.  
  47.     initOnlineItems : function () {
  48.         this.showItem( "context-sendIM", this.onlineTab );
  49.         this.showItem( "context-sendChat", this.onlineTab );
  50.         this.showItem( "onlineseparator", this.onlineTab );
  51.         //this.showItem( "context-EditList", this.sidebar );
  52.     },
  53.  
  54.     initListSetupItems : function () {
  55. //        this.showItem( "context-addBuddy", this.listSetupTab );
  56. //        this.showItem( "context-addGroup", this.listSetupTab );
  57. //        this.showItem( "context-delete", this.listSetupTab );
  58.         //this.showItem( "context-editAB", this.listSetupTab );
  59.     },
  60.  
  61.     // Set various context menu attributes based on the state of the world.
  62.     setTarget : function ( node ) {
  63.         // Remember the node that was clicked.
  64.         this.target = node;
  65.               var sidebarframe=window; 
  66.           // determine if we're in the standalone or sidebar
  67.         var parentState = top.document.getElementById("AimSidebarState");
  68.         if(!parentState)
  69.         {
  70.             var tab = sidebarframe.document.getElementById("OnlineOrgTabPanel");
  71.             if (tab.getAttribute('index') == 0 )  
  72.                 {
  73.                 this.sidebar = true;   
  74.                 this.onlineTab = true;
  75.                 this.listSetupTab = false;
  76.                 }        
  77.                        else
  78.                 {
  79.                 this.sidebar = true;   
  80.                                 this.onlineTab = false;
  81.                                 this.listSetupTab = true;  
  82.                 }
  83.         }
  84.         else
  85.         {
  86.               var curTab;
  87.               curTab = parentState.getAttribute("AimSidebarTab");
  88.           // Determine if we're in the Online tab or List Setup tab
  89.               if(curTab == "Online")
  90.                   {
  91.                       this.onlineTab = true;
  92.                       this.listSetupTab  = false;
  93.               this.sidebar = false;
  94.                   }
  95.               else
  96.                   {
  97.                       this.listSetupTab = true;
  98.                       this.onlineTab = false;
  99.               this.sidebar = false;
  100.                   }
  101.           }
  102.  
  103.         // set the screen name based on the target
  104.         this.screenName = this.target.parentNode.parentNode.getAttribute('ScreenName');
  105.         //dump("Context: Screen name is " + this.screenName + "\n");
  106.     },
  107.  
  108.     // sendIM
  109.     cmdContextSendIM : function () {
  110.       dump("Context: Send IM\n");
  111.     cmdNewIM();
  112. /*      if (aimIMDoesIMExist(this.screenName))
  113.               aimErrorBox(aimString("msg.DuplicateIM"));
  114.           else 
  115.                 aimIMInvokeIMForm(this.screenName, null);
  116. */
  117.     },
  118.  
  119.     // sendChat
  120.     cmdContextSendChat : function () {
  121.           //window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no','', false,'outgoingchat');
  122.      inviteArgsObj = {
  123.          inviteProposalScreenName: '', 
  124.          inviteProposalObj: null,
  125.          invitedScreenNames: getSelectedBuddiesFromList(),
  126.          inviteToExistingWindow: false,
  127.          inviteMode: 'outgoingchat'
  128.          }
  129.           window.openDialog('chrome://aim/content/chatInviteBuddy.xul','_blank','chrome,all,dialog=no',inviteArgsObj);
  130.  
  131.  
  132.           dump("Context: Chat\n");
  133.     },
  134.  
  135.     // Edit List
  136.     cmdContextEditList : function  () {
  137.       dump("Context: Edit List\n");
  138.       //toOpenWindowByType2('Aim:AimApp', 'chrome://aim/content/App.xul');
  139.     },
  140.  
  141.     // addbuddy
  142.     cmdContextAddBuddy : function () {
  143.       dump("Context: Add Buddy\n");
  144.       cmdAddBuddy();
  145.     },
  146.  
  147.     // addGroup
  148.     cmdContextAddGroup : function () {
  149.       dump("Context: Add Group\n");
  150.       cmdAddGroup();
  151.     },
  152.  
  153.       // delete
  154.     cmdContextDelete : function () {
  155.       dump("Context: Delete\n");
  156.       cmdDelete();
  157.     },
  158.  
  159.     //cmdContextEditAB : function () {
  160.       //dump("Context: Edit AddressBook\n");
  161.       //cmdAbEditCard();
  162.     //},     
  163.  
  164.     // Utilities
  165.  
  166.     // Show/hide one item (specified via name or the item element itself).
  167.     showItem : function ( itemOrId, show ) {
  168.         var item = null;
  169.         if ( itemOrId.constructor == String ) {
  170.             // Argument specifies item id.
  171.             item = document.getElementById( itemOrId );
  172.         } else {
  173.             // Argument is the item itself.
  174.             item = itemOrId;
  175.         }
  176.         if ( item ) {
  177.             var styleIn = item.getAttribute( "style" );
  178.             var styleOut = styleIn;
  179.             if ( show ) {
  180.                 // Remove style="display:none;".
  181.                 styleOut = styleOut.replace( "display:none;", "" );
  182.  
  183.             } else {
  184.                 // Set style="display:none;".
  185.                 if ( styleOut.indexOf( "display:none;" ) == -1 ) {
  186.                     // Add style the first time we need to.
  187.                     styleOut += "display:none;";
  188.                 }
  189.             }
  190.             // Only set style if it's different.
  191.             if ( styleIn != styleOut ) {
  192.                 item.setAttribute( "style", styleOut );
  193.             }
  194.         }
  195.     },
  196.  
  197.     // Set given attribute of specified context-menu item.  If the
  198.     // value is null, then it removes the attribute (which works
  199.     // nicely for the disabled attribute).
  200.     setItemAttr : function ( id, attr, val ) {
  201.         var elem = document.getElementById( id );
  202.         if ( elem ) {
  203.             if ( val == null ) {
  204.                 // null indicates attr should be removed.
  205.                 elem.removeAttribute( attr );
  206.             } else {
  207.                 // Set attr=val.
  208.                 elem.setAttribute( attr, val );
  209.             }
  210.         }
  211.     },
  212.  
  213.     // Set context menu attribute according to like attribute of another node
  214.     // (such as a broadcaster).
  215.     setItemAttrFromNode : function ( item_id, attr, other_id ) {
  216.         var elem = document.getElementById( other_id );
  217.         if ( elem && elem.getAttribute( attr ) == "true" ) {
  218.             this.setItemAttr( item_id, attr, "true" );
  219.         } else {
  220.             this.setItemAttr( item_id, attr, null );
  221.         }
  222.     }
  223. };
  224.