search field autocomplete

This commit is contained in:
Shish 2010-04-26 04:51:56 +01:00
parent 062f30abe7
commit 29d9c7ae16
2 changed files with 26 additions and 0 deletions

View File

@ -173,6 +173,28 @@ class Index extends SimpleExtension {
$this->theme->display_page($page, $images);
}
}
if($event->page_matches("api/internal/index/get_tags")) {
$page->set_mode("data");
$page->set_type("text/plain");
$term = ltrim($_GET["term"]);
$space_pos = strrpos($term, " ");
$pre = "";
$term_only = $term;
if($space_pos !== FALSE) {
$pre = substr($term, 0, $space_pos+1);
$term_only = substr($term, $space_pos+1);
}
$all = $database->get_all(
"SELECT tag FROM tags WHERE tag LIKE ? LIMIT 10",
array($term_only."%"));
$res = array();
foreach($all as $row) {$res[] = $pre.$row["tag"];}
$page->set_data(json_encode($res));
}
}
public function onSetupBuilding($event) {

View File

@ -82,6 +82,10 @@ EOD;
<script><!--
$(document).ready(function() {
$(\"#search_input\").DefaultValue(\"Search\");
$(\"#search_input\").autocomplete({
source: \"".make_link("api/internal/index/get_tags")."\",
minLength: 2
});
});
//--></script>
<p><form action='$h_search_link' method='GET'>