From 53a7e23b641474757cfffb7b70853e21dcd60165 Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 28 Feb 2014 02:03:41 +0000 Subject: [PATCH] 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) --- ext/tag_list/main.php | 14 +++++++++----- lib/shimmie.js | 22 +++++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 3dc3b92d..c299fdd3 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -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"); diff --git a/lib/shimmie.js b/lib/shimmie.js index f7731186..2a1f09ed 100644 --- a/lib/shimmie.js +++ b/lib/shimmie.js @@ -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();