various autocomplete tweaks

* made limit for /api/internal/tag_list/complete optional (as this breaks the autocomplete on dbs with lots of tags)
* removed delay + minChars = 1 again (due to above change)
* first autocomplete tag is selected by default
* tab now works as a select button
* autocompleted tags will now be followed by a space (so the next tag can be instantly autocompleted)
This commit is contained in:
Daku 2014-02-28 02:03:41 +00:00
parent e78ddc69f3
commit 53a7e23b64
2 changed files with 22 additions and 14 deletions

View File

@ -49,12 +49,16 @@ class TagList extends Extension {
if($event->page_matches("api/internal/tag_list/complete")) {
if(!isset($_GET["s"])) return;
$all = $database->get_all(
"SELECT tag FROM tags WHERE tag LIKE :search AND count > 0 LIMIT 10",
array("search"=>$_GET["s"]."%"));
$limit = 0;
$limitSQL = "";
$SQLarr = array("search"=>$_GET["s"]."%");
if(isset($_GET["limit"]) && $_GET["limit"] !== 0){
$limitSQL = "LIMIT :limit";
$SQLarr['limit'] = $_GET["limit"];
}
$res = array();
foreach($all as $row) {$res[] = $row["tag"];}
$res = $database->get_col(
"SELECT tag FROM tags WHERE tag LIKE :search AND count > 0 $limitSQL", $SQLarr);
$page->set_mode("data");
$page->set_type("text/plain");

View File

@ -8,16 +8,20 @@ $(document).ready(function() {
//TODO: Possibly move to using TextExtJS for autocomplete? - http://textextjs.com/
// Also use autocomplete in tag box?
$('.autocomplete_tags').autocomplete(base_href + '/api/internal/tag_list/complete', {
width: 320,
max: 10,
highlight: false,
multiple: true,
multipleSeparator: ' ',
scroll: true,
scrollHeight: 300,
selectFirst: false,
//extraParams: {limit: 10},
queryParamName: 's',
delay: 150
minChars: 1,
delay: 0,
useCache: true,
maxCacheLength: 10,
matchInside: false,
selectFirst: true,
selectOnly: false,
preventDefaultReturn: 1,
preventDefaultTab: 1,
useDelimiter: true,
delimiterChar : " ",
delimiterKeyCode : 48
});
$("TABLE.sortable").tablesorter();