Completed
Push — master ( bc1ad9...b87221 )
by Askupa
01:45
created

assets/js/src/sections.js   A

Complexity

Total Complexity 13
Complexity/F 1.44

Size

Lines of Code 60
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 2
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 13
mnd 1
bc 14
fnc 9
bpm 1.5555
cpm 1.4443
noi 3

7 Functions

Rating   Name   Duplication   Size   Complexity  
A Amarkal.settings.sections.init 0 7 1
A Amarkal.settings.sections.getSubtitle 0 3 1
A Amarkal.settings.sections.activate 0 16 1
A Amarkal.settings.sections.initSections 0 12 3
A Amarkal.settings.sections.getTitle 0 3 1
A Amarkal.settings.sections.activateInitialSection 0 8 2
A Amarkal.settings.sections.deactivate 0 5 1
1
Amarkal.settings.sections = {
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
    $links: null,
4
    sections: null,
5
    activeSection: null,
6
    init: function() {
7
        this.sections = JSON.parse($('#sections-config').text());
8
        this.$fields = $('.amarkal-settings-field');
9
        this.$links = $('.amarkal-settings-sections li');
10
11
        this.initSections();
12
    },
13
    initSections: function() {
14
        if(typeof this.sections === 'object' && Object.keys(this.sections).length > 1) {
15
            var _this = this;
16
            this.$links.on('click', function(){
17
                _this.activate($(this).attr('data-slug'));
18
            });
19
            this.activateInitialSection();
20
        }
21
        else {
22
            this.$fields.addClass('visible');
23
        }
24
    },
25
    activateInitialSection: function() {
26
        if('' !== window.location.hash) {
27
            this.activate(window.location.hash.substring(1));
28
        }
29
        else {
30
            this.activate($(this.$links[0]).attr('data-slug'));
31
        }
32
    },
33
    activate: function(sectionSlug) {
34
        this.$links.each(function(){
35
            $(this).removeClass('active');
36
            if($(this).attr('data-slug') === sectionSlug) {
37
                $(this).addClass('active');
38
            }
39
        });
40
41
        this.$fields.removeClass('visible');
42
        Amarkal.settings.header.setSectionTitle(this.getTitle(sectionSlug));
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...
43
        Amarkal.settings.header.setSectionSubtitle(this.getSubtitle(sectionSlug));
44
        this.activeSection = sectionSlug;
45
46
        $('.amarkal-settings-field[data-section="'+sectionSlug+'"]').addClass('visible');
47
        window.location = '#'+sectionSlug;
48
    },
49
    deactivate: function() {
50
        var sectionSlug = this.activeSection;
0 ignored issues
show
Unused Code introduced by
The variable sectionSlug seems to be never used. Consider removing it.
Loading history...
51
        this.$links.removeClass('active');
52
        this.$fields.removeClass('visible');
53
    },
54
    getTitle: function(slug) {
55
        return this.sections[slug].title;
56
    },
57
    getSubtitle: function(slug) {
58
        return this.sections[slug].subtitle;
59
    }
60
};