Issues (11)

utils/index.js (1 issue)

1
2
3
'use strict';
4
5
function isEmpty(x) {
6
    return (
7
        typeof x === 'undefined' ||
8
        x === null ||
9
        x === 'null' ||
10
        x === 'undefined' ||
11
        x === false ||
12
        x.length === 0 ||
13
        x === ''||
14
        (x === "object" && Object.key(x).length === 0) ||
15
        (x && Object.keys(x).length === 0
16
        && Object.getPrototypeOf(x) === Object.prototype)
17
    );
18
}
19
20
function isJson(str) {
21
    try {
22
      str=JSON.parse(str);
0 ignored issues
show
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...
23
    } catch (e) {
24
        return str;
25
    }
26
}
27
28
function checkEmptyHtml(id, checkChildNode = false) {
29
    const elem = document.querySelector(`${id}`);
30
    if (elem === null || elem === undefined) {
31
        return true;
32
    } else if (elem && elem.childNodes.length > 0 && checkChildNode) {
33
        return true;
34
    }
35
    return false;
36
}
37
38
function prepareFrame(checkout_url) {
39
    const ifrm = document.createElement("iframe");
40
    let url = new URL(checkout_url);
41
42
    ifrm.setAttribute("src", url.href);
43
    ifrm.setAttribute("id", 'bSecurePaymentPluginEmbeddedIframe');
44
    ifrm.setAttribute("name", 'bSecurePaymentPluginEmbeddedIframe');
45
    ifrm.style.position = "absolute";
46
    ifrm.style.border = "none";
47
    ifrm.style.top = "0";
48
    ifrm.style.left = "0";
49
    ifrm.style.width = "100%";
50
    ifrm.style.height = "100%";
51
    document.getElementById("bSecurePaymentPluginContainer").appendChild(ifrm);
52
}
53
54
55
function resetFrame() {
56
    document.getElementById("bSecurePaymentPluginContainer").remove();
57
}
58
59
module.exports = {
60
    isEmpty: isEmpty,
61
    isJson: isJson,
62
    checkEmptyHtml: checkEmptyHtml,
63
    prepareFrame: prepareFrame,
64
    resetFrame: resetFrame,
65
};