home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 October / Gamestar_77_2005-10_dvd.iso / Programy / nsb-install-8-0.exe / chrome / browser.jar / content / browser / search / internetresults.js < prev    next >
Encoding:
JavaScript  |  2005-07-29  |  8.8 KB  |  266 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is mozilla.org code.
  15.  *
  16.  * The Initial Developer of the Original Code is Robert John Churchill.
  17.  * Portions created by the Initial Developer are Copyright (C) 1999
  18.  * the Initial Developer. All Rights Reserved.
  19.  *
  20.  * Contributor(s): 
  21.  *    Robert John Churchill   <rjc@netscape.com> (Original Author)
  22.  *    Ben Goodger             <ben@netscape.com>
  23.  *    Daniel Matejka          <danm@netscape.com>
  24.  *    Eric Pollmann           <pollmann@netscape.com>
  25.  *    Ray Whitmer             <rayw@netscape.com>
  26.  *    Peter Annema            <disttsc@bart.nl>
  27.  *    Blake Ross              <blakeross@telocity.com>
  28.  *    Joe Hewitt              <hewitt@netscape.com>
  29.  *    Jan Varga               <varga@utcruk.sk>
  30.  *    Karsten Duesterloh      <kd-moz@tprac.de>
  31.  *
  32.  * Alternatively, the contents of this file may be used under the terms of
  33.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  34.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  35.  * in which case the provisions of the GPL or the LGPL are applicable instead
  36.  * of those above. If you wish to allow use of your version of this file only
  37.  * under the terms of either the GPL or the LGPL, and not to allow others to
  38.  * use your version of this file under the terms of the MPL, indicate your
  39.  * decision by deleting the provisions above and replace them with the notice
  40.  * and other provisions required by the GPL or the LGPL. If you do not delete
  41.  * the provisions above, a recipient may use your version of this file under
  42.  * the terms of any one of the MPL, the GPL or the LGPL.
  43.  *
  44.  * ***** END LICENSE BLOCK ***** */
  45.  
  46. function searchResultsOpenURL(event)
  47. {
  48.   var tree = document.getElementById("resultsList");
  49.   var node = tree.contentView.getItemAtIndex(tree.currentIndex);
  50.   
  51.   var url = node.id;
  52.   var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
  53.   if (rdf)   rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
  54.   if (rdf)
  55.   {
  56.     var ds = rdf.GetDataSource("rdf:internetsearch");
  57.     if (ds)
  58.     {
  59.       var src = rdf.GetResource(url, true);
  60.       var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
  61.       var target = ds.GetTarget(src, prop, true);
  62.       if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
  63.       if (target) target = target.Value;
  64.       if (target) url = target;
  65.     }
  66.   }
  67.  
  68.   // Ignore "NC:" urls.
  69.   if (url.substring(0, 3) == "NC:")
  70.     return false;
  71.  
  72.   if ("loadURI" in top)
  73.     top.loadURI(url);
  74.   else
  75.     top._content.location.href = url;
  76.  
  77.   return true;
  78. }
  79.  
  80.  
  81. // Workaround for bug 196057 (double onload event): accept only the first onload event
  82. // ( This workaround will fix bug 147068 (duplicate search results).
  83. //   Without this fix, xpfe\components\search\src\nsInternetSearchService.cpp will
  84. //   crash when removing the same tree node twice. )
  85. // If bug 196057 should be fixed eventually, this workaround does no harm -
  86. // nevertheless it should be removed then
  87. var gbProcessOnloadEvent = true;
  88.  
  89. function onLoadInternetResults()
  90. {
  91.   if (gbProcessOnloadEvent)
  92.   { // forbid other onload events
  93.     gbProcessOnloadEvent = false;
  94.  
  95.     // clear any previous results on load
  96.     var iSearch = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
  97.                             .getService(Components.interfaces.nsIInternetSearchService);
  98.     iSearch.ClearResultSearchSites();
  99.  
  100.     // the search URI is passed in as a parameter, so get it and them root the results list
  101.     var searchURI = top._content.location.href;
  102.     if (searchURI) {
  103.       const lastSearchURIPref = "browser.search.lastMultipleSearchURI";
  104.       var offset = searchURI.indexOf("?");
  105.       if (offset > 0) {
  106.         nsPreferences.setUnicharPref(lastSearchURIPref, searchURI); // evil
  107.         searchURI = searchURI.substr(offset+1);
  108.         loadResultsList(searchURI);
  109.       }
  110.       else {
  111.         searchURI = nsPreferences.copyUnicharPref(lastSearchURIPref, "");
  112.         offset = searchURI.indexOf("?");
  113.         if (offset > 0) {
  114.           nsPreferences.setUnicharPref(lastSearchURIPref, searchURI); // evil
  115.           searchURI = searchURI.substr(offset+1);
  116.           loadResultsList(searchURI);
  117.         }
  118.       }
  119.     }
  120.   }
  121.   return true;
  122. }
  123.  
  124. function loadResultsList( aSearchURL )
  125. {
  126.   var resultsTree = document.getElementById( "resultsList" );
  127.   if (!resultsTree) return false;
  128.   resultsTree.setAttribute("ref", decodeURI(aSearchURL));
  129.   return true;
  130. }
  131.  
  132.  
  133.  
  134. function doEngineClick( event, aNode )
  135. {
  136.   event.target.checked = true;
  137.  
  138.   var html = null;
  139.  
  140.   var resultsTree = document.getElementById("resultsList");
  141.   var contentArea = document.getElementById("content");
  142.   var splitter = document.getElementById("results-splitter");
  143.   var engineURI = aNode.id;
  144.   if (engineURI == "allEngines") {
  145.     resultsTree.removeAttribute("hidden");
  146.     splitter.removeAttribute("hidden");
  147.   }
  148.   else
  149.   {
  150.     resultsTree.setAttribute("hidden", "true");
  151.     splitter.setAttribute("hidden", "true");
  152.     try
  153.     {
  154.       var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
  155.       if (rdf)   rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
  156.       if (rdf)
  157.       {
  158.         var internetSearchStore = rdf.GetDataSource("rdf:internetsearch");
  159.         if (internetSearchStore)
  160.         {
  161.           var src = rdf.GetResource(engineURI, true);
  162.           var htmlProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#HTML", true);
  163.           html = internetSearchStore.GetTarget(src, htmlProperty, true);
  164.           if ( html ) html = html.QueryInterface(Components.interfaces.nsIRDFLiteral);
  165.           if ( html ) html = html.Value;
  166.         }
  167.       }
  168.     }
  169.     catch(ex)
  170.     {
  171.     }
  172.   }
  173.  
  174.   if ( html )
  175.   {
  176.     var doc = frames[0].document;
  177.     if (doc)
  178.     {
  179.         doc.open("text/html", "replace");
  180.         doc.writeln( html );
  181.         doc.close();
  182.     }
  183.   }
  184.   else
  185.     frames[0].document.location = "chrome://browser/locale/search/default.htm";
  186. }
  187.  
  188.  
  189.  
  190. function doResultClick(node)
  191. {
  192.   var theID = node.id;
  193.   if (!theID) return(false);
  194.  
  195.   try
  196.   {
  197.     var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
  198.     if (rdf)   rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
  199.     if (rdf)
  200.     {
  201.       var internetSearchStore = rdf.GetDataSource("rdf:internetsearch");
  202.       if (internetSearchStore)
  203.       {
  204.         var src = rdf.GetResource(theID, true);
  205.         var urlProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
  206.         var bannerProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#Banner", true);
  207.         var htmlProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#HTML", true);
  208.  
  209.         var url = internetSearchStore.GetTarget(src, urlProperty, true);
  210.         if (url)  url = url.QueryInterface(Components.interfaces.nsIRDFLiteral);
  211.         if (url)  url = url.Value;
  212.         if (url)
  213.         {
  214.           var statusNode = document.getElementById("status-button");
  215.           if (statusNode)
  216.           {
  217.             statusNode.label = url;
  218.           }
  219.         }
  220.  
  221.         var banner = internetSearchStore.GetTarget(src, bannerProperty, true);
  222.         if (banner) banner = banner.QueryInterface(Components.interfaces.nsIRDFLiteral);
  223.         if (banner) banner = banner.Value;
  224.  
  225.         var target = internetSearchStore.GetTarget(src, htmlProperty, true);
  226.         if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
  227.         if (target) target = target.Value;
  228.         if (target)
  229.         {
  230.           var text = "<HTML><HEAD><TITLE>Search</TITLE><BASE TARGET='_top'></HEAD><BODY><FONT POINT-SIZE='9'>";
  231.  
  232.           if (banner)
  233.             text += banner + "</A><BR>"; // add a </A> and a <BR> just in case
  234.           text += target;
  235.           text += "</FONT></BODY></HTML>"
  236.  
  237.           var doc = frames[0].document;
  238.           doc.open("text/html", "replace");
  239.           doc.writeln(text);
  240.           doc.close();
  241.         }
  242.       }
  243.     }
  244.   }
  245.   catch(ex)
  246.   {
  247.   }
  248.   return(true);
  249. }
  250.  
  251. function listSelect(event)
  252. {
  253.   var tree = document.getElementById("resultsList");
  254.   if (tree.view.selection.count != 1)
  255.     return false;
  256.   var selection = tree.contentView.getItemAtIndex(tree.currentIndex);
  257.   return doResultClick(selection);
  258. }
  259.  
  260. function listClick(event)
  261. { // left double click opens URL
  262.   if (event.detail == 2 && event.button == 0)
  263.     searchResultsOpenURL(event);
  264.   return true; // always allow further click processing
  265. }
  266.