rails3-jquery-autocomplete 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/integration/Gemfile +1 -1
- data/integration/Gemfile.lock +37 -40
- data/integration/app/controllers/nested_models_controller.rb +8 -0
- data/integration/app/models/feature.rb +2 -0
- data/integration/app/models/product.rb +3 -0
- data/integration/app/views/layouts/application.html.haml +1 -1
- data/integration/app/views/nested_models/new.html.haml +11 -0
- data/integration/config/routes.rb +4 -0
- data/integration/db/migrate/20110209020136_create_features.rb +14 -0
- data/integration/db/schema.rb +8 -1
- data/integration/features/autocomplete.feature +11 -0
- data/integration/features/step_definitions/autocomplete_steps.rb +5 -0
- data/integration/features/support/env.rb +0 -1
- data/integration/public/javascripts/jquery-ui.min.js +90 -394
- data/integration/public/javascripts/rails.js +137 -163
- data/lib/rails3-jquery-autocomplete/autocomplete.rb +1 -1
- data/lib/rails3-jquery-autocomplete/form_helper.rb +1 -1
- data/lib/rails3-jquery-autocomplete/helpers.rb +34 -10
- data/lib/rails3-jquery-autocomplete/version.rb +1 -1
- metadata +10 -7
- data/integration/public/javascripts/jquery-ui.js +0 -11437
@@ -1,163 +1,137 @@
|
|
1
|
-
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
var input = $(this);
|
139
|
-
input.data('enable-with', input.val())
|
140
|
-
.attr('value', input.attr('data-disable-with'))
|
141
|
-
.attr('disabled', 'disabled');
|
142
|
-
});
|
143
|
-
};
|
144
|
-
|
145
|
-
$(disable_with_form_remote_selector).live('ajax:before.rails', disable_with_input_function);
|
146
|
-
$(disable_with_form_not_remote_selector).live('submit.rails', disable_with_input_function);
|
147
|
-
|
148
|
-
$(disable_with_form_remote_selector).live('ajax:complete.rails', function () {
|
149
|
-
$(this).find(disable_with_input_selector).each(function () {
|
150
|
-
var input = $(this);
|
151
|
-
input.removeAttr('disabled')
|
152
|
-
.val(input.data('enable-with'));
|
153
|
-
});
|
154
|
-
});
|
155
|
-
|
156
|
-
var jqueryVersion = $().jquery;
|
157
|
-
|
158
|
-
if (!( (jqueryVersion === '1.4.3') || (jqueryVersion === '1.4.4'))){
|
159
|
-
alert('This rails.js does not support the jQuery version you are using. Please read documentation.');
|
160
|
-
}
|
161
|
-
|
162
|
-
|
163
|
-
});
|
1
|
+
/**
|
2
|
+
* Unobtrusive scripting adapter for jQuery
|
3
|
+
*
|
4
|
+
* Requires jQuery 1.4.3 or later.
|
5
|
+
* https://github.com/rails/jquery-ujs
|
6
|
+
*/
|
7
|
+
|
8
|
+
(function($) {
|
9
|
+
// Triggers an event on an element and returns the event result
|
10
|
+
function fire(obj, name, data) {
|
11
|
+
var event = new $.Event(name);
|
12
|
+
obj.trigger(event, data);
|
13
|
+
return event.result !== false;
|
14
|
+
}
|
15
|
+
|
16
|
+
// Submits "remote" forms and links with ajax
|
17
|
+
function handleRemote(element) {
|
18
|
+
var method, url, data,
|
19
|
+
dataType = element.attr('data-type') || ($.ajaxSettings && $.ajaxSettings.dataType);
|
20
|
+
|
21
|
+
if (element.is('form')) {
|
22
|
+
method = element.attr('method');
|
23
|
+
url = element.attr('action');
|
24
|
+
data = element.serializeArray();
|
25
|
+
// memoized value from clicked submit button
|
26
|
+
var button = element.data('ujs:submit-button');
|
27
|
+
if (button) {
|
28
|
+
data.push(button);
|
29
|
+
element.data('ujs:submit-button', null);
|
30
|
+
}
|
31
|
+
} else {
|
32
|
+
method = element.attr('data-method');
|
33
|
+
url = element.attr('href');
|
34
|
+
data = null;
|
35
|
+
}
|
36
|
+
|
37
|
+
$.ajax({
|
38
|
+
url: url, type: method || 'GET', data: data, dataType: dataType,
|
39
|
+
// stopping the "ajax:beforeSend" event will cancel the ajax request
|
40
|
+
beforeSend: function(xhr, settings) {
|
41
|
+
if (settings.dataType === undefined) {
|
42
|
+
xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
|
43
|
+
}
|
44
|
+
return fire(element, 'ajax:beforeSend', [xhr, settings]);
|
45
|
+
},
|
46
|
+
success: function(data, status, xhr) {
|
47
|
+
element.trigger('ajax:success', [data, status, xhr]);
|
48
|
+
},
|
49
|
+
complete: function(xhr, status) {
|
50
|
+
element.trigger('ajax:complete', [xhr, status]);
|
51
|
+
},
|
52
|
+
error: function(xhr, status, error) {
|
53
|
+
element.trigger('ajax:error', [xhr, status, error]);
|
54
|
+
}
|
55
|
+
});
|
56
|
+
}
|
57
|
+
|
58
|
+
// Handles "data-method" on links such as:
|
59
|
+
// <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
|
60
|
+
function handleMethod(link) {
|
61
|
+
var href = link.attr('href'),
|
62
|
+
method = link.attr('data-method'),
|
63
|
+
csrf_token = $('meta[name=csrf-token]').attr('content'),
|
64
|
+
csrf_param = $('meta[name=csrf-param]').attr('content'),
|
65
|
+
form = $('<form method="post" action="' + href + '"></form>'),
|
66
|
+
metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
|
67
|
+
|
68
|
+
if (csrf_param !== undefined && csrf_token !== undefined) {
|
69
|
+
metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
|
70
|
+
}
|
71
|
+
|
72
|
+
form.hide().append(metadata_input).appendTo('body');
|
73
|
+
form.submit();
|
74
|
+
}
|
75
|
+
|
76
|
+
function disableFormElements(form) {
|
77
|
+
form.find('input[data-disable-with]').each(function() {
|
78
|
+
var input = $(this);
|
79
|
+
input.data('ujs:enable-with', input.val())
|
80
|
+
.val(input.attr('data-disable-with'))
|
81
|
+
.attr('disabled', 'disabled');
|
82
|
+
});
|
83
|
+
}
|
84
|
+
|
85
|
+
function enableFormElements(form) {
|
86
|
+
form.find('input[data-disable-with]').each(function() {
|
87
|
+
var input = $(this);
|
88
|
+
input.val(input.data('ujs:enable-with')).removeAttr('disabled');
|
89
|
+
});
|
90
|
+
}
|
91
|
+
|
92
|
+
function allowAction(element) {
|
93
|
+
var message = element.attr('data-confirm');
|
94
|
+
return !message || (fire(element, 'confirm') && confirm(message));
|
95
|
+
}
|
96
|
+
|
97
|
+
$('a[data-confirm], a[data-method], a[data-remote]').live('click.rails', function(e) {
|
98
|
+
var link = $(this);
|
99
|
+
if (!allowAction(link)) return false;
|
100
|
+
|
101
|
+
if (link.attr('data-remote')) {
|
102
|
+
handleRemote(link);
|
103
|
+
return false;
|
104
|
+
} else if (link.attr('data-method')) {
|
105
|
+
handleMethod(link);
|
106
|
+
return false;
|
107
|
+
}
|
108
|
+
});
|
109
|
+
|
110
|
+
$('form').live('submit.rails', function(e) {
|
111
|
+
var form = $(this);
|
112
|
+
if (!allowAction(form)) return false;
|
113
|
+
|
114
|
+
if (form.attr('data-remote')) {
|
115
|
+
handleRemote(form);
|
116
|
+
return false;
|
117
|
+
} else {
|
118
|
+
disableFormElements(form);
|
119
|
+
}
|
120
|
+
});
|
121
|
+
|
122
|
+
$('form input[type=submit], form button[type=submit], form button:not([type])').live('click.rails', function() {
|
123
|
+
var button = $(this);
|
124
|
+
if (!allowAction(button)) return false;
|
125
|
+
// register the pressed submit button
|
126
|
+
var name = button.attr('name'), data = name ? {name:name, value:button.val()} : null;
|
127
|
+
button.closest('form').data('ujs:submit-button', data);
|
128
|
+
});
|
129
|
+
|
130
|
+
$('form').live('ajax:beforeSend.rails', function(event) {
|
131
|
+
if (this == event.target) disableFormElements($(this));
|
132
|
+
});
|
133
|
+
|
134
|
+
$('form').live('ajax:complete.rails', function(event) {
|
135
|
+
if (this == event.target) enableFormElements($(this));
|
136
|
+
});
|
137
|
+
})( jQuery );
|
@@ -30,7 +30,7 @@ module Rails3JQueryAutocomplete
|
|
30
30
|
if term && !term.empty?
|
31
31
|
#allow specifying fully qualified class name for model object
|
32
32
|
class_name = options[:class_name] || object
|
33
|
-
items =
|
33
|
+
items = get_autocomplete_items(:model => get_object(class_name), \
|
34
34
|
:options => options, :term => term, :method => method)
|
35
35
|
else
|
36
36
|
items = {}
|
@@ -51,6 +51,6 @@ end
|
|
51
51
|
|
52
52
|
class ActionView::Helpers::FormBuilder #:nodoc:
|
53
53
|
def autocomplete_field(method, source, options = {})
|
54
|
-
@template.autocomplete_field(@object_name, method, source, options)
|
54
|
+
@template.autocomplete_field(@object_name, method, source, objectify_options(options))
|
55
55
|
end
|
56
56
|
end
|
@@ -3,7 +3,10 @@ module Rails3JQueryAutocomplete
|
|
3
3
|
# Contains utility methods used by autocomplete
|
4
4
|
module Helpers
|
5
5
|
|
6
|
-
#
|
6
|
+
#
|
7
|
+
# Returns a three keys hash actually used by the Autocomplete jQuery-ui
|
8
|
+
# Can be overriden to show whatever you like
|
9
|
+
#
|
7
10
|
def json_for_autocomplete(items, method)
|
8
11
|
items.collect {|item| {"id" => item.id, "label" => item.send(method), "value" => item.send(method)}}
|
9
12
|
end
|
@@ -12,6 +15,7 @@ module Rails3JQueryAutocomplete
|
|
12
15
|
#
|
13
16
|
# get_object(:actor)
|
14
17
|
# # returns a Actor constant supposing it is already defined
|
18
|
+
#
|
15
19
|
def get_object(model_sym)
|
16
20
|
object = model_sym.to_s.camelize.constantize
|
17
21
|
end
|
@@ -29,14 +33,20 @@ module Rails3JQueryAutocomplete
|
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
32
|
-
#
|
36
|
+
#DEPRECATED
|
33
37
|
def get_order(implementation, method, options)
|
38
|
+
warn 'Rails3JQueryAutocomplete#get_order is has been DEPRECATED, please use #get_autocomplete_order instead'
|
39
|
+
get_autocomplete_order(implementation, method, options)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns the order parameter to be used in the query created by get_items
|
43
|
+
def get_autocomplete_order(implementation, method, options)
|
34
44
|
order = options[:order]
|
35
45
|
|
36
46
|
case implementation
|
37
47
|
when :mongoid then
|
38
48
|
if order
|
39
|
-
order.split(',').collect do |fields|
|
49
|
+
order.split(',').collect do |fields|
|
40
50
|
sfields = fields.split
|
41
51
|
[sfields[0].downcase.to_sym, sfields[1].downcase.to_sym]
|
42
52
|
end
|
@@ -48,25 +58,39 @@ module Rails3JQueryAutocomplete
|
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
51
|
-
#
|
61
|
+
# DEPRECATED
|
52
62
|
def get_limit(options)
|
63
|
+
warn 'Rails3JQueryAutocomplete#get_limit is has been DEPRECATED, please use #get_autocomplete_limit instead'
|
64
|
+
get_autocomplete_limit(options)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns a limit that will be used on the query
|
68
|
+
def get_autocomplete_limit(options)
|
53
69
|
options[:limit] ||= 10
|
54
70
|
end
|
55
|
-
|
56
|
-
#
|
57
|
-
#
|
58
|
-
# items = get_items(:model => get_object(object), :options => options, :term => term, :method => method)
|
71
|
+
|
72
|
+
# DEPRECATED
|
59
73
|
def get_items(parameters)
|
74
|
+
warn 'Rails3JQueryAutocomplete#get_items is has been DEPRECATED, you should use #get_autocomplete_items instead'
|
75
|
+
get_autocomplete_items(parameters)
|
76
|
+
end
|
60
77
|
|
78
|
+
#
|
79
|
+
# Can be overriden to return or filter however you like
|
80
|
+
# the objects to be shown by autocomplete
|
81
|
+
#
|
82
|
+
# items = get_autocomplete_items(:model => get_object(object), :options => options, :term => term, :method => method)
|
83
|
+
#
|
84
|
+
def get_autocomplete_items(parameters)
|
61
85
|
model = parameters[:model]
|
62
86
|
method = parameters[:method]
|
63
87
|
options = parameters[:options]
|
64
88
|
term = parameters[:term]
|
65
89
|
is_full_search = options[:full]
|
66
90
|
|
67
|
-
limit =
|
91
|
+
limit = get_autocomplete_limit(options)
|
68
92
|
implementation = get_implementation(model)
|
69
|
-
order =
|
93
|
+
order = get_autocomplete_order(implementation, method, options)
|
70
94
|
|
71
95
|
case implementation
|
72
96
|
when :mongoid
|
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 3
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 2
|
10
|
+
version: 0.6.2
|
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:
|
18
|
+
date: 2011-02-12 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- integration/app/controllers/autocomplete_controller.rb
|
136
136
|
- integration/app/controllers/id_elements_controller.rb
|
137
137
|
- integration/app/controllers/multiple_selections_controller.rb
|
138
|
+
- integration/app/controllers/nested_models_controller.rb
|
138
139
|
- integration/app/controllers/sub_classes_controller.rb
|
139
140
|
- integration/app/helpers/application_helper.rb
|
140
141
|
- integration/app/helpers/autocomplete_helper.rb
|
@@ -143,12 +144,14 @@ files:
|
|
143
144
|
- integration/app/helpers/layout_helper.rb
|
144
145
|
- integration/app/helpers/sub_classes_helper.rb
|
145
146
|
- integration/app/models/brand.rb
|
147
|
+
- integration/app/models/feature.rb
|
146
148
|
- integration/app/models/foreign_brand.rb
|
147
149
|
- integration/app/models/product.rb
|
148
150
|
- integration/app/views/autocomplete/new.html.haml
|
149
151
|
- integration/app/views/id_elements/new.html.haml
|
150
152
|
- integration/app/views/layouts/application.html.haml
|
151
153
|
- integration/app/views/multiple_selections/new.html.haml
|
154
|
+
- integration/app/views/nested_models/new.html.haml
|
152
155
|
- integration/app/views/sub_classes/new.html.haml
|
153
156
|
- integration/config.ru
|
154
157
|
- integration/config/application.rb
|
@@ -169,6 +172,7 @@ files:
|
|
169
172
|
- integration/db/migrate/20101209014338_create_brands.rb
|
170
173
|
- integration/db/migrate/20101209014355_create_products.rb
|
171
174
|
- integration/db/migrate/20101209053936_add_type_to_brand.rb
|
175
|
+
- integration/db/migrate/20110209020136_create_features.rb
|
172
176
|
- integration/db/schema.rb
|
173
177
|
- integration/db/seeds.rb
|
174
178
|
- integration/doc/README_FOR_APP
|
@@ -187,7 +191,6 @@ files:
|
|
187
191
|
- integration/public/images/rails.png
|
188
192
|
- integration/public/javascripts/application.js
|
189
193
|
- integration/public/javascripts/autocomplete-rails.js
|
190
|
-
- integration/public/javascripts/jquery-ui.js
|
191
194
|
- integration/public/javascripts/jquery-ui.min.js
|
192
195
|
- integration/public/javascripts/jquery.js
|
193
196
|
- integration/public/javascripts/jquery.min.js
|
@@ -246,7 +249,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
246
249
|
requirements: []
|
247
250
|
|
248
251
|
rubyforge_project:
|
249
|
-
rubygems_version: 1.
|
252
|
+
rubygems_version: 1.4.1
|
250
253
|
signing_key:
|
251
254
|
specification_version: 3
|
252
255
|
summary: Use jQuery's autocomplete plugin with Rails 3.
|