]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - themes/_global/js/autoCompleteTags.js
3 function split( val
) {
4 return val
.split( /,\s*/ );
6 function extractLast( term
) {
7 return split( term
).pop();
11 $("#value").bind("keydown", function(event
) {
12 if (event
.keyCode
=== $.ui
.keyCode
.TAB
&& $(this).data("ui-autocomplete").menu
.active
) {
13 event
.preventDefault();
16 source : function(request
, response
) {
17 $.getJSON("./?view=tags", {
18 term : extractLast(request
.term
),
19 //id: $(':hidden#entry_id').val()
24 var term
= extractLast(this.value
);
25 if (term
.length
< 1) {
30 // prevent value inserted on focus
33 select : function(event
, ui
) {
34 var terms
= split(this.value
);
35 // remove the current input
37 // add the selected item
38 terms
.push(ui
.item
.value
);
39 // add placeholder to get the comma-and-space at the end
41 this.value
= terms
.join(", ");
46 $('.suggestedtag').click(function(){
47 var input
= $("#value");
48 var value
= input
.val();
49 var tag
= $(this).text();
50 var terms
= value
.split(','); // tags into the <input>
51 if (jQuery
.inArray(tag
, terms
) == -1 ) { // if the tag hasn't already been added
56 input
[0].selectionStart
= input
[0].selectionEnd
= input
.val().length
;