Skip to content

Commit b7c7208

Browse files
committed
Merge branch 'master' of https://github.com/risuiowa/rails3-jquery-autocomplete into risuiowa-master
Resolve merge Conflicts. Conflicts: lib/assets/javascripts/autocomplete-rails-uncompressed.js lib/assets/javascripts/autocomplete-rails.js rails3-jquery-autocomplete.gemspec
2 parents 65b428a + dd05478 commit b7c7208

File tree

5 files changed

+110
-14
lines changed

5 files changed

+110
-14
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## MAC OS
66
.DS_Store
7+
.idea
78

89
## TEXTMATE
910
*.tmproj

.jshintrc

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
// JSHint Default Configuration File (as on JSHint website)
3+
// See http://jshint.com/docs/ for more details
4+
5+
"maxerr" : 50, // {int} Maximum error before stopping
6+
7+
// Enforcing
8+
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
9+
"camelcase" : false, // true: Identifiers must be in camelCase
10+
"curly" : true, // true: Require {} for every new block or scope
11+
"eqeqeq" : true, // true: Require triple equals (===) for comparison
12+
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
13+
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
14+
//"indent" : 4, // {int} Number of spaces to use for indentation
15+
"latedef" : false, // true: Require variables/functions to be defined before being used
16+
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
17+
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
18+
"noempty" : true, // true: Prohibit use of empty blocks
19+
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
20+
"plusplus" : false, // true: Prohibit use of `++` & `--`
21+
"quotmark" : false, // Quotation mark consistency:
22+
// false : do nothing (default)
23+
// true : ensure whatever is used is consistent
24+
// "single" : require single quotes
25+
// "double" : require double quotes
26+
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
27+
"unused" : true, // true: Require all defined variables be used
28+
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
29+
"trailing" : false, // true: Prohibit trailing whitespaces
30+
"maxparams" : false, // {int} Max number of formal params allowed per function
31+
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
32+
"maxstatements" : false, // {int} Max number statements per function
33+
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
34+
"maxlen" : false, // {int} Max number of characters per line
35+
36+
// Relaxing
37+
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
38+
"boss" : false, // true: Tolerate assignments where comparisons would be expected
39+
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
40+
"eqnull" : false, // true: Tolerate use of `== null`
41+
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
42+
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
43+
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
44+
// (ex: `for each`, multiple try/catch, function expression…)
45+
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
46+
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
47+
"funcscope" : false, // true: Tolerate defining variables inside control statements"
48+
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
49+
"iterator" : false, // true: Tolerate using the `__iterator__` property
50+
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
51+
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
52+
"laxcomma" : false, // true: Tolerate comma-first style coding
53+
"loopfunc" : false, // true: Tolerate functions being defined in loops
54+
"multistr" : false, // true: Tolerate multi-line strings
55+
"proto" : false, // true: Tolerate using the `__proto__` property
56+
"scripturl" : false, // true: Tolerate script-targeted URLs
57+
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
58+
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
59+
"sub" : true, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
60+
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
61+
"validthis" : false, // true: Tolerate using this in a non-constructor function
62+
63+
// Environments
64+
"browser" : true, // Web Browser (window, document, etc)
65+
"couch" : false, // CouchDB
66+
"devel" : true, // Development/debugging (alert, confirm, etc)
67+
"dojo" : false, // Dojo Toolkit
68+
"jquery" : true, // jQuery
69+
"mootools" : false, // MooTools
70+
"node" : false, // Node.js
71+
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
72+
"prototypejs" : false, // Prototype and Scriptaculous
73+
"rhino" : false, // Rhino
74+
"worker" : false, // Web Workers
75+
"wsh" : false, // Windows Scripting Host
76+
"yui" : false, // Yahoo User Interface
77+
78+
// Legacy
79+
"nomen" : false, // true: Prohibit dangling `_` in variables
80+
"onevar" : false, // true: Allow only one `var` statement per function
81+
"passfail" : false, // true: Stop on first error
82+
"white" : false, // true: Check against strict whitespace and indentation rules
83+
84+
// Custom Globals
85+
"globals" : {} // additional predefined global variables
86+
}

lib/assets/javascripts/autocomplete-rails-uncompressed.js

+21-12
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
};
3333

3434
jQuery.railsAutocomplete = function (e) {
35-
_e = e;
35+
var _e = e;
3636
this.init(_e);
3737
};
3838

@@ -58,40 +58,42 @@
5858
appendTo: e.append_to,
5959
autoFocus: e.autoFocus,
6060
source: function( request, response ) {
61-
params = {term: extractLast( request.term )}
61+
var firedFrom = this.element[0];
62+
var params = {term: extractLast( request.term )};
6263
if (jQuery(e).attr('data-autocomplete-fields')) {
6364
jQuery.each(jQuery.parseJSON(jQuery(e).attr('data-autocomplete-fields')), function(field, selector) {
6465
params[field] = jQuery(selector).val();
6566
});
6667
}
6768
jQuery.getJSON( jQuery(e).attr('data-autocomplete'), params, function() {
68-
if(arguments[0].length == 0) {
69-
arguments[0] = []
70-
arguments[0][0] = { id: "", label: "no existing match" }
69+
if(arguments[0].length === 0) {
70+
arguments[0] = [];
71+
arguments[0][0] = { id: "", label: "no existing match" };
7172
}
7273
jQuery(arguments[0]).each(function(i, el) {
7374
var obj = {};
7475
obj[el.id] = el;
7576
jQuery(e).data(obj);
7677
});
7778
response.apply(null, arguments);
79+
jQuery(firedFrom).trigger('railsAutocomplete.source', arguments);
7880
});
7981
},
8082
change: function( event, ui ) {
8183
if(!jQuery(this).is('[data-id-element]') ||
82-
jQuery(jQuery(this).attr('data-id-element')).val() == "") {
83-
return;
84-
}
84+
jQuery(jQuery(this).attr('data-id-element')).val() === "") {
85+
return;
86+
}
8587
jQuery(jQuery(this).attr('data-id-element')).val(ui.item ? ui.item.id : "");
8688

8789
if (jQuery(this).attr('data-update-elements')) {
8890
var update_elements = jQuery.parseJSON(jQuery(this).attr("data-update-elements"));
8991
var data = ui.item ? jQuery(this).data(ui.item.id.toString()) : {};
90-
if(update_elements && jQuery(update_elements['id']).val() == "") {
91-
return;
92+
if(update_elements && jQuery(update_elements['id']).val() === "") {
93+
return;
9294
}
9395
for (var key in update_elements) {
94-
element = jQuery(update_elements[key]);
96+
var element = jQuery(update_elements[key]);
9597
if (element.is(':checkbox')) {
9698
if (data[key] != null) {
9799
element.prop('checked', data[key]);
@@ -114,6 +116,10 @@
114116
return false;
115117
},
116118
select: function( event, ui ) {
119+
if(ui.item.value.toLowerCase().indexOf('no match') != -1 || ui.item.value.toLowerCase().indexOf('too many results') != -1){
120+
jQuery(this).trigger('railsAutocomplete.noMatch', ui);
121+
return false;
122+
}
117123
var terms = split( this.value );
118124
// remove the current input
119125
terms.pop();
@@ -132,7 +138,7 @@
132138
var data = jQuery(this).data(ui.item.id.toString());
133139
var update_elements = jQuery.parseJSON(jQuery(this).attr("data-update-elements"));
134140
for (var key in update_elements) {
135-
element = jQuery(update_elements[key]);
141+
var element = jQuery(update_elements[key]);
136142
if (element.is(':checkbox')) {
137143
if (data[key] != null) {
138144
element.prop('checked', data[key]);
@@ -141,6 +147,9 @@
141147
element.val(data[key]);
142148
}
143149
}
150+
if(jQuery(update_elements[key]).attr("type") === "checkbox"){
151+
jQuery(update_elements[key]).attr("checked","checked");
152+
}
144153
}
145154
}
146155
var remember_string = this.value;

lib/assets/javascripts/autocomplete-rails.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rails3-jquery-autocomplete.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
1313
s.description = %q{Use jQuery's autocomplete plugin with Rails 3.}
1414
s.license = %q{MIT}
1515

16-
s.add_dependency('rails', '>=3.0')
16+
s.add_dependency('rails', '>= 3.2')
1717

1818
s.add_development_dependency 'sqlite3-ruby'
1919
s.add_development_dependency 'mongoid', '>= 2.0.0'

0 commit comments

Comments
 (0)