Total Complexity | 10 |
Complexity/F | 1.67 |
Lines of Code | 49 |
Function Count | 6 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | /** |
||
5 | Amarkal.settings.search = { |
||
|
|||
6 | $fields: null, |
||
7 | $input: null, |
||
8 | init: function() { |
||
9 | var _this = this; |
||
10 | this.$fields = $('.amarkal-settings-field'); |
||
11 | this.$input = $('#settings-search'); |
||
12 | this.$input.on('keyup',function(){_this.onKeyup();}); |
||
13 | }, |
||
14 | onKeyup: function(e) { |
||
15 | var query = this.$input.val().toLowerCase(), |
||
16 | $matches; |
||
17 | |||
18 | // The user's search query is longer than 1 character |
||
19 | if(query.length > 1) { |
||
20 | |||
21 | $matches = this.find(query); |
||
22 | |||
23 | this.$fields.hide(); |
||
24 | $matches.show(); |
||
25 | |||
26 | // Textual user feedback |
||
27 | $('#settings-search-results').text($matches.length ? $matches.length+' settings found' : 'Nothing found'); |
||
28 | } |
||
29 | |||
30 | // The user's search query is not longer than 1 character |
||
31 | else { |
||
32 | this.$fields.show(); |
||
33 | $('#settings-search-results').text(''); |
||
34 | } |
||
35 | }, |
||
36 | find: function(query) { |
||
37 | var matches = []; |
||
38 | |||
39 | this.$fields.each(function(){ |
||
40 | var $field = $(this), |
||
41 | title = $field.attr('data-title').toLowerCase(), |
||
42 | description = $field.find('.description').text(); |
||
43 | |||
44 | // Check query against the field's title |
||
45 | if(title.match(query) || description.match(query)){ |
||
46 | matches.push($field); |
||
47 | } |
||
48 | }); |
||
49 | |||
50 | // Convert the matches array to a jQuery |
||
51 | return $(matches).map(function(){return this.toArray();}); |
||
52 | } |
||
53 | }; |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.