* A little better JS event handler code

* Re-add search box, now appearing on all pages

svn: r10030

original commit: 66cb57f46d68e2dffb00983484fbd51743032872
This commit is contained in:
Eli Barzilay 2008-05-30 04:12:21 +00:00
parent ed08874f6c
commit 34f239498b
2 changed files with 12 additions and 14 deletions

View File

@ -186,17 +186,16 @@
[onchange "delayed_search(this.value,event);"]
[onkeyup "delayed_search(this.value,event);"]))})
(define (search-index-box index-url) ; appears on every page
)
(define (search-index-box) ; appears on every page
(let ([sa string-append])
`(input
([style ,(sa "font-size: 75%; margin: 0px; padding: 0px; border: 1px;"
" background-color: #eee; color: #888;")]
[type "text"]
[value "...search..."]
[onkeypress ,(sa "if (event && event.keyCode==13"
" && this.value.indexOf(\"...search...\")<0) {"
" location=\"doc-index.html?q=\"+escape(this.value);"
" };")]
[onkeypress ,(format "return DoSearchKey(event, this, ~s);" (version))]
[onfocus ,(sa "this.style.color=\"black\";"
" if (this.value.indexOf(\"...search...\")>=0)"
" this.value=\"\";")]
@ -204,8 +203,6 @@
" this.style.color=\"#888\";"
" this.value=\"...search...\"; }")]))))
)
;; ----------------------------------------
;; main mixin
@ -611,9 +608,9 @@
#; ; no need for these index-local searches
,@(if (eq? d index)
null
`((small nbsp
,(search-index-box (derive-filename index))))))
null))
`((small nbsp ,(search-index-box)))))
null)
,@(if up-path `(nbsp (small ,(search-index-box))) null))
(div ([class "navright"])
,@(render
(make-element

View File

@ -44,14 +44,15 @@ function NormalizePath(path) {
return path;
}
function DoSearchKey(event, field) {
function DoSearchKey(event, field, ver) {
var val = field.value;
if (event && event.keyCode == 13 && val.indexOf("...search...") < 0) {
var u = GetCookie("PLT_Root");
var u = GetCookie("PLT_Root."+ver);
if (u == null) u = "../"; // default: go up
u = u.replace(/[^\/\\]*$/, "") + "plt-search.html";
location = u + "?q=" + escape(val);
location = u + "search/index.html" + "?q=" + escape(val);
return false;
}
return true;
}
// `noscript' is problematic in some browsers (always renders as a