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

View File

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