home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 August / PCpro_2005_08.ISO / files / firefox / ieview.xpi / chrome / ieview.jar / content / ieviewOverlay.js < prev    next >
Encoding:
JavaScript  |  2005-06-02  |  24.3 KB  |  1,030 lines

  1. /* 
  2.  *
  3.  * Copyright (c) 2003  Paul Roub <paul@roub.net>
  4.  *
  5.  * $Header: /cvs/ieview/ieview/content/ieviewOverlay.js,v 1.27 2005/06/02 20:41:15 roub Exp $
  6.  *
  7.  * Portions based on GPLed code by
  8.  *     Ted Mielczarek
  9.  *
  10.  * This library is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU Lesser General Public
  12.  * License as published by the Free Software Foundation; either
  13.  * version 2.1 of the License, or (at your option) any later version.
  14.  * 
  15.  * This library is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  18.  * Lesser General Public License for more details.
  19.  * 
  20.  * You should have received a copy of the GNU Lesser General Public
  21.  * License along with this library; if not, write to the Free Software
  22.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23.  *
  24.  * *****
  25.  *
  26.  * Notes:
  27.  *
  28.  *    Since we can't know ahead of time where IE will be installed, we Kiboze the
  29.  *    Start Menu tree.  If the shortcut has been renamed (i.e. it is no longer
  30.  *    titled "Internet Explorer"), we're out of luck.  The only option at that
  31.  *    point would be to open and dereference every symlink we find, and see if the
  32.  *    target leaf name is "iexplore.exe".  Not doing that at the moment, since
  33.  *    it just seems insane.
  34.  */
  35.  
  36. var    gIeViewBundle;
  37. var     gOldOpenOneBookmark = null;
  38.  
  39. function ieviewAlert(msg)
  40. {
  41.     // alert(msg);
  42. }
  43.  
  44. var IeView = {
  45.    
  46.    ieviewMenuItems: new Array("ieview-do-view", "ieview-do-forcepage"),
  47.    ieviewLinkMenuItems: new Array("ieview-do-viewlink", "ieview-do-forcelink", "ieview-do-forcelink-menu"),
  48.    userPrograms: "Progs",
  49.    allUserPrograms: "CmPrgs",
  50.    applicationData: "AppData",
  51.    
  52.    isJsLink: function(href)
  53.    {
  54.      return(! this.isForceable(href));
  55.    },
  56.  
  57.    enableForceIE: function()
  58.    { 
  59.      var    enabled = true;
  60.      var    pref = this.getBoolPref("ieview.disableForce", false);
  61.  
  62.      if (pref)
  63.      {
  64.     enabled = false;
  65.      }
  66.  
  67.      return(enabled);
  68.    },
  69.    
  70.    ieviewContext: function() 
  71.    {
  72.       if (gContextMenu)
  73.       {
  74.          var i;
  75.  
  76.          for ( i=0; i < this.ieviewMenuItems.length; i++)
  77.          {
  78.             var menuitem = document.getElementById(this.ieviewMenuItems[i]);
  79.  
  80.             if (menuitem)      // click-on-page item
  81.             {
  82.                menuitem.hidden = (gContextMenu.isTextSelected || gContextMenu.onLink || gContextMenu.onImage || gContextMenu.onTextInput ) ||
  83.             ((! this.enableForceIE()) && (this.ieviewMenuItems[i].indexOf("force") >= 0));
  84.             }
  85.          }
  86.  
  87.      for ( i = 0; i < this.ieviewLinkMenuItems.length; ++i )
  88.      {
  89.         var menuitem = document.getElementById(this.ieviewLinkMenuItems[i]);
  90.       
  91.             if (menuitem)      // click-on-link item
  92.             {
  93.                menuitem.hidden = (! gContextMenu.onLink)  || // no link, no link item
  94.             ((! this.enableForceIE()) && (this.ieviewMenuItems[i].indexOf("force") >= 0));
  95.                
  96.                // disable the link if it's javascript
  97.                //
  98.                var disable = ((! menuitem.hidden) && this.isJsLink(gContextMenu.linkURL()));
  99.                
  100.                if (disable)
  101.                   menuitem.setAttribute('disabled', 'true');
  102.                else
  103.                   menuitem.setAttribute('disabled', 'false');
  104.             }
  105.          }
  106.       }
  107.    },
  108.    
  109.    ieView: function() 
  110.    {
  111.          var href = gBrowser.currentURI.spec;
  112.          
  113.          this.ieViewLaunch("Internet Explorer.lnk", href);
  114.    },
  115.    
  116.    
  117.    ieViewLink: function() 
  118.    {
  119.       if (gContextMenu)
  120.       {
  121.          var href = gContextMenu.linkURL();
  122.          
  123.          this.ieViewLaunch("Internet Explorer.lnk", href);
  124.       }
  125.    },
  126.  
  127.    saveIeLoc: function(path)
  128.    {
  129.          var prefService = Components.classes["@mozilla.org/preferences-service;1"]
  130.                                .getService(Components.interfaces.nsIPrefService);
  131.  
  132.          var prefs = prefService.getBranch("");
  133.  
  134.          prefs.setCharPref("ieview.ieapp", path);
  135.    },
  136.  
  137.    confirmAdd: function(href)
  138.    {
  139.       var alwaysMsg = "Will always use IE to open URLs beginning with";
  140.  
  141.       try
  142.       {
  143.          alwaysMessage = gIeViewBundle.getString("ieview.alwaysopenwith");
  144.       }
  145.       catch(e)
  146.       {
  147.          alert(e);
  148.      return(false);
  149.       }
  150.      
  151.       alwaysMessage += " " + href;
  152.  
  153.       return( confirm(alwaysMessage) );
  154.    },
  155.  
  156.    addForce: function(href)
  157.    {
  158.     var root = href;
  159.  
  160.         var cls = Components.classes["@mozilla.org/network/io-service;1"];
  161.         var srv = cls.getService(Components.interfaces.nsIIOService);
  162.  
  163.     var uri = false;
  164.  
  165.     try
  166.     {
  167.        uri = srv.newURI(href, null, null);
  168.     }
  169.     catch(e)
  170.     {
  171.         uri = false;
  172.     }
  173.  
  174.     if (uri && uri.prePath && uri.username && uri.userPass)
  175.     {                        
  176.             uri.username = '';
  177.             uri.userPass = '';
  178.  
  179.             root = uri.prePath;
  180.     }
  181.  
  182.     if (! this.confirmAdd(root))
  183.     {
  184.       return(false);
  185.     }
  186.  
  187.         var forces = this.getForceList();
  188.         forces[forces.length] = root;
  189.         var forceStr = forces.join(" ");
  190.  
  191.          var prefService = Components.classes["@mozilla.org/preferences-service;1"]
  192.                                .getService(Components.interfaces.nsIPrefService);
  193.  
  194.          var prefs = prefService.getBranch("");
  195.  
  196.          prefs.setCharPref("ieview.forceielist", forceStr);
  197.  
  198.     return(true);
  199.    },
  200.  
  201.  
  202.    forceLink: function()
  203.    {
  204.         if (! gContextMenu)
  205.         {
  206.                 return;
  207.         }
  208.  
  209.         var href = gContextMenu.linkURL();
  210.         
  211.         this.addForce(href);
  212.  
  213.         this.ieViewLink();
  214.    },
  215.    
  216.    forcePage: function()
  217.    {
  218.          var href = gBrowser.currentURI.spec;
  219.         
  220.         if (this.addForce(href))
  221.     {
  222.        this.ieView();
  223.     }
  224.    },
  225.    
  226.    
  227.    // attempt to grab the real path of a predefined directory
  228.    //
  229.    tryDir: function(dsp, key)
  230.    {
  231.       try
  232.       {
  233.          var nif = dsp.get(key, Components.interfaces.nsIFile);
  234.          return(nif.path);
  235.       }
  236.       catch (ar)
  237.       {
  238.          return("");
  239.       }
  240.    },
  241.    
  242.    
  243.    searchPath: function(path, fname)
  244.    {
  245.       var result = null;
  246.  
  247.       try
  248.       {
  249.          var f = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  250.    
  251.          f.initWithPath(path);
  252.    
  253.          if (f.exists() && f.isDirectory())
  254.          {
  255.             var entries = f.directoryEntries;
  256.    
  257.             while (entries.hasMoreElements())
  258.             {
  259.                var ent = entries.getNext().QueryInterface(Components.interfaces.nsIFile);
  260.    
  261.                if (ent.isDirectory())
  262.                {
  263.                   result = this.searchPath(ent.path, fname);
  264.    
  265.                   if (result)
  266.                   {
  267.                      break;
  268.                   }
  269.                }
  270.                else if (ent.isSymlink())
  271.                {
  272.                   if (ent.leafName.toLowerCase() == fname.toLowerCase())
  273.                   {
  274.                      result = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  275.                      result.followLinks = true;
  276.                      result.initWithPath(ent.path);
  277.    
  278.                      if (result.target == "")
  279.                      {
  280.                         result = null;
  281.                      }
  282.                      else
  283.                      {
  284.                         break;
  285.                      }
  286.                   }
  287.                }
  288.                else if (ent.isFile())
  289.                {
  290.                   if (ent.leafName.toLowerCase() == fname.toLowerCase())
  291.                   {
  292.                      result = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  293.                      result.initWithPath(ent.path);
  294.                      break;
  295.                   }
  296.                }
  297.             }
  298.          }
  299.       }
  300.       catch (ar)
  301.       {
  302.          return(null);
  303.       }
  304.    
  305.       return( result );
  306.    },
  307.    
  308.    
  309.    ievtrim: function(st) 
  310.    {
  311.       result = st.replace( /^\s+/g, "" );
  312.       result = result.replace( /\s+$/g, "" );
  313.       return(result);
  314.    },
  315.    
  316.    
  317.    deQuote: function(st)
  318.    {
  319.       var result = this.ievtrim(st);
  320.  
  321.       if ((result.length >= 2) &&
  322.           (result.charAt(0) == '"') &&
  323.           (result.charAt(result.length - 1) == '"')
  324.          )
  325.       {
  326.          result = this.ievtrim(result.substr(1, result.length - 2));
  327.       }
  328.  
  329.       return(result);
  330.    },
  331.  
  332.    getBoolPref: function(prefName, defval)
  333.    {
  334.     var    result = defval;
  335.  
  336.         var prefservice = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  337.         var prefs = prefservice.getBranch("");
  338.  
  339.         if (prefs.getPrefType(prefName) == prefs.PREF_BOOL)
  340.         {
  341.        result = prefs.getBoolPref(prefName);
  342.     }
  343.  
  344.     return(result);
  345.    },
  346.  
  347.    getForceList: function()
  348.    {  
  349.         var prefservice = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  350.         
  351.         var prefs = prefservice.getBranch("");
  352.         var forces = new Array();
  353.         
  354.         if (prefs.getPrefType("ieview.forceielist") == prefs.PREF_STRING)
  355.         {
  356.             var forceList = this.deQuote(prefs.getCharPref("ieview.forceielist"));
  357.             forces = forceList.split(" ");
  358.         
  359.             var msg = "force list:\r\n";
  360.             
  361.             var i;
  362.             
  363.             for (i = 0; i < forces.length; ++i )
  364.             {
  365.                 msg += forces[i] + "\r\n";
  366.             }
  367.         }
  368.         
  369.         return(forces);
  370.    },
  371.  
  372.  
  373.    ieViewLaunch: function (path,argumentstext)
  374.    {
  375.       var cantMessage = "can't find";
  376.  
  377.       if (! this.isForceable(argumentstext))
  378.     {
  379.         return;
  380.     }
  381.  
  382.       try
  383.       {
  384.          cantMessage = gIeViewBundle.getString("ieview.cantFindExplorer");
  385.       }
  386.       catch(e)
  387.       {
  388.          alert(e);
  389.       }
  390.  
  391.       var prefservice = Components.classes["@mozilla.org/preferences-service;1"].
  392.                         getService(Components.interfaces.nsIPrefService);
  393.  
  394.       var prefs = prefservice.getBranch("");
  395.  
  396.       try
  397.       {
  398.          if (path=="") return false;
  399.  
  400.          var ieloc = null;
  401.  
  402.          if (prefs.getPrefType("ieview.ieapp") == prefs.PREF_STRING)
  403.          {
  404.             ieloc = this.deQuote(prefs.getCharPref("ieview.ieapp"));
  405.  
  406.             if (this.trim(ieloc) == "")
  407.             {
  408.                 ieloc = null;
  409.             }
  410.          }
  411.  
  412.          var   natTarget = null;
  413.          var   usePath = null;
  414.  
  415.          if (ieloc != null)
  416.          {
  417.             natTarget = ieloc;
  418.          }
  419.          else
  420.          {
  421.             var dsprops = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties);
  422.  
  423.             usePath = this.tryDir(dsprops, this.userPrograms);    // try user-specific program menu first
  424.  
  425.             var file = null;
  426.  
  427.             if (usePath != "")
  428.             {
  429.                file = this.searchPath(usePath, path);
  430.             }
  431.  
  432.             if (! file)
  433.             {
  434.                usePath = this.tryDir(dsprops, this.allUserPrograms);   // no joy?  try "all users" program menu
  435.  
  436.                if (usePath != "")
  437.                {
  438.                   file = this.searchPath(usePath, path);
  439.                }
  440.             }
  441.  
  442.             if (! file)
  443.             {
  444.                usePath = this.tryDir(dsprops, this.applicationData);   // last resort, check the "quick start" bar
  445.  
  446.                if (usePath != "")
  447.                {
  448.                   var   quickPath = "\\microsoft\\internet explorer\\quick launch";
  449.  
  450.                   usePath = usePath + quickPath;
  451.  
  452.                   file = this.searchPath(usePath, path);
  453.  
  454.                   if (! file)    // check alternate QuickLaunch bar title
  455.                   {
  456.                      var launchLink = "Launch Internet Explorer Browser.lnk";
  457.  
  458.                      file = this.searchPath(usePath, launchLink);
  459.                   }
  460.                }
  461.             }
  462.  
  463.             // last ditch -- find the windows directory
  464.             // assume that the main Program Files directory is on the same drive
  465.             // look in there, under Program Files\Internet Explorer, for iexplore.exe
  466.             //
  467.             if (! file)
  468.             {
  469.                usePath = this.tryDir(dsprops, "WinD");
  470.  
  471.                if ((usePath != "") && (usePath.charAt(1) == ":"))
  472.                {
  473.                   usePath = usePath.substr(0, 2) + "\\program files\\internet explorer";
  474.  
  475.                   file = this.searchPath(usePath, "iexplore.exe");
  476.                }
  477.             }
  478.  
  479.             if ((! file) || (! file.exists()))
  480.             {
  481.                alert(cantMessage);
  482.                return false;
  483.             }
  484.  
  485.             natTarget = file.target;
  486.             this.saveIeLoc(natTarget);
  487.          }
  488.  
  489.          var targetFile = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
  490.  
  491.          try
  492.          {
  493.             targetFile.initWithPath(natTarget);
  494.          }
  495.          catch(e)
  496.          {
  497.             alert(cantMessage);
  498.             return(false);
  499.          }
  500.  
  501.          if (! targetFile.exists())
  502.          {
  503.             alert(cantMessage);
  504.             return(false);
  505.          }
  506.  
  507.          usePath = targetFile.target;
  508.  
  509.          var process = Components.classes['@mozilla.org/process/util;1'].getService(Components.interfaces.nsIProcess);
  510.          process.init(targetFile);
  511.          var arguments= [] ;
  512.  
  513.          arguments.push(argumentstext);
  514.  
  515.          process.run(false, arguments, arguments.length,{});
  516.          return true;
  517.  
  518.       }
  519.       catch (e)
  520.       {
  521.          alert(e);
  522.          return false;
  523.       }
  524.  
  525.       return false;     // avoid JavaScript Error.
  526.    },
  527.  
  528.  
  529.    ieviewInit: function()
  530.    {
  531.       var   i;
  532.       var menu = document.getElementById("contentAreaContextMenu");
  533.  
  534.       if (menu)
  535.       {
  536.          menu.addEventListener("popupshowing", ieviewContextListener,false);
  537.       }
  538.  
  539.       gIeViewBundle = document.getElementById("bundle_ieview");
  540.  
  541.       var   docHref = this.getDocHref();
  542.  
  543.       if (docHref == "")
  544.       {
  545.          docHref = document.location.href;
  546.       }
  547.  
  548.       if (docHref.substring(0, 7) != 'chrome:')
  549.       {
  550.          if (! gIeViewBundle)
  551.          {
  552.             alert("no bundle");
  553.          }
  554.       }
  555.  
  556.       var appcontent = document.getElementById("appcontent");   // browser
  557.  
  558.       if (appcontent)
  559.       {
  560.          appcontent.addEventListener("load", ieviewLoadListener, true);
  561.       }
  562.    },
  563.  
  564.    isForceable: function(href) {
  565.     return( (typeof(href) != 'undefined') && (href.substr) &&
  566.                 ((href.substr(0, 4) == 'http') || (href.substr(0, 7) == 'file://'))
  567.           );
  568.    },
  569.  
  570.    hideMenu: function(aEvent)
  571.    {
  572.        var i;
  573.        var doc = aEvent.originalTarget;
  574.  
  575.        var menuitem = document.getElementById('ieview-do-forcepage-menu');
  576.  
  577.        if (! menuitem)
  578.     {
  579.        menuitem = doc.getElementById('ieview-do-forcepage-menu');
  580.     }
  581.  
  582.     if (! menuitem)
  583.     {    
  584.                menuitem = document.getElementById('ieview-do-forcepage-menu-moz');
  585.     }
  586.  
  587.        if (! menuitem)
  588.     {
  589.        menuitem = doc.getElementById('ieview-do-forcepage-menu-moz');
  590.     }
  591.  
  592.        if (menuitem)      // click-on-page item
  593.         {
  594.        var href = '';
  595.  
  596.        if (doc.location && doc.location.href)
  597.         {
  598.             href = doc.location.href;
  599.         }
  600.  
  601.        var enabled = this.enableForceIE() && this.isForceable(href);
  602.  
  603.                   menuitem.setAttribute('disabled', enabled ? 'false' : 'true');
  604.  
  605.         }
  606.    },
  607.  
  608.    grabLinks: function(aEvent)
  609.    {
  610.        var i;
  611.        var doc = aEvent.originalTarget;
  612.  
  613.        if ((! this.enableForceIE()) || ! doc.links || ! doc.links.length)
  614.     {
  615.       return;
  616.     }
  617.  
  618.        for (i = 0; i < doc.links.length; ++i)
  619.        {
  620.            var   ln = doc.links[i];
  621.  
  622.            if (! ln.onclick)
  623.            {
  624.                ln.onclick = this.ieviewClick;
  625.            }
  626.        }
  627.    },
  628.  
  629.    //    check whether the document behind a dom-loaded event is framed
  630.    //
  631.    isFramed: function(aEvent)
  632.    {
  633.     var framed = aEvent.originalTarget && 
  634.         window._content && window._content.document &&
  635.         (window._content.document != aEvent.originalTarget);
  636.  
  637.     return(framed);
  638.   },
  639.  
  640.  
  641.    checkForced: function(aEvent)
  642.    {
  643.        var i;
  644.        var doc = aEvent.originalTarget;
  645.  
  646.        if (! this.enableForceIE())
  647.     {
  648.       return;
  649.     }
  650.  
  651.     // only want to reload the topmost frame
  652.     //
  653.     if (this.isFramed(aEvent))
  654.     {
  655.       return;
  656.     }
  657.  
  658.        if (doc.location && doc.location.href && this.forceIe(doc.location.href))
  659.     {
  660.       var ws = gBrowser.docShell.QueryInterface(Components.interfaces.nsIRefreshURI);
  661.  
  662.       if (ws)
  663.       {
  664.           ws.cancelRefreshURITimers();
  665.       }
  666.  
  667.     doc.location.href = "chrome://ieview/content/reloaded.html";
  668.  
  669.       var head = null;
  670.  
  671.       var heads = doc.getElementsByTagName('head');
  672.  
  673.       if (heads && heads.length > 0)
  674.       {
  675.         head = heads[0];
  676.          }
  677.       else
  678.       {
  679.         heads = doc.getElementsByTagName('HEAD');
  680.  
  681.         if (heads && heads.length > 0)
  682.         {
  683.           head = heads[0];
  684.            }
  685.       }
  686.  
  687.       if (head)
  688.       {
  689.         head.innerHTML = "<title>IE View " + gIeViewBundle.getString("ieview.reloaded") + "</title>";
  690.       }
  691.  
  692.       this.ieViewLaunch("Internet Explorer.lnk", doc.location.href);
  693.     }
  694.    },
  695.  
  696.    startsWith: function(st, pref)
  697.    {
  698.       return( (pref.length > 0) && (st.substring(0, pref.length) == pref) );
  699.         
  700.    },
  701.  
  702.    isMatch: function(url, pattern)
  703.    {
  704.         if ((pattern == null) || (pattern == ""))
  705.         {
  706.        return(false);
  707.         }
  708.  
  709.         var     repat = pattern;
  710.  
  711.         repat = repat.replace(/\\/, "\\\\");
  712.         repat = repat.replace(/\./g, "\\.");
  713.         repat = repat.replace(/\//g, "\\/");
  714.         repat = repat.replace(/\*/g, ".*");
  715.         repat = repat.replace(/\.\*\\\./g, ".*\\.?\\b");
  716.         repat = "^" + repat;
  717.  
  718. //      document.write("\n " + pattern + " - " + repat + " <br />\n");
  719.  
  720.         var     reg = new RegExp(repat);
  721.  
  722.         var     matched = (reg.test(url));
  723.  
  724.         return(matched);
  725.    },
  726.  
  727.    forceIe: function(href)
  728.    {
  729.        var skipList = this.getForceList();
  730.  
  731.        for (i = 0; i < skipList.length; ++i)
  732.        {
  733.            if (this.isMatch(href, skipList[i]))
  734.            {
  735.                ieviewAlert(href + " matches " + skipList[i]);
  736.                return(true);
  737.            }
  738.        }
  739.  
  740.        return(false);
  741.    },
  742.  
  743.    ieviewClick: function(aEvent)
  744.    {
  745.        var link = aEvent.originalTarget;
  746.  
  747.        if ((! link) || (! link.href))
  748.        {
  749.            link = aEvent.currentTarget;
  750.        }
  751.  
  752.        if (IeView.forceIe(link.href))
  753.        {
  754.            IeView.ieViewLaunch("Internet Explorer.lnk", link.href);
  755.            return(false);
  756.        }
  757.  
  758.        return(true);
  759.    },
  760.  
  761.    setIeviewOptions: function()
  762.    {
  763.          var prefService = Components.classes["@mozilla.org/preferences-service;1"]
  764.                                .getService(Components.interfaces.nsIPrefService);
  765.  
  766.          var prefs = prefService.getBranch("");
  767.  
  768.          prefs.setCharPref("ieview.ieapp", document.getElementById('ieloc').value);
  769.  
  770.          prefs.setCharPref("ieview.forceielist", this.getPrefListString());
  771.  
  772.       window.close();
  773.    },
  774.  
  775.    pickIe: function()
  776.    {
  777.        var picker = Components.classes["@mozilla.org/filepicker;1"].getService(Components.interfaces.nsIFilePicker);
  778.  
  779.        picker.init(window, "Choose Browser", 0);
  780.        picker.appendFilters(64);
  781.  
  782.        if (picker.show() == 0)
  783.        {
  784.            document.getElementById('ieloc').value = picker.file.target;
  785.        }
  786.    },
  787.  
  788.  
  789.    initPath: function()
  790.    {
  791.        var prefservice = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
  792.  
  793.        var prefs = prefservice.getBranch("");
  794.  
  795.        var ieloc = null;
  796.  
  797.        if (prefs.getPrefType("ieview.ieapp") == prefs.PREF_STRING)
  798.        {
  799.          ieloc = prefs.getCharPref("ieview.ieapp");
  800.        }
  801.  
  802.        if ((ieloc != null) && (ieloc.length > 0))
  803.        {
  804.            document.getElementById('ieloc').value = ieloc;
  805.        }
  806.  
  807.        var skips = this.getForceList();
  808.  
  809.         var listbox = document.getElementById('patlist');
  810.  
  811.         if (! listbox)
  812.         {
  813.             alert('no listbox');
  814.         }
  815.         else
  816.         {
  817.             var i;
  818.             
  819.             for ( i = 0; i < skips.length; ++i )
  820.             {
  821.         if (skips[i] != '')
  822.         {
  823.                     listbox.appendItem(skips[i]); 
  824.         }    
  825.             }
  826.         }
  827.  
  828.        prefs = null;
  829.  
  830.        var np = document.getElementById('newpat');
  831.        
  832.        np.disabled = ! this.enableForceIE();
  833.        listbox.disabled = ! this.enableForceIE();
  834.    },
  835.  
  836.    updateDelButtonStatus: function()
  837.    {
  838.         var lb = document.getElementById('patlist');
  839.         var bt = document.getElementById('delpat');
  840.  
  841.         bt.disabled = (lb.selectedItems.length < 1) || ! this.enableForceIE();        
  842.    },
  843.  
  844.    compareNum: function(a,b)
  845.    {
  846.      return(b-a);
  847.    },
  848.  
  849.    deleteSelected: function()
  850.    {
  851.         var lb = document.getElementById('patlist');
  852.         var selected = lb.selectedItems;
  853.         var indexes = new Array();
  854.  
  855.         var i;
  856.  
  857.         for ( i  = 0; i < selected.length; ++i )
  858.         {
  859.             var item = selected[i];
  860.  
  861.             var idx = lb.getIndexOfItem(item);
  862.     
  863.             indexes[i] = idx;
  864.         }
  865.  
  866.         indexes.sort(this.compareNum);
  867.  
  868.         for ( i = 0; i < indexes.length; ++i )
  869.         {
  870.             lb.removeItemAt(indexes[i]);
  871.         }
  872.  
  873.         this.updateDelButtonStatus();
  874.    },
  875.  
  876.  
  877.    updateButtonStatus: function()
  878.    {
  879.         var tb = document.getElementById('newpat');
  880.         var bt = document.getElementById('addpat');
  881.  
  882.         bt.disabled = (this.trim(tb.value).length < 1);        
  883.    },
  884.  
  885.    addNewPat: function()
  886.    {
  887.         var tb = document.getElementById('newpat');
  888.  
  889.         var newstr = tb.value;
  890.  
  891.         if (newstr.indexOf("://") < 0)
  892.         {
  893.             newstr = "http://" + newstr;
  894.         }
  895.  
  896.         var        listbox = document.getElementById('patlist');
  897.  
  898.         listbox.appendItem(this.trim(newstr));
  899.  
  900.         tb.value = "";
  901.         this.updateButtonStatus();
  902.    },
  903.  
  904.    getPrefListString: function()
  905.    {
  906.         var result = "";
  907.  
  908.         var        listbox = document.getElementById('patlist');
  909.         var rows = listbox.getRowCount();
  910.         var i;
  911.  
  912.         for ( i = 0; i < rows; ++i )
  913.         {
  914.           var li = listbox.getItemAtIndex(i);
  915.         
  916.           if (result != "")
  917.           {
  918.                 result += " ";
  919.           }
  920.  
  921.           result += li.label;
  922.         }
  923.  
  924.         return(result);
  925.    },
  926.  
  927.    trim: function(st)
  928.    {
  929.         var result = st;
  930.  
  931.         while ((result.length > 0) && (result.substring(0,1) == " "))
  932.         {
  933.                 result = result.substring(1);
  934.          }
  935.  
  936.         while ((result.length > 0) && (result.substring(st.length - 1, 1) == " "))
  937.         {
  938.                 result = result.substring(0, result.length - 1);
  939.         }
  940.  
  941.         return(result);
  942.    },
  943.  
  944.    getDocHref: function()
  945.    {
  946.       if (typeof(XPCNativeWrapper) == "undefined")
  947.       {
  948.          return("");
  949.       }
  950.  
  951.       var winWrapper = new XPCNativeWrapper(window._content, 'document');
  952.       var docWrapper = new XPCNativeWrapper(winWrapper.document, 'location');
  953.       var locWrapper = new XPCNativeWrapper(docWrapper.location, 'href');
  954.  
  955.       return(locWrapper.href);
  956.    },
  957. };
  958.  
  959.  
  960. function ieviewLaunchOptions()
  961. {
  962.             window.openDialog("chrome://ieview/content/ieviewsettings.xul", "ieviewsettings", 
  963.               "resizable,centerscreen,modal");
  964. }
  965.  
  966. function ieviewContextListener(aEvent)
  967. {
  968.   return(IeView.ieviewContext(aEvent));
  969. }
  970.  
  971. function ieviewLoadListener(aEvent)
  972. {
  973.    IeView.hideMenu(aEvent);
  974.  
  975.    return(IeView.grabLinks(aEvent));
  976. }
  977.  
  978. function ieviewCheckForcedListener(aEvent)
  979. {
  980.    IeView.checkForced(aEvent);
  981. }
  982.  
  983. function ieviewInitListener(aEvent)
  984. {
  985.    return(IeView.ieviewInit(aEvent));
  986. }
  987.  
  988. // do the init on load
  989. window.addEventListener("load", ieviewInitListener, false);
  990. window.addEventListener("DOMContentLoaded", ieviewCheckForcedListener, false);
  991.  
  992. if (typeof(BookmarksCommand) != "undefined")
  993. {
  994.    if (BookmarksCommand.openOneBookmark && ! gOldOpenOneBookmark && IeView.enableForceIE())
  995.    {
  996.        gOldOpenOneBookmark = BookmarksCommand.openOneBookmark;
  997.    
  998.        BookmarksCommand.openOneBookmark = function(aURI, aTargetBrowser, aDS) {
  999.  
  1000.            var namespaceVar = null;
  1001.  
  1002.            if (typeof(gNC_NS) != "undefined")
  1003.            {
  1004.               namespaceVar = gNC_NS;
  1005.            }
  1006.            else if (typeof(NC_NS) != "undefined")
  1007.            {
  1008.               namespaceVar = NC_NS;
  1009.            }
  1010.            else
  1011.            {
  1012.               alert('no namespace var');
  1013.            }
  1014.    
  1015.            var url = BookmarksUtils.getProperty(aURI, namespaceVar+"URL", aDS);
  1016.    
  1017.            if (IeView.forceIe(url))
  1018.            {
  1019.                IeView.ieViewLaunch("Internet Explorer.lnk", url);
  1020.                return;
  1021.            }
  1022.            else
  1023.            {
  1024.                gOldOpenOneBookmark(aURI, aTargetBrowser, aDS);
  1025.            }
  1026.        };
  1027.    }
  1028. }
  1029.  
  1030.