rails3-jquery-autocomplete 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/generators/templates/autocomplete-rails.js +73 -12
- metadata +5 -5
@@ -15,16 +15,77 @@
|
|
15
15
|
*/
|
16
16
|
|
17
17
|
$(document).ready(function(){
|
18
|
-
|
19
|
-
$(this).autocomplete({
|
20
|
-
source: $(this).attr('data-autocomplete'),
|
21
|
-
select: function(event, ui) {
|
22
|
-
$(this).val(ui.item.value);
|
23
|
-
if ($(this).attr('id_element')) {
|
24
|
-
$($(this).attr('id_element')).val(ui.item.id);
|
25
|
-
}
|
26
|
-
return false;
|
27
|
-
}
|
28
|
-
});
|
29
|
-
});
|
18
|
+
$('input[data-autocomplete]').railsAutocomplete();
|
30
19
|
});
|
20
|
+
|
21
|
+
(function(jQuery)
|
22
|
+
{
|
23
|
+
var self = null;
|
24
|
+
jQuery.fn.railsAutocomplete = function() {
|
25
|
+
return this.live('focus',function() {
|
26
|
+
if (!this.railsAutoCompleter) {
|
27
|
+
this.railsAutoCompleter = new jQuery.railsAutocomplete(this);
|
28
|
+
}
|
29
|
+
});
|
30
|
+
};
|
31
|
+
|
32
|
+
jQuery.railsAutocomplete = function (e) {
|
33
|
+
_e = e;
|
34
|
+
this.init(_e);
|
35
|
+
};
|
36
|
+
|
37
|
+
jQuery.railsAutocomplete.fn = jQuery.railsAutocomplete.prototype = {
|
38
|
+
railsAutocomplete: '0.0.1'
|
39
|
+
};
|
40
|
+
|
41
|
+
jQuery.railsAutocomplete.fn.extend = jQuery.railsAutocomplete.extend = jQuery.extend;
|
42
|
+
jQuery.railsAutocomplete.fn.extend({
|
43
|
+
init: function(e) {
|
44
|
+
e.delimiter = $(e).attr('data-delimiter') || null;
|
45
|
+
function split( val ) {
|
46
|
+
return val.split( e.delimiter );
|
47
|
+
}
|
48
|
+
function extractLast( term ) {
|
49
|
+
return split( term ).pop();
|
50
|
+
}
|
51
|
+
|
52
|
+
$(e).autocomplete({
|
53
|
+
source: function( request, response ) {
|
54
|
+
$.getJSON( $(e).attr('data-autocomplete'), {
|
55
|
+
term: extractLast( request.term )
|
56
|
+
}, response );
|
57
|
+
},
|
58
|
+
search: function() {
|
59
|
+
// custom minLength
|
60
|
+
var term = extractLast( this.value );
|
61
|
+
if ( term.length < 2 ) {
|
62
|
+
return false;
|
63
|
+
}
|
64
|
+
},
|
65
|
+
focus: function() {
|
66
|
+
// prevent value inserted on focus
|
67
|
+
return false;
|
68
|
+
},
|
69
|
+
select: function( event, ui ) {
|
70
|
+
var terms = split( this.value );
|
71
|
+
// remove the current input
|
72
|
+
terms.pop();
|
73
|
+
// add the selected item
|
74
|
+
terms.push( ui.item.value );
|
75
|
+
// add placeholder to get the comma-and-space at the end
|
76
|
+
if (e.delimiter != null) {
|
77
|
+
terms.push( "" );
|
78
|
+
this.value = terms.join( e.delimiter );
|
79
|
+
} else {
|
80
|
+
this.value = terms.join("");
|
81
|
+
if ($(this).attr('id_element')) {
|
82
|
+
$($(this).attr('id_element')).val(ui.item.id);
|
83
|
+
}
|
84
|
+
};
|
85
|
+
|
86
|
+
return false;
|
87
|
+
}
|
88
|
+
});
|
89
|
+
}
|
90
|
+
});
|
91
|
+
})(jQuery);
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails3-jquery-autocomplete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Padilla
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-05 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|