assets/js/src/search.js   A
last analyzed

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 38
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 0
nc 2
dl 0
loc 38
rs 10
c 1
b 1
f 0
wmc 5
mnd 2
bc 5
fnc 2
bpm 2.5
cpm 2.5
noi 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
B Amarkal.settings.search.onKeyup 0 30 4
A Amarkal.settings.search.init 0 4 1
1
/**
2
 * The search class is used internally to search through the fields and find those
3
 * that match the user's query.
4
 */
5
Amarkal.settings.search = {
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

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.

Loading history...
6
    $input: null,
7
    activeSection: null,
8
    init: function() {
9
        this.$input = $('#settings-search');
10
        this.$input.on('keyup',this.onKeyup.bind(this));
11
    },
12
    onKeyup: function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
13
        var query = this.$input.val().toLowerCase().replace(/[^\w\d\s]/g,'');
14
            
15
        // The user's search query is longer than 0 characters
16
        if(query.length > 0) {
17
            
18
            var $matches = Amarkal.settings.fields.search(query);
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

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.

Loading history...
19
            
20
            // Store a copy of the active section before it is deactivated
21
            if(null === this.activeSection) {
22
                this.activeSection = Amarkal.settings.sections.activeSection;
23
            }
24
25
            Amarkal.settings.sections.deactivate();
26
            Amarkal.settings.header.setSectionTitle('Field Search Results');
27
            Amarkal.settings.header.setSectionSubtitle('');
28
            Amarkal.settings.fields.hideAll();
29
            Amarkal.settings.fields.show($matches);
30
31
            // Textual user feedback
32
            $('#settings-search-results').addClass('visible').text($matches.length ? $matches.length+' settings found' : 'Nothing found');
33
        }
34
35
        // The user's search query is not longer than 0 character
36
        else {
37
            $('#settings-search-results').removeClass('visible').text('');
38
            Amarkal.settings.sections.activate(this.activeSection);
39
            this.activeSection = null;
40
        }
41
    }
42
};