Added an `hq' argument for a pre-filter argument, parsed on a separate

page instead of in index.html, so that it can be removed from the url
to avoid resetting the cookie on every refresh.

svn: r10715
This commit is contained in:
Eli Barzilay 2008-07-11 08:40:11 +00:00
parent d58b1ffdac
commit f44a06a4da
3 changed files with 54 additions and 4 deletions

View File

@ -20,6 +20,11 @@
(define-runtime-path search-script "search.js")
;; this file is used as a trampoline to set a context (a pre-filter cookie) and
;; then hop over to the search page (the search page can do it itself, but it's
;; to heavy to load twice).
(define-runtime-path search-context-page "search-context.html")
(define (quote-string str)
(define (hex4 ch)
(let ([s (number->string (char->integer (string-ref ch 0)) 16)])
@ -166,9 +171,10 @@
(add-between ms ",\n "))};
@||})))
(let ([js (build-path dest-dir "search.js")])
(when (file-exists? js) (delete-file js))
(copy-file search-script js))
(for ([src (list search-script search-context-page)])
(define dest (build-path dest-dir (file-name-from-path file)))
(when (file-exists? dest) (delete-file dest))
(copy-file src dest))
(list
(script-ref "plt-index.js"

View File

@ -0,0 +1,43 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--
This page serves as a trampoline -- it finds an "hq" parameter,
stores it in a cookie, and continues to the search page. This
avoids having the "hq" argument be on the search page -- since then
when you refresh the search you will reset the cookie.
-->
<head>
<meta http-equiv="content-type" content="text-html; charset=utf-8" />
<title>Search Manuals</title>
<script type="text/javascript" src="../scribble-common.js"></script>
</head>
<body>
<noscript>Sorry, you must have JavaScript to use this page.<br></noscript>
<script>
if (location.search.length > 0) {
var paramstrs = location.search.substring(1).split(/[;&]/);
var newsearch = null;
for (var i=0; i<paramstrs.length; i++) {
var param = paramstrs[i].split(/=/);
// an empty "hq=" can be used to clear the cookie
if (param[0] == "hq") {
SetCookie("PLT_PreQuery", ((param.length==2) ? unescape(param[1]) : ""));
} else {
newsearch = (newsearch == null)
? paramstrs[i] : (newsearch + "&" + paramstrs[i]);
}
}
newsearch = (newsearch == null) ? "" : ("?" + newsearch);
// localtion.replace => jump without leaving the current page in the history
// (the new url uses "index.html" and the new search part)
location.replace(location.href.replace(/\/[^\/?#]*[?][^#]*/,
"/index.html" + newsearch));
} else {
// no parameters found? just jump to the search page...
location.href = "index.html";
}
</script>
</body>
</html>

View File

@ -168,18 +168,19 @@ function InitializeSearch() {
results_container.normalize();
result_links.push(n);
AdjustResultsNum();
PreFilter();
// get search string
if (location.search.length > 0) {
var paramstrs = location.search.substring(1).split(/[;&]/);
for (var i=0; i<paramstrs.length; i++) {
var param = paramstrs[i].split(/=/);
// ignores an empty "q=" (param.length will be 1)
if (param.length == 2 && param[0] == "q") {
query.value = unescape(param[1]);
break;
}
}
}
PreFilter();
DoSearch();
query.focus();
query.select();