diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-03-10 18:14:43 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-03-10 18:14:43 +0100 |
commit | 1acd18510a8fc5b843bf793322ed79b249b195dc (patch) | |
tree | 8218a340193e2827e1c4b0a6117adf81344e7b43 /themes/default/js/autoCompleteTags.js | |
parent | d47a05a9a5185e835d51341febc8257f5262ce03 (diff) | |
parent | fb26cc9375ce9ef8df748eb473eb6e58884421c6 (diff) | |
download | wallabag-1acd18510a8fc5b843bf793322ed79b249b195dc.tar.gz wallabag-1acd18510a8fc5b843bf793322ed79b249b195dc.tar.zst wallabag-1acd18510a8fc5b843bf793322ed79b249b195dc.zip |
Merge pull request #544 from mariroz/feature-tags-autocomplete
a lot of enhancements related to tags: tags list is now sorted, shows number of articles, autocomplete added according to #477, #542
Diffstat (limited to 'themes/default/js/autoCompleteTags.js')
-rwxr-xr-x | themes/default/js/autoCompleteTags.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/themes/default/js/autoCompleteTags.js b/themes/default/js/autoCompleteTags.js new file mode 100755 index 00000000..90bc982c --- /dev/null +++ b/themes/default/js/autoCompleteTags.js | |||
@@ -0,0 +1,47 @@ | |||
1 | jQuery(function($) { | ||
2 | |||
3 | function split( val ) { | ||
4 | return val.split( /,\s*/ ); | ||
5 | } | ||
6 | function extractLast( term ) { | ||
7 | return split( term ).pop(); | ||
8 | } | ||
9 | |||
10 | |||
11 | $("#value").bind("keydown", function(event) { | ||
12 | if (event.keyCode === $.ui.keyCode.TAB && $(this).data("ui-autocomplete").menu.active) { | ||
13 | event.preventDefault(); | ||
14 | } | ||
15 | }).autocomplete({ | ||
16 | source : function(request, response) { | ||
17 | $.getJSON("./?view=tags", { | ||
18 | term : extractLast(request.term), | ||
19 | //id: $(':hidden#entry_id').val() | ||
20 | }, response); | ||
21 | }, | ||
22 | search : function() { | ||
23 | // custom minLength | ||
24 | var term = extractLast(this.value); | ||
25 | if (term.length < 1) { | ||
26 | return false; | ||
27 | } | ||
28 | }, | ||
29 | focus : function() { | ||
30 | // prevent value inserted on focus | ||
31 | return false; | ||
32 | }, | ||
33 | select : function(event, ui) { | ||
34 | var terms = split(this.value); | ||
35 | // remove the current input | ||
36 | terms.pop(); | ||
37 | // add the selected item | ||
38 | terms.push(ui.item.value); | ||
39 | // add placeholder to get the comma-and-space at the end | ||
40 | terms.push(""); | ||
41 | this.value = terms.join(", "); | ||
42 | return false; | ||
43 | } | ||
44 | }); | ||
45 | |||
46 | |||
47 | }); | ||