2006-07-27 18:57:38 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Robert John Churchill.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Robert John Churchill <rjc@netscape.com> (Original Author)
|
|
|
|
* Ben Goodger <ben@netscape.com>
|
|
|
|
* Daniel Matejka <danm@netscape.com>
|
|
|
|
* Eric Pollmann <pollmann@netscape.com>
|
|
|
|
* Ray Whitmer <rayw@netscape.com>
|
|
|
|
* Peter Annema <disttsc@bart.nl>
|
|
|
|
* Blake Ross <blakeross@telocity.com>
|
|
|
|
* Joe Hewitt <hewitt@netscape.com>
|
|
|
|
* Jan Varga <varga@utcruk.sk>
|
|
|
|
* Karsten Duesterloh <kd-moz@tprac.de>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2006-07-27 18:52:49 +04:00
|
|
|
function searchResultsOpenURL(event)
|
2006-07-27 18:49:06 +04:00
|
|
|
{
|
2006-07-27 18:55:43 +04:00
|
|
|
var tree = document.getElementById("resultsList");
|
|
|
|
var node = tree.contentView.getItemAtIndex(tree.currentIndex);
|
|
|
|
|
2006-07-27 18:53:34 +04:00
|
|
|
var url = node.id;
|
|
|
|
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
|
|
|
|
if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
|
|
|
|
if (rdf)
|
|
|
|
{
|
|
|
|
var ds = rdf.GetDataSource("rdf:internetsearch");
|
|
|
|
if (ds)
|
|
|
|
{
|
|
|
|
var src = rdf.GetResource(url, true);
|
|
|
|
var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
|
|
|
|
var target = ds.GetTarget(src, prop, true);
|
|
|
|
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
|
|
|
if (target) target = target.Value;
|
|
|
|
if (target) url = target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore "NC:" urls.
|
|
|
|
if (url.substring(0, 3) == "NC:")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ("loadURI" in top)
|
|
|
|
top.loadURI(url);
|
|
|
|
else
|
2006-07-27 18:58:33 +04:00
|
|
|
top.content.location.href = url;
|
2006-07-27 18:53:34 +04:00
|
|
|
|
|
|
|
return true;
|
2006-07-27 18:49:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-27 18:55:54 +04:00
|
|
|
// Workaround for bug 196057 (double onload event): accept only the first onload event
|
|
|
|
// ( This workaround will fix bug 147068 (duplicate search results).
|
|
|
|
// Without this fix, xpfe\components\search\src\nsInternetSearchService.cpp will
|
|
|
|
// crash when removing the same tree node twice. )
|
|
|
|
// If bug 196057 should be fixed eventually, this workaround does no harm -
|
|
|
|
// nevertheless it should be removed then
|
|
|
|
var gbProcessOnloadEvent = true;
|
2006-07-27 18:49:06 +04:00
|
|
|
|
1999-09-15 15:08:58 +04:00
|
|
|
function onLoadInternetResults()
|
|
|
|
{
|
2006-07-27 18:55:54 +04:00
|
|
|
if (gbProcessOnloadEvent)
|
|
|
|
{ // forbid other onload events
|
|
|
|
gbProcessOnloadEvent = false;
|
2006-07-27 18:52:49 +04:00
|
|
|
|
2006-07-27 18:55:54 +04:00
|
|
|
// clear any previous results on load
|
|
|
|
var iSearch = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
|
|
|
|
.getService(Components.interfaces.nsIInternetSearchService);
|
|
|
|
iSearch.ClearResultSearchSites();
|
|
|
|
|
2006-07-27 18:58:38 +04:00
|
|
|
// the search URI is passed in as a parameter, so get it and then root the results list
|
2006-07-27 18:58:33 +04:00
|
|
|
var searchURI = top.content.location.href;
|
2006-07-27 18:55:54 +04:00
|
|
|
if (searchURI) {
|
|
|
|
const lastSearchURIPref = "browser.search.lastMultipleSearchURI";
|
|
|
|
var offset = searchURI.indexOf("?");
|
2006-07-27 18:52:49 +04:00
|
|
|
if (offset > 0) {
|
|
|
|
nsPreferences.setUnicharPref(lastSearchURIPref, searchURI); // evil
|
|
|
|
searchURI = searchURI.substr(offset+1);
|
2006-07-27 18:55:43 +04:00
|
|
|
loadResultsList(searchURI);
|
2006-07-27 18:52:49 +04:00
|
|
|
}
|
2006-07-27 18:55:54 +04:00
|
|
|
else {
|
|
|
|
searchURI = nsPreferences.copyUnicharPref(lastSearchURIPref, "");
|
|
|
|
offset = searchURI.indexOf("?");
|
|
|
|
if (offset > 0) {
|
|
|
|
nsPreferences.setUnicharPref(lastSearchURIPref, searchURI); // evil
|
|
|
|
searchURI = searchURI.substr(offset+1);
|
|
|
|
loadResultsList(searchURI);
|
|
|
|
}
|
|
|
|
}
|
2006-07-27 18:52:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
1999-09-15 15:08:58 +04:00
|
|
|
}
|
|
|
|
|
2006-07-27 18:55:43 +04:00
|
|
|
function loadResultsList( aSearchURL )
|
1999-08-23 11:06:19 +04:00
|
|
|
{
|
2006-07-27 18:55:43 +04:00
|
|
|
var resultsTree = document.getElementById( "resultsList" );
|
2006-07-27 18:52:49 +04:00
|
|
|
if (!resultsTree) return false;
|
2006-07-27 18:57:42 +04:00
|
|
|
resultsTree.setAttribute("ref", decodeURI(aSearchURL));
|
2006-07-27 18:48:34 +04:00
|
|
|
return true;
|
|
|
|
}
|
1999-08-23 11:06:19 +04:00
|
|
|
|
2006-07-27 18:49:06 +04:00
|
|
|
|
|
|
|
|
2006-07-27 18:49:10 +04:00
|
|
|
function doEngineClick( event, aNode )
|
2006-07-27 18:48:34 +04:00
|
|
|
{
|
2006-07-27 18:54:46 +04:00
|
|
|
event.target.checked = true;
|
2006-07-27 18:49:10 +04:00
|
|
|
|
2006-07-27 18:53:34 +04:00
|
|
|
var html = null;
|
|
|
|
|
2006-07-27 18:55:43 +04:00
|
|
|
var resultsTree = document.getElementById("resultsList");
|
2006-07-27 18:58:38 +04:00
|
|
|
var contentArea = document.getElementById("resultsContent");
|
2006-07-27 18:53:34 +04:00
|
|
|
var splitter = document.getElementById("results-splitter");
|
|
|
|
var engineURI = aNode.id;
|
|
|
|
if (engineURI == "allEngines") {
|
|
|
|
resultsTree.removeAttribute("hidden");
|
|
|
|
splitter.removeAttribute("hidden");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
resultsTree.setAttribute("hidden", "true");
|
|
|
|
splitter.setAttribute("hidden", "true");
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
|
|
|
|
if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
|
|
|
|
if (rdf)
|
|
|
|
{
|
|
|
|
var internetSearchStore = rdf.GetDataSource("rdf:internetsearch");
|
|
|
|
if (internetSearchStore)
|
|
|
|
{
|
|
|
|
var src = rdf.GetResource(engineURI, true);
|
|
|
|
var htmlProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#HTML", true);
|
|
|
|
html = internetSearchStore.GetTarget(src, htmlProperty, true);
|
|
|
|
if ( html ) html = html.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
|
|
|
if ( html ) html = html.Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( html )
|
|
|
|
{
|
|
|
|
var doc = frames[0].document;
|
|
|
|
if (doc)
|
|
|
|
{
|
|
|
|
doc.open("text/html", "replace");
|
|
|
|
doc.writeln( html );
|
|
|
|
doc.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2006-07-27 18:58:40 +04:00
|
|
|
frames[0].document.location.href =
|
|
|
|
"chrome://communicator/locale/search/default.htm";
|
1999-08-23 11:06:19 +04:00
|
|
|
}
|
|
|
|
|
1999-12-04 05:00:24 +03:00
|
|
|
|
|
|
|
|
1999-08-23 11:06:19 +04:00
|
|
|
function doResultClick(node)
|
1999-08-21 12:16:17 +04:00
|
|
|
{
|
2006-07-27 18:53:34 +04:00
|
|
|
var theID = node.id;
|
|
|
|
if (!theID) return(false);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
|
|
|
|
if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
|
|
|
|
if (rdf)
|
|
|
|
{
|
|
|
|
var internetSearchStore = rdf.GetDataSource("rdf:internetsearch");
|
|
|
|
if (internetSearchStore)
|
|
|
|
{
|
|
|
|
var src = rdf.GetResource(theID, true);
|
|
|
|
var urlProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
|
|
|
|
var bannerProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#Banner", true);
|
|
|
|
var htmlProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#HTML", true);
|
|
|
|
|
|
|
|
var url = internetSearchStore.GetTarget(src, urlProperty, true);
|
|
|
|
if (url) url = url.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
|
|
|
if (url) url = url.Value;
|
|
|
|
if (url)
|
|
|
|
{
|
|
|
|
var statusNode = document.getElementById("status-button");
|
|
|
|
if (statusNode)
|
|
|
|
{
|
|
|
|
statusNode.label = url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var banner = internetSearchStore.GetTarget(src, bannerProperty, true);
|
|
|
|
if (banner) banner = banner.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
|
|
|
if (banner) banner = banner.Value;
|
|
|
|
|
|
|
|
var target = internetSearchStore.GetTarget(src, htmlProperty, true);
|
|
|
|
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
|
|
|
if (target) target = target.Value;
|
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
var text = "<HTML><HEAD><TITLE>Search</TITLE><BASE TARGET='_top'></HEAD><BODY><FONT POINT-SIZE='9'>";
|
|
|
|
|
|
|
|
if (banner)
|
|
|
|
text += banner + "</A><BR>"; // add a </A> and a <BR> just in case
|
|
|
|
text += target;
|
|
|
|
text += "</FONT></BODY></HTML>"
|
|
|
|
|
|
|
|
var doc = frames[0].document;
|
|
|
|
doc.open("text/html", "replace");
|
|
|
|
doc.writeln(text);
|
|
|
|
doc.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
return(true);
|
1999-08-21 05:09:30 +04:00
|
|
|
}
|
2006-07-27 18:51:31 +04:00
|
|
|
|
2006-07-27 18:55:43 +04:00
|
|
|
function listSelect(event)
|
2006-07-27 18:52:49 +04:00
|
|
|
{
|
2006-07-27 18:55:43 +04:00
|
|
|
var tree = document.getElementById("resultsList");
|
|
|
|
if (tree.view.selection.count != 1)
|
2006-07-27 18:52:49 +04:00
|
|
|
return false;
|
2006-07-27 18:55:43 +04:00
|
|
|
var selection = tree.contentView.getItemAtIndex(tree.currentIndex);
|
2006-07-27 18:57:38 +04:00
|
|
|
return doResultClick(selection);
|
2006-07-27 18:52:49 +04:00
|
|
|
}
|
|
|
|
|
2006-07-27 18:55:43 +04:00
|
|
|
function listClick(event)
|
2006-07-27 18:57:38 +04:00
|
|
|
{ // left double click opens URL
|
2006-07-27 18:53:34 +04:00
|
|
|
if (event.detail == 2 && event.button == 0)
|
2006-07-27 18:52:49 +04:00
|
|
|
searchResultsOpenURL(event);
|
2006-07-27 18:57:38 +04:00
|
|
|
return true; // always allow further click processing
|
2006-07-27 18:52:52 +04:00
|
|
|
}
|