Very partial change, the only visible effect should be that "Pre-Query"

is no longer part of the interface in any way.

svn: r16136
This commit is contained in:
Eli Barzilay 2009-09-27 14:13:57 +00:00
parent c3602ff740
commit b9f4662af9
2 changed files with 53 additions and 50 deletions

View File

@ -22,9 +22,10 @@ if (location.search.length > 0) {
var param = paramstrs[i].split(/=/); var param = paramstrs[i].split(/=/);
// an empty "hq=" can be used to clear the cookie // an empty "hq=" can be used to clear the cookie
if (param[0] == "hq") { if (param[0] == "hq") {
SetCookie("PLT_PreQuery", ((param.length==2) ? unescape(param[1]) : "")); SetCookie("PLT_ContextQuery",
((param.length==2) ? unescape(param[1]) : ""));
} else if (param[0] == "label") { } else if (param[0] == "label") {
SetCookie("PLT_PreQueryLabel", SetCookie("PLT_ContextQueryLabel",
((param.length==2) ? unescape(param[1]) : "")); ((param.length==2) ? unescape(param[1]) : ""));
} else { } else {
newsearch = (newsearch == null) newsearch = (newsearch == null)

View File

@ -1,14 +1,14 @@
// Globally visible bindings // Globally visible bindings
var key_handler, toggle_panel, hide_prefs, new_query, refine_query, var key_handler, toggle_panel, hide_prefs, new_query, refine_query,
set_pre_query, set_context_query, set_show_manuals, set_show_manual_titles, set_ctx_query, set_context_query, set_show_manuals, set_show_manual_titles,
set_results_num, set_type_delay, set_highlight_color, status_line, set_results_num, set_type_delay, set_highlight_color, status_line,
saved_status = false, pre_query_label_line; saved_status = false, ctx_query_label_line;
(function(){ (function(){
// Configuration options (use || in case a cookie exists but is empty) // Configuration options (use || in case a cookie exists but is empty)
var pre_query = GetCookie("PLT_PreQuery",""); var ctx_query = GetCookie("PLT_ContextQuery","");
var pre_query_label = GetCookie("PLT_PreQueryLabel",""); // no prefs UI var ctx_query_label = GetCookie("PLT_ContextQueryLabel",""); // no prefs UI
var manual_settings = parseInt(GetCookie("PLT_ManualSettings",1)); var manual_settings = parseInt(GetCookie("PLT_ManualSettings",1));
var show_manuals = manual_settings % 10; var show_manuals = manual_settings % 10;
var show_manual_titles = ((manual_settings - show_manuals) / 10) > 0; var show_manual_titles = ((manual_settings - show_manuals) / 10) > 0;
@ -25,7 +25,7 @@ var prev_page_link1, prev_page_link2, next_page_link1, next_page_link2;
// 2 index links // 2 index links
// 3 help/pref toggle // 3 help/pref toggle
// 4 pref widgets // 4 pref widgets
// 5 clear current pre-filter context // 5 clear current context-query
// -1 prev/next page (un-tab-able) // -1 prev/next page (un-tab-able)
function MakePref(label, input) { function MakePref(label, input) {
@ -62,9 +62,9 @@ function MakeChevrons(num, middle) {
+'</div>'; +'</div>';
} }
function MakePreQueryItem(qry, desc) { function MakeContextQueryItem(qry, desc) {
return '<li><a href="?hq='+encodeURIComponent(qry)+'" tabIndex="4"' return '<li><a href="?hq='+encodeURIComponent(qry)+'" tabIndex="4"'
+' title="set this as your pre-filter context"' +' title="set this as your context-query"'
+' style="text-decoration: none;"' +' style="text-decoration: none;"'
+' onclick="return new_query(this,\'' +' onclick="return new_query(this,\''
+encodeURIComponent(desc) +encodeURIComponent(desc)
@ -169,9 +169,9 @@ function InitializeSearch() {
"The color to use for highlighting exact" "The color to use for highlighting exact"
+" matches (a known color name or #RGB)") +" matches (a known color name or #RGB)")
+'>') +'>')
+ MakePref('Pre-Query', + MakePref('Context-Query',
'<input type="text" ' '<input type="text" '
+PrefInputArgs("pre_query", +PrefInputArgs("ctx_query",
"A &ldquo;context&rdquo; query that is implicitly added" "A &ldquo;context&rdquo; query that is implicitly added"
+" to all searches") +" to all searches")
+'>&nbsp;' +'>&nbsp;'
@ -182,20 +182,20 @@ function InitializeSearch() {
+'</div>' +'</div>'
+'<div id="contexts_panel" '+panelstyle+'>' +'<div id="contexts_panel" '+panelstyle+'>'
+'<table align="center" style="margin: 0em 2em;">' +'<table align="center" style="margin: 0em 2em;">'
+ MakePref('Pre-Query', + MakePref('Context-Query',
'<input type="text" ' '<input type="text" '
+PrefInputArgs("context_query", +PrefInputArgs("context_query",
"A &ldquo;context&rdquo; query that is implicitly added" "A &ldquo;context&rdquo; query that is implicitly added"
+" to all searches") +" to all searches")
+'>') +'>')
+'</table>' +'</table>'
+'Clicking the following links will set your pre-query context to a' +'Clicking the following links will set your context-query to a'
+' few common choices:' +' few common choices:'
+'<ul style="padding: 0em; margin: 0.5em 1.5em;">' +'<ul style="padding: 0em; margin: 0.5em 1.5em;">'
+MakePreQueryItem("M:", "Bindings") +MakeContextQueryItem("M:", "Bindings")
+MakePreQueryItem("T:reference", "Reference manual") +MakeContextQueryItem("T:reference", "Reference manual")
+MakePreQueryItem("M:scheme", "{{scheme}} bindings") +MakeContextQueryItem("M:scheme", "{{scheme}} bindings")
+MakePreQueryItem("M:scheme/base", "{{scheme/base}} bindings") +MakeContextQueryItem("M:scheme/base", "{{scheme/base}} bindings")
+'</ul>' +'</ul>'
+'</div>' +'</div>'
+MakeChevrons(1, +MakeChevrons(1,
@ -208,12 +208,12 @@ function InitializeSearch() {
+'</div>' +'</div>'
+'<br />' +'<br />'
+MakeChevrons(2, +MakeChevrons(2,
'<span id="pre_query_label" style="color: #444;">&nbsp;</span>') '<span id="ctx_query_label" style="color: #444;">&nbsp;</span>')
+'</div>'; +'</div>';
// get the widgets we use // get the widgets we use
query = document.getElementById("search_box"); query = document.getElementById("search_box");
status_line = document.getElementById("search_status"); status_line = document.getElementById("search_status");
pre_query_label_line = document.getElementById("pre_query_label"); ctx_query_label_line = document.getElementById("ctx_query_label");
prev_page_link1 = document.getElementById("prev_page_link1"); prev_page_link1 = document.getElementById("prev_page_link1");
prev_page_link2 = document.getElementById("prev_page_link2"); prev_page_link2 = document.getElementById("prev_page_link2");
next_page_link1 = document.getElementById("next_page_link1"); next_page_link1 = document.getElementById("next_page_link1");
@ -237,7 +237,7 @@ function InitializeSearch() {
} }
} }
} }
PreFilter(); ContextFilter();
DoSearch(); DoSearch();
query.focus(); query.focus();
query.select(); query.select();
@ -457,13 +457,13 @@ function Search(data, term, is_pre, K) {
function GetContextHTML() { function GetContextHTML() {
// useful only when a context is set // useful only when a context is set
return (((pre_query_label != "") && pre_query_label) return (((ctx_query_label != "") && ctx_query_label)
? SanitizeHTML(pre_query_label) ? SanitizeHTML(ctx_query_label)
: ('&ldquo;' + SanitizeHTML(pre_query) + '&rdquo;')); : ('&ldquo;' + SanitizeHTML(ctx_query) + '&rdquo;'));
} }
function GetContextClearerHTML(text) { function GetContextClearerHTML(text) {
return ('<a href="?hq=" tabIndex="5"' return ('<a href="?hq=" tabIndex="5"'
+' title="Clear pre-filter context"' +' title="Clear context-query"'
+' style="text-decoration: none; color: #444;' +' style="text-decoration: none; color: #444;'
+' font-size: 82%; font-weight: bold;"' +' font-size: 82%; font-weight: bold;"'
+' onclick="return new_query(this,\'\');">' +' onclick="return new_query(this,\'\');">'
@ -472,24 +472,24 @@ function GetContextClearerHTML(text) {
} }
var search_data; // pre-filtered searchable index data var search_data; // pre-filtered searchable index data
function PreFilter() { function ContextFilter() {
pre_query = NormalizeSpaces(pre_query); ctx_query = NormalizeSpaces(ctx_query);
search_data = Search(plt_search_data, pre_query, true, false)[1]; search_data = Search(plt_search_data, ctx_query, true, false)[1];
if (pre_query == "") { if (ctx_query == "") {
pre_query_label_line.innerHTML = ctx_query_label_line.innerHTML =
'<a href="#" tabIndex="5"' '<a href="#" tabIndex="5"'
+' title="Edit pre-filter context"' +' title="Edit context-query"'
+' style="text-decoration: none; color: #444;' +' style="text-decoration: none; color: #444;'
+' font-size: 82%; font-weight: bold;"' +' font-size: 82%; font-weight: bold;"'
+' onclick="toggle_panel(\'contexts\'); return false;">' +' onclick="toggle_panel(\'contexts\'); return false;">'
+'[set context]</a>'; +'[set context]</a>';
} else { } else {
pre_query_label_line.innerHTML = ctx_query_label_line.innerHTML =
'Context:&nbsp;' + GetContextHTML() 'Context:&nbsp;' + GetContextHTML()
+ '&nbsp;' + '&nbsp;'
+ GetContextClearerHTML('[clear') + GetContextClearerHTML('[clear')
+ '/<a href="#" tabIndex="5"' + '/<a href="#" tabIndex="5"'
+' title="Edit pre-filter context"' +' title="Edit context-query"'
+' style="text-decoration: none; color: #444;' +' style="text-decoration: none; color: #444;'
+' font-size: 82%; font-weight: bold;"' +' font-size: 82%; font-weight: bold;"'
+' onclick="toggle_panel(\'contexts\'); return false;">' +' onclick="toggle_panel(\'contexts\'); return false;">'
@ -613,14 +613,14 @@ function UpdateResults() {
if (search_results.length == 0) { if (search_results.length == 0) {
if (last_search_term == "") status_line.innerHTML = ""; if (last_search_term == "") status_line.innerHTML = "";
else status_line.innerHTML = 'No matches found' else status_line.innerHTML = 'No matches found'
+ ((pre_query != "") + ((ctx_query != "")
? (' in '+GetContextHTML() ? (' in '+GetContextHTML()
+' '+GetContextClearerHTML('<small>[clear]</small>')) +' '+GetContextClearerHTML('<small>[clear]</small>'))
: '') : '')
+ '<br><div style="color: black; font-size: 82%;">' + '<br><div style="color: black; font-size: 82%;">'
+ '(Make sure your spelling is correct' + '(Make sure your spelling is correct'
+ (last_search_term.search(/ /)>=0 ? ', or try fewer keywords' : '') + (last_search_term.search(/ /)>=0 ? ', or try fewer keywords' : '')
+ ((pre_query != "") ? ', or clear the search context' : '') + ((ctx_query != "") ? ', or clear the search context' : '')
+ ')</div>'; + ')</div>';
} else if (search_results.length <= results_num) } else if (search_results.length <= results_num)
status_line.innerHTML = "Showing all matches" + exact; status_line.innerHTML = "Showing all matches" + exact;
@ -698,7 +698,7 @@ function NewQuery(node,label) {
DoSearch(); DoSearch();
return false; return false;
} else if ((m = href.search(/[?]hq=[^?&;]*$/)) >= 0) { // `hq' can } else if ((m = href.search(/[?]hq=[^?&;]*$/)) >= 0) { // `hq' can
SetPreQuery(decodeURIComponent(href.substring(m+4)), SetContextQuery(decodeURIComponent(href.substring(m+4)),
decodeURIComponent(label)); decodeURIComponent(label));
return false; return false;
} else { } else {
@ -732,7 +732,7 @@ function TogglePanel(name) {
} }
panel_shown = ((panel_shown != name) && name); panel_shown = ((panel_shown != name) && name);
if (panel_shown == "prefs") { if (panel_shown == "prefs") {
document.getElementById("pre_query_pref").value = pre_query; document.getElementById("ctx_query_pref").value = ctx_query;
document.getElementById("show_manuals_pref").selectedIndex = show_manuals; document.getElementById("show_manuals_pref").selectedIndex = show_manuals;
document.getElementById("show_manual_titles_pref").checked document.getElementById("show_manual_titles_pref").checked
= show_manual_titles; = show_manual_titles;
@ -740,12 +740,14 @@ function TogglePanel(name) {
document.getElementById("type_delay_pref").value = type_delay; document.getElementById("type_delay_pref").value = type_delay;
document.getElementById("highlight_color_pref").value = highlight_color; document.getElementById("highlight_color_pref").value = highlight_color;
} else if (panel_shown == "contexts") { } else if (panel_shown == "contexts") {
document.getElementById("context_query_pref").value = pre_query; document.getElementById("context_query_pref").value = ctx_query;
} }
if (panel_shown) { if (panel_shown) {
document.getElementById(panel_shown+"_panel").style.display = "block"; document.getElementById(panel_shown+"_panel").style.display = "block";
document.getElementById("close_panel").style.display = "block"; document.getElementById("close_panel").style.display = "block";
document.getElementById(panel_shown+"_panel").scrollIntoView(); // This is annoying -- would be nicer to have a way to make sure
// that it's in view without scrolling if not necessary.
// document.getElementById(panel_shown+"_panel").scrollIntoView();
} }
} }
toggle_panel = TogglePanel; toggle_panel = TogglePanel;
@ -767,23 +769,23 @@ function SetShowManuals(inp) {
} }
set_show_manuals = SetShowManuals; set_show_manuals = SetShowManuals;
function SetPreQuery(inp,label) { function SetContextQuery(inp,label) {
// can be called with the input object, or with a string // can be called with the input object, or with a string
if (typeof inp != "string") inp = inp.value; if (typeof inp != "string") inp = inp.value;
if (inp != pre_query) { if (inp != ctx_query) {
pre_query = inp; ctx_query = inp;
SetCookie("PLT_PreQuery", pre_query); SetCookie("PLT_ContextQuery", ctx_query);
label = label || ""; label = label || "";
pre_query_label = label; ctx_query_label = label;
SetCookie("PLT_PreQueryLabel",label); SetCookie("PLT_ContextQueryLabel",label);
PreFilter(); ContextFilter();
document.getElementById("pre_query_pref").value = pre_query; document.getElementById("ctx_query_pref").value = ctx_query;
document.getElementById("context_query_pref").value = pre_query; document.getElementById("context_query_pref").value = ctx_query;
DoSearch(); DoSearch();
} }
} }
set_pre_query = SetPreQuery; set_ctx_query = SetContextQuery;
set_context_query = SetPreQuery; // a different widget, same effect set_context_query = SetContextQuery; // a different widget, same effect
function SetShowManuals(inp) { function SetShowManuals(inp) {
if (inp.selectedIndex != show_manuals) { if (inp.selectedIndex != show_manuals) {