Skinnability: use <xul:menulist> instead of <html:select>. Convert pluses to spaces before calling unescape().

This commit is contained in:
rjc%netscape.com 2006-07-27 14:49:25 +00:00
parent 0c884c45f3
commit 391d1e08f1
2 changed files with 240 additions and 125 deletions

View File

@ -25,15 +25,28 @@ var textArc = null;
var RDF_observer = new Object;
var pref = null;
function debug(msg)
{
// uncomment for debugging information
// dump(msg+"\n");
}
// get the click count pref
try {
try
{
pref = Components.classes["component://netscape/preferences"].getService();
if( pref )
pref = pref.QueryInterface( Components.interfaces.nsIPref );
if( pref ) pref = pref.QueryInterface( Components.interfaces.nsIPref );
}
catch(e) {
catch(e)
{
}
RDF_observer =
{
OnAssert : function(src, prop, target)
@ -58,18 +71,26 @@ RDF_observer =
}
}
function rememberSearchText(targetNode)
function rememberSearchText(target)
{
if (targetNode) targetNode = targetNode.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (targetNode) targetNode = targetNode.Value;
if (targetNode && (targetNode != ""))
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (target) target = target.Value;
if (target && (target != ""))
{
var textNode = document.getElementById("sidebar-search-text");
if (!textNode) return(false);
textNode.value = unescape(targetNode);
// convert pluses (+) back to spaces
target = target.replace(/+/i, " ");
textNode.value = unescape(target);
}
}
// Initialize the Search panel:
// 1) init the category list
// 2) load the search engines associated with this category
@ -108,33 +129,65 @@ function SearchPanelStartup()
}
}
try {
var pref = Components.classes["component://netscape/preferences"].getService();
if( pref )
pref = pref.QueryInterface( Components.interfaces.nsIPref );
var lastCategoryName = pref.CopyCharPref( "browser.search.last_search_category" );
}
catch( e ) {
// try and determine last category name used
var lastCategoryName = "";
try
{
var pref = Components.classes["component://netscape/preferences"].getService();
if (pref) pref = pref.QueryInterface( Components.interfaces.nsIPref );
if (pref) lastCategoryName = pref.CopyCharPref( "browser.search.last_search_category" );
if (lastCategoryName != "")
{
// strip off the prefix if necessary
var prefix="NC:SearchCategory?category=";
if (lastCategoryName.indexOf(prefix) == 0)
{
lastCategoryName = lastCategoryName.substr(prefix.length);
}
// dump("*** lastCategoryName = " + lastCategoryName + "\n");
}
}
catch( e )
{
debug("Exception in SearchPanelStartup\n");
lastCategoryName = "";
}
debug("\nSearchPanelStartup: lastCategoryName = '" + lastCategoryName + "'\n");
// select the appropriate category
var categoryList = document.getElementById( "categoryList" );
if( categoryList ) {
//set to default value 'the web'
var categoryPopup = document.getElementById( "categoryPopup" );
if( categoryList && categoryPopup )
{
//set to default value 'Web'
//hack: hardcoded postion in here replace with a function that finds the entry 'the web'
for( var i = 0; i < categoryList.options.length; i++ )
var found = false;
for( var i = 0; i < categoryPopup.childNodes.length; i++ )
{
if( ( lastCategoryName == "" && categoryList.options[i].value == "NC:SearchEngineRoot" ) ||
( categoryList.options[i].getAttribute("id") == lastCategoryName ) ) {
categoryList.selectedIndex = i;
if( ( lastCategoryName == "" && categoryPopup.childNodes[i].getAttribute("data") == "NC:SearchEngineRoot" ) ||
( categoryPopup.childNodes[i].getAttribute("id") == lastCategoryName ) )
{
categoryList.selectedItem = categoryPopup.childNodes[i];
found = true;
break;
}
}
if (found == false)
{
categoryList.selectedItem = categoryPopup.childNodes[0];
}
if( lastCategoryName == "" )
{
lastCategoryName = "NC:SearchEngineRoot";
}
else
{
lastCategoryName = "NC:SearchCategory?category=" + lastCategoryName;
}
var treeNode = document.getElementById("searchengines");
treeNode.setAttribute( "ref", lastCategoryName );
}
@ -143,10 +196,17 @@ function SearchPanelStartup()
// if we have search results, show them, otherwise show engines
if (haveSearchResults() == true)
{
switchTab(0);
else switchTab(1);
}
else
{
switchTab(1);
}
}
function haveSearchResults()
{
var resultsTree = document.getElementById("Tree");
@ -167,6 +227,10 @@ function haveSearchResults()
{
var textNode = document.getElementById("sidebar-search-text");
if (!textNode) return(false);
// convert pluses (+) back to spaces
target = target.replace(/+/i, " ");
textNode.value = unescape(target);
return(true);
}
@ -174,58 +238,84 @@ function haveSearchResults()
return(false);
}
function getNumEngines()
{
var treeNode = document.getElementById("searchengines");
var numChildren = treeNode.childNodes.length;
var treeChildrenNode = null;
for (var x = 0; x<numChildren; x++)
{
if (treeNode.childNodes[x].tagName == "treechildren")
{
var treeChildrenNode = treeNode.childNodes[x];
treeChildrenNode = treeNode.childNodes[x];
break;
}
}
if( !treeChildrenNode )
return -1;
return treeChildrenNode.childNodes.length;
if( !treeChildrenNode ) return(-1);
return(treeChildrenNode.childNodes.length);
}
function chooseCategory( aSelectElement )
function chooseCategory( aNode )
{
var category = aSelectElement.options[ aSelectElement.selectedIndex ].getAttribute("id");
var pref = Components.classes["component://netscape/preferences"].getService();
if( pref )
pref = pref.QueryInterface( Components.interfaces.nsIPref );
if( !category )
category = "";
pref.SetCharPref( "browser.search.last_search_category", category );
if ( category )
category = "NC:SearchCategory?category=" + category;
var category = aNode.getAttribute("id");
if ((!category) || (category == ""))
{
category="NC:SearchEngineRoot";
}
else
category = "NC:SearchEngineRoot";
{
category = "NC:SearchCategory?category=" + category;
}
debug("chooseCategory: '" + category + "'\n");
if (pref) pref.SetCharPref( "browser.search.last_search_category", category );
else debug("Unable to set browser.search.last_search_category pref.\n");
var treeNode = document.getElementById("searchengines");
if (!treeNode)
return false;
if (treeNode)
{
treeNode.setAttribute( "ref", category );
}
loadEngines( category );
return true;
return(true);
}
function saveEngines( aSelectElement )
// check an engine representation in the engine list
function doCheck(aNode)
{
var category = aSelectElement.options[ aSelectElement.selectedIndex ].getAttribute("id");
saveEngines();
return(false);
}
function saveEngines()
{
var categoryList = document.getElementById("categoryList");
var category = categoryList.selectedItem.getAttribute("id");
if( category )
{
category = "NC:SearchCategory?category=" + category;
}
else
{
category = "NC:SearchEngineRoot";
}
var rdf = Components.classes["component://netscape/rdf/rdf-service"].getService();
if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
if (rdf)
{
var localStore = rdf.GetDataSource("rdf:local-store");
if( !localStore )
return false;
if( !localStore ) return(false);
var treeNode = document.getElementById("searchengines");
var numChildren = treeNode.childNodes.length;
for (var x = 0; x<numChildren; x++)
@ -249,17 +339,29 @@ function saveEngines( aSelectElement )
var engineSRC = rdf.GetResource(engineURI, true);
var checkbox = treeItem.firstChild.firstChild.firstChild;
if( checkbox.checked )
debug("#" + x + ": tag=" + checkbox.tagName + " checked=" + checkbox.checked + "\n");
if( checkbox.checked == true || checkbox.checked == "true")
localStore.Assert( categorySRC, checkedProperty, engineSRC, true );
else
localStore.Unassert( categorySRC, checkedProperty, engineSRC, true );
}
flushableStore = localStore.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
if (flushableStore)
flushableStore.Flush();
// save changes; flush out the localstore
try
{
var flushableStore = localStore.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
if (flushableStore) flushableStore.Flush();
}
catch(ex)
{
}
}
}
// initialise the appropriate engine list, and the checked state of the engines
function loadEngines( aCategory )
{
@ -293,8 +395,7 @@ function loadEngines( aCategory )
var engineSRC = rdf.GetResource( engineURI, true );
var hasAssertion = localStore.HasAssertion( categorySRC, checkedProperty, engineSRC, true );
var checkbox = treeItem.firstChild.firstChild.firstChild;
// dump("*** hasAssertion = " + hasAssertion + "\n");
if ( hasAssertion )
if ( hasAssertion == true)
{
checkbox.checked = true;
}
@ -305,6 +406,7 @@ function loadEngines( aCategory )
}
function SearchPanelShutdown()
{
var tree = document.getElementById("Tree");
@ -314,6 +416,8 @@ function SearchPanelShutdown()
}
}
function doStop()
{
// should stop button press also stop the load of the page in the browser? I think so.
@ -350,10 +454,10 @@ function doStop()
{
var resultsTree = top.content.document.getElementById("internetresultstree");
if( !resultsTree )
return false;
return(false);
var searchURL = resultsTree.getAttribute("ref");
if( !searchURL )
return false;
return(false);
var searchResource = rdf.GetResource(searchURL, true);
var priceProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#Price", true);
@ -416,6 +520,8 @@ function doStop()
switchTab(0);
}
function doSearch()
{
//get click count pref for later
@ -493,8 +599,7 @@ function doSearch()
continue;
var checkbox = treeItem.firstChild.firstChild.firstChild;
var checkedFlag = checkbox.checked;
if ( checkedFlag )
if ( checkbox.checked == true || checkbox.checked == "true")
{
var engineURI = treeItem.getAttribute("id");
if (!engineURI) continue;
@ -510,11 +615,11 @@ function doSearch()
engineURIs[engineURIs.length] = treeItem.getAttribute( "id" );
}
else {
// dump("*** multiple search engines present, selecting the netscape search engine\n");
debug("*** multiple search engines present, selecting the netscape search engine\n");
for( var i = 0; i < treeChildrenNode.childNodes.length; i++ )
{
var currItem = treeChildrenNode.childNodes[i];
// dump("*** the current URI is = " + currItem.getAttribute("id") + "\n");
debug("*** the current URI is = " + currItem.getAttribute("id") + "\n");
if( currItem.getAttribute("id").indexOf("NetscapeSearch.src") != -1 ) {
engineURIs[engineURIs.length] = currItem.getAttribute("id");
break;
@ -533,12 +638,7 @@ function doSearch()
return true;
}
// check an engine representation in the engine list
function doCheck( aNode )
{
saveEngines( document.getElementById("categoryList") )
return false;
}
function checkSearchProgress( aSearchURL )
{
@ -593,6 +693,8 @@ function checkSearchProgress( aSearchURL )
return(activeSearchFlag);
}
function FOO_doSearch()
{
var textNode = document.getElementById("sidebar-search-text");
@ -602,6 +704,8 @@ function FOO_doSearch()
return(true);
}
function sidebarOpenURL(event, treeitem, root)
{
try {
@ -665,6 +769,8 @@ function sidebarOpenURL(event, treeitem, root)
}
}
// this should go somewhere else.
function OpenSearch( tabName, forceDialogFlag, aSearchStr, engineURIs )
{
@ -765,6 +871,8 @@ function OpenSearch( tabName, forceDialogFlag, aSearchStr, engineURIs )
}
}
function switchTab( aPageIndex )
{
var deck = document.getElementById( "advancedDeck" );
@ -803,8 +911,8 @@ function switchTab( aPageIndex )
}
if (haveSearchRef == true)
saveQueryButton.removeAttribute("style", "visibility: collapse");
else saveQueryButton.setAttribute("style", "visibility: collapse");
saveQueryButton.removeAttribute("disabled", "true");
else saveQueryButton.setAttribute("disabled", "true");
return(true);
}
@ -846,12 +954,15 @@ function saveSearch()
if (target) target = target.Value;
if (target && target != "")
{
// convert pluses (+) back to spaces
target = target.replace(/+/i, " ");
lastSearchText = unescape(target);
}
}
dump("Bookmark search Name: '" + lastSearchText + "'\n");
dump("Bookmark search URL: '" + lastSearchURI + "'\n");
debug("Bookmark search Name: '" + lastSearchText + "'\n");
debug("Bookmark search URL: '" + lastSearchURI + "'\n");
if ((lastSearchURI == null) || (lastSearchURI == "")) return(false);
if ((lastSearchText == null) || (lastSearchText == "")) return(false);
@ -862,7 +973,7 @@ function saveSearch()
var textNode = document.getElementById("sidebar-search-text");
if( !textNode ) return(false);
var searchTitle = "Internet Search: '" + lastSearchText + "'"; // using " + gSites;
var searchTitle = "Search: '" + lastSearchText + "'"; // using " + gSites;
if (bmks) bmks.AddBookmark(lastSearchURI, searchTitle);
return(true);

View File

@ -50,22 +50,26 @@
<titledbutton id="stopbutton" align="left" src="resource:/res/rdf/loading.gif" value="&stop.button.label;" onclick="return doStop();" class="dialog toolbar-non-iconic" style="display:none;"/>
</box>
<box align="horizontal" class="spaced">
<html:label for="">&within.label;</html:label>
<template id="categoryTemplate">
<rule iscontainer="true">
<html:optgroup uri="..." label="rdf:http://home.netscape.com/NC-rdf#title" />
</rule>
<rule>
<html:option uri="..." value="rdf:http://home.netscape.com/NC-rdf#category" >
<textnode value="rdf:http://home.netscape.com/NC-rdf#title" />
</html:option>
</rule>
<text value="&within.label;" />
<menulist id="categoryList" ref="NC:SearchCategoryRoot" datasources="rdf:null"
onmousedown="return switchTab(1);" >
<template>
<menupopup>
<menuitem uri="rdf:*" oncommand="return chooseCategory(this);"
data="rdf:http://home.netscape.com/NC-rdf#category"
value="rdf:http://home.netscape.com/NC-rdf#title" />
</menupopup>
</template>
<html:select id="categoryList" template="categoryTemplate" ref="NC:SearchCategoryRoot" datasources="rdf:null"
onmousedown="return switchTab(1);"
onchange="return chooseCategory(this)" >
<html:option value="NC:SearchEngineRoot" >&allengines.label;</html:option>
</html:select>
<menupopup id="categoryPopup">
<menuitem data="NC:SearchEngineRoot" value="&allengines.label;"
oncommand="return chooseCategory(this)" />
<menuseparator />
</menupopup>
</menulist>
</box>
</box>