Completed
Push — develop ( 7b16e5...b5dddc )
by Freddie
14:27
created

src/Domain/BoilerPlates/jQuery/main.js   A

Complexity

Total Complexity 26
Complexity/F 2.36

Size

Lines of Code 122
Function Count 11

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 76
c 0
b 0
f 0
dl 0
loc 122
rs 10
wmc 26
mnd 15
bc 15
fnc 11
bpm 1.3636
cpm 2.3636
noi 6

1 Function

Rating   Name   Duplication   Size   Complexity  
F main.js ➔ getCookie 0 19 26
1
jQuery(document).ready(function ($) {
2
    'use strict';
3
    if ($('.notification-list').length) {
4
        $('.notification-list').slimScroll({
5
            height: '100%'
6
        });
7
    }
8
    if ($('.menu-list').length) {
9
        $('.menu-list').slimScroll({
10
            height: '100%'
11
        });
12
    }
13
    if ($('.navbar-nav > .nav-item > a').length) {
14
        $('.navbar-nav > .nav-item > a').click(function (event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
15
            if ($(this).hasClass('active')) {
16
                $(this).removeClass('active');
17
                $(this).attr('aria-expanded', 'false');
18
19
                return;
20
            }
21
22
            $('.navbar-nav > .nav-item > a').each(function () {
23
                $(this).removeClass('active');
24
                $(this).attr('aria-expanded', 'false');
25
26
                const target = $(this).data('target');
27
28
                $(target).removeClass('show');
29
                $(target).attr('aria-expanded', 'false');
30
            })
31
32
            $(this).addClass('active');
33
            $(this).attr('aria-expanded', 'true');
34
        });
35
    }
36
    if ($('.sidebar-nav-fixed a').length) {
37
        $('.sidebar-nav-fixed a').click(function (event) {
38
            if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
39
                && location.hostname == this.hostname
40
            ) {
41
                var target = $(this.hash);
42
                target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
43
                if (target.length) {
44
                    event.preventDefault();
45
                    $('html, body').animate({
46
                        scrollTop: target.offset().top - 90
47
                    }, 1000, function () {
48
                        var $target = $(target);
49
                        $target.focus();
50
                        if ($target.is(':focus')) {
51
                            return false;
52
                        } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
53
                            $target.attr('tabindex', '-1');
54
                            $target.focus();
55
                        };
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
56
                    });
57
                }
58
            };
59
60
            $('.sidebar-nav-fixed a').each(function () {
61
                $(this).removeClass('active');
62
            })
63
64
            $(this).addClass('active');
65
        });
66
    }
67
68
    if ($('[data-toggle="tooltip"]').length) {
69
        $('[data-toggle="tooltip"]').tooltip()
70
    }
71
72
    if ($('[data-toggle="popover"]').length) {
73
        $('[data-toggle="popover"]').popover()
74
    }
75
76
    $(document).on('submit', 'form[data-confirmation]', function (event) {
77
        var $form = $(this),
78
            $confirm = $('#confirmationModal');
79
80
        if ($confirm.data('result') !== 'yes') {
81
            //cancel submit event
82
            event.preventDefault();
83
84
            $confirm
85
                .off('click', '#btnYes')
86
                .on('click', '#btnYes', function () {
87
                    $confirm.data('result', 'yes');
88
                    $form.find('input[type="submit"]').attr('disabled', 'disabled');
89
                    $form.submit();
90
                })
91
                .modal('show');
92
        }
93
    });
94
95
    $(document).on('submit', 'form:not([data-confirmation])', function (event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
96
        $('.overlay').show();
97
    });
98
99
    $(document).on('click', '.show-overlay', function (event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
100
        $('.overlay').show();
101
    });
102
});
103
104
function getCookie(cname)
105
{
106
    const name = cname + "=";
107
    const ca = document.cookie.split(';');
108
109
    for (let i = 0; i < ca.length; i++) {
110
        let c = ca[i];
111
112
        while (c.charAt(0) == ' ') {
113
            c = c.substring(1);
114
        }
115
116
        if (c.indexOf(name) == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing c.indexOf(name) to 0 using the == operator is not safe. Consider using === instead.
Loading history...
117
            return c.substring(name.length, c.length);
118
        }
119
    }
120
121
    return '';
122
}
123