Completed
Push — master ( dc838b...dfb2bc )
by Askupa
01:34
created

assets/js/src/fields.js   A

Complexity

Total Complexity 13
Complexity/F 1.3

Size

Lines of Code 46
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 0
c 1
b 0
f 1
nc 3
dl 0
loc 46
rs 10
wmc 13
mnd 1
bc 11
fnc 10
bpm 1.1
cpm 1.3
noi 2

8 Functions

Rating   Name   Duplication   Size   Complexity  
A Amarkal.settings.fields.showBySection 0 4 1
A Amarkal.settings.fields.flag 0 3 1
A Amarkal.settings.fields.hide 0 3 1
A Amarkal.settings.fields.init 0 3 1
A Amarkal.settings.fields.showAll 0 3 1
A Amarkal.settings.fields.show 0 6 1
A Amarkal.settings.fields.search 0 18 1
A Amarkal.settings.fields.hideAll 0 3 1
1
Amarkal.settings.fields = {
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...
2
    $fields: null,
3
    init: function () {
4
        this.$fields = $('.amarkal-settings-field');
5
    },
6
    hideAll: function () {
7
        this.hide(this.$fields);
8
    },
9
    showAll: function () {
10
        this.show(this.$fields);
11
    },
12
    showBySection: function (slug) {
13
        this.hideAll();
14
        this.show(this.$fields.filter('[data-section="'+slug+'"]'));
15
    },
16
    search: function(query) {
17
        var matches  = [];
18
        
19
        this.$fields.each(function(){
20
            var $field = $(this),
21
                title  = $field.find('h3').text().toLowerCase(),
22
                help = $field.find('.help-content').text();
23
                description = $field.find('.description').text();
0 ignored issues
show
Bug introduced by
The variable description seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.description.
Loading history...
24
25
            // Check query against the field's title
26
            if(title.match(query) || description.match(query) || help.match(query)) {
27
                matches.push($field);
28
            }
29
        });
30
31
        // Convert the matches array to a jQuery object
32
        return $(matches).map(function(){return this.toArray();});
33
    },
34
    show: function($fields) {
35
        $fields
36
            .addClass('visible')
37
            .find('.amarkal-ui-component')
38
            .amarkalUIComponent('refresh');
39
    },
40
    hide: function($fields) {
41
        $fields.removeClass('visible');
42
    },
43
    flag: function(type, fieldName) {
44
        this.$fields.filter('[data-name="'+fieldName+'"]').addClass('flag-'+type);
45
    }
46
};