src/js/components/tabs.js   A
last analyzed

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A Mivhak.component(ꞌtabsꞌ).created 0 12 1
A Mivhak.component(ꞌtabsꞌ).methods.showTab 0 10 1
1
Mivhak.component('tabs', {
0 ignored issues
show
Bug introduced by
The variable Mivhak seems to be never declared. If this is a global, consider adding a /** global: Mivhak */ 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
    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',{
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable Mivhak seems to be never declared. If this is a global, consider adding a /** global: Mivhak */ 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...
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();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
29
            });
30
        }
31
    }
32
});