Test Setup Failed
Branch master (354693)
by Valery
10:57
created

assets/js/page.js   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 36
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 36
rs 10
wmc 5
mnd 2
bc 2
fnc 3
bpm 0.6666
cpm 1.6666
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A page.js ➔ updateDisplay 0 12 5
1
'use strict';
2
3
$(document).ready(function () {
4
5
    let $checkbox = $('#page_add_contact_form');
6
    let $emailContainer = $('#email-address');
7
    let $emailField = $('#page_contact_email_address');
8
9
10
    if ($checkbox.attr("checked") === 'checked') {
11
        $emailContainer.slideDown();
12
        $emailField.prop('required', true);
13
    }
14
15
    // Event Handler
16
    $checkbox.on('change', function () {
17
18
        updateDisplay();
19
    });
20
21
    // Action
22
23
    function updateDisplay() {
24
25
        let isChecked = $checkbox.is(':checked');
26
27
        if (isChecked) {
28
            $emailContainer.slideDown();
29
            $emailField.focus().prop('required', true);
30
        } else {
31
            $emailContainer.slideUp();
32
            $emailField.prop('required', false);
33
        }
34
    }
35
36
});
37