author | Madhusudan.C.S <madhusudancs@gmail.com> |
Fri, 21 Jan 2011 00:27:33 +0530 | |
changeset 504 | 3b78ea899168 |
parent 423 | 966d3241d2b4 |
permissions | -rw-r--r-- |
423
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1 |
var create_form = function (suggest_task_tags_url) { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2 |
$(function() { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
3 |
function split( val ) { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
4 |
return val.split( /,\s*/ ); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
5 |
} |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
6 |
|
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
function extractLast( term ) { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
8 |
return split( term ).pop(); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
9 |
} |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
10 |
|
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
11 |
$( "#id_tags_field") |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
12 |
// don't navigate away from the field on tab when selecting an item |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
.bind( "keydown", function( event ) { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
14 |
if ( event.keyCode === $.ui.keyCode.TAB && |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
15 |
$( this ).data( "autocomplete" ).menu.active ) { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
event.preventDefault(); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
17 |
} |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
18 |
}) |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
19 |
.autocomplete({ |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
20 |
source: function( request, response ) { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
21 |
$.getJSON(suggest_task_tags_url, { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
term: extractLast( request.term ) |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
23 |
}, response ); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
24 |
}, |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
25 |
search: function() { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
26 |
// custom minLength |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
27 |
var term = extractLast( this.value ); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
28 |
if ( term.length < 2 ) { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
29 |
return false; |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
30 |
} |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
31 |
}, |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
32 |
focus: function() { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
33 |
// prevent value inserted on focus |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
34 |
return false; |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
35 |
}, |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
36 |
select: function( event, ui ) { |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
37 |
var terms = split( this.value ); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
38 |
// remove the current input |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
39 |
terms.pop(); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
40 |
// add the selected item |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
41 |
terms.push( ui.item.value ); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
42 |
// add placeholder to get the comma-and-space at the end |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
43 |
terms.push( "" ); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
44 |
this.value = terms.join( ", " ); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
45 |
return false; |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
46 |
} |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
47 |
}); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
48 |
}); |
966d3241d2b4
Add JQuery and JQuery UI files to the collection.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
49 |
} |