diff options
| author | tim b <timb@camcompu.home> | 2010-06-10 07:20:27 -0700 |
|---|---|---|
| committer | tim b <timb@camcompu.home> | 2010-06-10 07:20:27 -0700 |
| commit | ba644ed21427afba75a8a578dda3e267c11c81f9 (patch) | |
| tree | b7cf97f1135e27d561378ad2cf2728909584571b /template/search_files.st | |
| parent | 0ff4dd1bbd2c917c28727346947a95f9c31e7b53 (diff) | |
hacky search
Diffstat (limited to 'template/search_files.st')
| -rw-r--r-- | template/search_files.st | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/template/search_files.st b/template/search_files.st new file mode 100644 index 0000000..ebe4d39 --- /dev/null +++ b/template/search_files.st @@ -0,0 +1,80 @@ +<html> + <head> + <title>dump.fm image search</title> + $head()$ + </head> + <body> + + <input type="text" name="search-query" id="search-query" /> + <div id="message"></div> + <div id="content"></div> + + </body> + + <script> + var term = "" + var maxImages = 20; + + function addScript(term){ + jQuery("#search-script").remove() + jQuery("head").append("<scr"+"ipt src='/cmd/ghettosearch/"+term+"' id='search-script'></sc"+"ript>") + } + + function setContent(x){ + jQuery("#content").html(x) + } + + function setMessage(x){ + jQuery("#message").html(x) + } + + function searchError(error){ + setContent("") + setMessage(error) + } + + function searchResult(results){ + var images = [] + var alreadyGot = {} + if(results === null || results.length == 0) { + setContent("") + setMessage("no results found") + } else { + + for(var r = 0; r<results.length; r++){ + if (images.length == maxImages) break; + var content = results[r]['content'] + if (content.substring(0,6) == "<safe>") continue; // skip html posts + var imageUrls = getImagesAsArray(content); + for (var i=0; i<imageUrls; i++){ + var imageUrl = imageUrls[i]; + if (imageUrl in alreadyGot) continue; + alreadyGot[imageUrl] = true + if (imageUrl.indexOf(term) > -1) + images.push(imageUrl) + } + } + var contentString = '' + for(var i = 0; i < images.length; i++){ + contentString += '<a href="'+images[i]+'"><img src="'+images[i]+'"></a>' + } + setContent(contentString) + } + } + + function keyHandler(){ + term = jQuery("#search-query").val().trim() + if (term.length < 3) { + setMessage("search query too small") + } else { + setMessage("searching for '"+term+"'") + addScript(term) + } + } + + jQuery("#search-query").keyup(keyHandler) + + + </script> + +</html>
\ No newline at end of file |
