search field autocomplete
This commit is contained in:
parent
062f30abe7
commit
29d9c7ae16
@ -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) {
|
||||
|
@ -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'>
|
||||
|
Loading…
x
Reference in New Issue
Block a user