Passed
Push — trunk ( 08307f...9f0935 )
by Christian
14:31 queued 12s
created

BootstrapUtil   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 43
rs 10
wmc 6

3 Functions

Rating   Name   Duplication   Size   Complexity  
A initPopover 0 14 2
A initBootstrapPlugins 0 4 1
A initTooltip 0 12 3
1
import Feature from 'src/helper/feature.helper';
2
3
/**
4
 * @deprecated tag:v6.5.0 - The bootstrap `data-toggle` attribute will be renamed to `data-bs-toggle`
5
 * @see https://getbootstrap.com/docs/5.0/migration/#javascript
6
 * @type {string}
7
 */
8
const BS_TOGGLE_ATTR = Feature.isActive('v6.5.0.0') ? 'data-bs-toggle' : 'data-toggle';
9
10
const TOOLTIP_SELECTOR = `[${BS_TOGGLE_ATTR}="tooltip"]`;
11
const POPOVER_SELECTOR = `[${BS_TOGGLE_ATTR}="popover"]`;
12
13
export default class BootstrapUtil {
14
15
    /**
16
     * Initialize Tooltip plugin everywhere
17
     * @see https://getbootstrap.com/docs/4.3/components/tooltips/#example-enable-tooltips-everywhere
18
     */
19
    static initTooltip() {
20
        /** @deprecated tag:v6.5.0 - Bootstrap v5 uses native elements to init Tooltip plugin */
21
        if (Feature.isActive('v6.5.0.0')) {
22
            return new bootstrap.Tooltip(document.body, {
0 ignored issues
show
Bug introduced by
The variable bootstrap seems to be never declared. If this is a global, consider adding a /** global: bootstrap */ 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...
23
                selector: TOOLTIP_SELECTOR,
24
            });
25
        } 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...
26
            $('body').tooltip({
27
                selector: TOOLTIP_SELECTOR,
28
            });
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...
29
        }
30
    }
31
32
    /**
33
     * Initialize Popover plugin everywhere
34
     * @see https://getbootstrap.com/docs/4.3/components/popovers/#example-enable-popovers-everywhere
35
     */
36
    static initPopover() {
37
        /** @deprecated tag:v6.5.0 - Bootstrap v5 uses native elements to init Popover plugin */
38
        if (Feature.isActive('v6.5.0.0')) {
39
            new bootstrap.Popover(document.body, {
0 ignored issues
show
Bug introduced by
The variable bootstrap seems to be never declared. If this is a global, consider adding a /** global: bootstrap */ 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...
Unused Code Best Practice introduced by
The object created with new bootstrap.Popover(do...ngLiteralNode(focus))}) is not used but discarded. Consider invoking another function instead of a constructor if you are doing this purely for side effects.
Loading history...
40
                selector: POPOVER_SELECTOR,
41
                trigger: 'focus',
42
            });
43
        } else {
44
            $('body').popover({
45
                selector: POPOVER_SELECTOR,
46
                trigger: 'focus',
47
            });
48
        }
49
    }
50
51
    static initBootstrapPlugins() {
52
        this.initTooltip();
53
        this.initPopover();
54
    }
55
}
56