home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / comm.jar / content / editor / sb-file-contextMenu.js < prev    next >
Encoding:
JavaScript  |  2001-03-21  |  3.2 KB  |  107 lines

  1. /*
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  *
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  *
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *   Ben Goodger
  22.  */
  23.  
  24. function fillContextMenu(name,node)
  25. {
  26.     if (!name)    return(false);
  27.     var popupNode = document.getElementById(name);
  28.     if (!popupNode)    return(false);
  29.  
  30.     var url = GetFileURL(node);             // get the URL of the selected file
  31.     var ext = getFileExtension(url);        // get the extension (type) of file
  32.  
  33.     // remove the menu node (which tosses all of its kids);
  34.     // do this in case any old command nodes are hanging around
  35.     var menuNode = popupNode.childNodes[0];
  36.     popupNode.removeChild(menuNode);
  37.  
  38.     // create a new menu node
  39.     menuNode = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menu");
  40.     popupNode.appendChild(menuNode);
  41.  
  42.     switch(ext) {
  43.     case "gif":
  44.     case "jpg":
  45.     case "jpeg":
  46.     case "png":
  47.         isImageFile(menuNode,url);
  48.         break;
  49.     case "htm":
  50.     case "html":
  51.         isHTMLFile(menuNode,url);
  52.         break;
  53.     default:
  54.         break;
  55.     }
  56.  
  57.     return(true);
  58. }
  59.  
  60. function GetFileURL(node)
  61. {
  62.     var url = node.getAttribute('id');
  63.  
  64.     // Ignore "NC:" urls.
  65.     if (url.substring(0, 3) == "NC:")
  66.     {
  67.         return(false);
  68.     }
  69.  
  70.   try
  71.   {
  72.     // add support for IE favorites under Win32, and NetPositive URLs under BeOS
  73.     if (url.indexOf("file://") == 0)
  74.     {
  75.       var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
  76.       if (rdf)   rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
  77.       if (rdf)
  78.       {
  79.         var fileSys = rdf.GetDataSource("rdf:files");
  80.         if (fileSys)
  81.         {
  82.           var src = rdf.GetResource(url, true);
  83.           var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
  84.           var target = fileSys.GetTarget(src, prop, true);
  85.           if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
  86.           if (target) target = target.Value;
  87.           if (target) url = target;
  88.  
  89.         }
  90.       }
  91.     }
  92.   }
  93.   catch(ex)
  94.   {
  95.   }
  96.     return url;
  97. }
  98.  
  99. function isImageFile(parent,url)
  100. {
  101.     // note: deleted all the doContextCmd stuff from bookmarks.
  102.     var menuItem = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "menuitem");
  103.     menuItem.setAttribute("label","Insert Image");
  104.     // menuItem.setAttribute("onaction","AutoInsertImage(\'" + url + "\')");
  105.     parent.appendChild(menuItem);
  106. }
  107.