From 4d699d8d47a98ef09148eaa7724757849a52ebf8 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Tue, 17 Jul 2012 20:18:19 +0200 Subject: [PATCH] Added quick-and-dirty javascript dropdown search thing --- www/index.pl | 7 +- www/man.css | 8 ++ www/man.js | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 234 insertions(+), 3 deletions(-) diff --git a/www/index.pl b/www/index.pl index 415b041..9b8ad6d 100755 --- a/www/index.pl +++ b/www/index.pl @@ -475,10 +475,11 @@ sub xmlsearch { my $q = $self->reqGet('q')||''; my $man = $self->dbSearch($q, 20); + # The JS dropdown search expects this particular format. $self->resHeader('Content-Type' => 'text/xml; charset=UTF-8'); xml; tag 'results'; - tag 'man', %$_, undef for(@$man); + tag 'item', id => "$_->{name}.$_->{section}", %$_, undef for(@$man); end 'results'; } @@ -501,8 +502,8 @@ sub htmlHeader { div id => 'header'; a href => '/', 'manned.org'; - form; - input type => 'text', name => 'q'; + form action => '/', method => 'get'; + input type => 'text', name => 'q', id => 'q'; input type => 'submit', value => ' '; end; end; diff --git a/www/man.css b/www/man.css index 4bca59c..dc23ff9 100644 --- a/www/man.css +++ b/www/man.css @@ -80,3 +80,11 @@ td { padding: 1px 5px; font-size: 12px; border-left: 1px solid #ccc; } pre, pre * { font-family: "Lucida Console", Monospace; font-size: 15px } pre b { color: #369; font-weight: normal; } +#ds_box { position: absolute; top: 0; border: 1px solid $border$; border-top: none; background: #f0f8ff; cursor: pointer; z-index: 2 } +#ds_box.hidden { display: none } +#ds_box b { padding: 2px 0 0 10px; font-size: 12px; } +#ds_box tr.selected { background: #fff; } +#ds_box table { width: 100%; border: 0; background: none; margin: 0 } +#ds_box td { border: 0; padding: 1px 5px } +#ds_box i { padding-left: 5px; color: #aaa; font-style: normal } + diff --git a/www/man.js b/www/man.js index 6a7b45c..4cb3269 100644 --- a/www/man.js +++ b/www/man.js @@ -3,6 +3,27 @@ var expanded_icon = '▾'; var collapsed_icon = '▸'; +var http_request = false; +function ajax(url, func, async) { + if(!async && http_request) + http_request.abort(); + var req = (window.ActiveXObject) ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest(); + if(req == null) + return alert("Your browser does not support the functionality this website requires."); + if(!async) + http_request = req; + req.onreadystatechange = function() { + if(!req || req.readyState != 4 || !req.responseText) + return; + if(req.status != 200) + return alert('Whoops, error! :('); + func(req); + }; + url += (url.indexOf('?')>=0 ? ';' : '?')+(Math.floor(Math.random()*999)+1); + req.open('GET', url, true); + req.send(null); +} + function byId(n) { return document.getElementById(n) } @@ -49,6 +70,20 @@ function tag() { } return el; } +function addBody(el) { + if(document.body.appendChild) + document.body.appendChild(el); + else if(document.documentElement.appendChild) + document.documentElement.appendChild(el); + else if(document.appendChild) + document.appendChild(el); +} +function setContent() { + setText(arguments[0], ''); + for(var i=1; i0 ? l[i-1] : l[l.length-1]; + else + sel = l[i+1] ? l[i+1] : l[0]; + } + obj.ds_selectedId = sel.id.substr(7); + } + + // set selected class + for(var i=0; i