Passed
Branch master (32b4c5)
by Askupa
01:33
created

src/js/components/top-bar-button.js   A

Complexity

Total Complexity 10
Complexity/F 1.25

Size

Lines of Code 42
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 42
rs 10
wmc 10
mnd 1
bc 9
fnc 8
bpm 1.125
cpm 1.25
noi 3
1
Mivhak.component('top-bar-button', {
2
    template: '<div class="mivhak-top-bar-button"></div>',
3
    props: {
4
        text: null,
5
        icon: null,
6
        dropdown: null,
7
        mivhakInstance: null,
8
        onClick: function(){}
9
    },
10
    events: {
11
        click: function() {
12
            this.onClick();
13
        }
14
    },
15
    created: function() {
16
        var $this = this;
17
        this.$el.text(this.text);
18
        if(this.icon) this.$el.addClass('mivhak-icon mivhak-icon-'+this.icon).append($(Mivhak.icons[this.icon]));
19
        if(this.dropdown) 
20
        {
21
            $this.$el.append(this.dropdown.$el);
22
            this.onClick = function() {
23
                $this.toggleActivation();
24
                $this.dropdown.toggle();
25
            };
26
        }
27
    },
28
    methods: {
29
        activate: function() {
30
            this.$el.addClass('mivhak-button-active');
31
        },
32
        deactivate: function() {
33
            this.$el.removeClass('mivhak-button-active');
34
        },
35
        toggleActivation: function() {
36
            this.$el.toggleClass('mivhak-button-active');
37
        },
38
        isActive: function() {
39
            return this.$el.hasClass('mivhak-button-active');
40
        }
41
    }
42
});