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

Complexity

Total Complexity 12
Complexity/F 1.33

Size

Lines of Code 66
Function Count 9

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 66
rs 10
wmc 12
mnd 1
bc 9
fnc 9
bpm 1
cpm 1.3333
noi 4

5 Functions

Rating   Name   Duplication   Size   Complexity  
A Mivhak.component(ꞌnotifierꞌ).methods.dismissibleNotification 0 10 1
A Mivhak.component(ꞌnotifierꞌ).methods.timedNotification 0 7 1
A Mivhak.component(ꞌnotifierꞌ).methods.hide 0 4 1
A Mivhak.component(ꞌnotifierꞌ).methods.callbackNotification 0 9 1
A Mivhak.component(ꞌnotifierꞌ).methods.notification 0 6 2
1
Mivhak.component('notifier', {
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-notifier"></div>',
3
    methods: {
4
        /**
5
         * Internally used to show a notification
6
         * @param {String} html
7
         */
8
        notification: function(html) {
9
            if(!html) return;
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...
10
            clearTimeout(this.timeout);
11
            this.$el.html(html);
12
            this.$el.addClass('mivhak-visible');
13
        },
14
        
15
        /**
16
         * Show a notification that will be automatically dismissed after the 
17
         * given timeout has passed
18
         * 
19
         * @param {String} html
20
         * @param {Number} timeout
21
         */
22
        timedNotification: function(html, timeout) {
23
            var $this = this;
24
            this.notification(html);
25
            this.timeout = setTimeout(function(){
26
                $this.hide();
27
            },timeout);
28
        },
29
        
30
        /**
31
         * Show a notification that can be dismissed by clicking on the X button
32
         * @param {String} html
33
         * @param {Function} onclick
34
         */
35
        dismissibleNotification: function(html, onclick)
36
        {
37
            var $this = this,
38
                $times = $('<div>',{class:'mivhak-times',html:'&#215;'}).click(function(){$this.hide();});
39
            this.notification(html);
40
            this.$el.append($times).addClass('mivhak-dismissible').click(function(e){
41
                if(typeof onclick !== 'undefined')
42
                    onclick.call(null, e);
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...
43
            });
44
        },
45
        
46
        /**
47
         * Show a notification that will execute a callback once clicked
48
         * @param {String} html
49
         * @param {Function} onclick
50
         */
51
        callbackNotification: function(html, onclick)
52
        {
53
            var $this = this;
54
            this.notification(html);
55
            this.$el.addClass('mivhak-button').click(function(e){
56
                if(typeof onclick !== 'undefined')
57
                    onclick.call($this, e);
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...
58
            });
59
        },
60
        
61
        hide: function() {
62
            this.$el.removeClass('mivhak-visible mivhak-button mivhak-dismissible');
63
            this.$el.off('click');
64
        }
65
    }
66
});