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

src/js/components/tabs.js   A

Complexity

Total Complexity 6
Complexity/F 1.5

Size

Lines of Code 32
Function Count 4

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 32
rs 10
wmc 6
mnd 1
bc 5
fnc 4
bpm 1.25
cpm 1.5
noi 4
1
Mivhak.component('tabs', {
2
    template: '<div class="mivhak-tabs"></div>',
3
    props: {
4
        mivhakInstance: null,
5
        activeTab: null,
6
        tabs: []
7
    },
8
    created: function() {
9
        var $this = this;
10
        this.$el = this.mivhakInstance.$selection.find('pre').wrapAll(this.$el).parent();
11
        $.each(this.mivhakInstance.resources.data,function(i, resource){
12
            if(resource.visible)
13
                $this.tabs.push(Mivhak.render('tab-pane',{
14
                    resource: resource,
15
                    index: i,
16
                    mivhakInstance: $this.mivhakInstance
17
                }));
18
        });
19
    },
20
    methods: {
21
        showTab: function(index){
22
            var $this = this;
23
            $.each(this.tabs, function(i, tab){
24
                if(index === i) {
25
                    $this.mivhakInstance.activeTab = tab;
26
                    tab.show();
27
                }
28
                else tab.hide();
29
            });
30
        }
31
    }
32
});