Total Complexity | 8 |
Complexity/F | 1.6 |
Lines of Code | 60 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | |||
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 | ); |
||
15 | } |
||
16 | |||
17 | function isJson(str) { |
||
18 | try { |
||
19 | str=JSON.parse(str); |
||
|
|||
20 | } catch (e) { |
||
21 | return str; |
||
22 | } |
||
23 | } |
||
24 | |||
25 | function checkEmptyHtml(id, checkChildNode = false) { |
||
26 | const elem = document.querySelector(`${id}`); |
||
27 | if (elem === null || elem === undefined) { |
||
28 | return true; |
||
29 | } else if (elem && elem.childNodes.length > 0 && checkChildNode) { |
||
30 | return true; |
||
31 | } |
||
32 | return false; |
||
33 | } |
||
34 | |||
35 | function prepareFrame(id = "bSecurePaymentPluginContainer", checkout_url) { |
||
36 | const ifrm = document.createElement("iframe"); |
||
37 | let url = new URL(checkout_url); |
||
38 | |||
39 | ifrm.setAttribute("src", url.href); |
||
40 | ifrm.setAttribute("id", 'bSecurePaymentPluginEmbeddedIframe'); |
||
41 | ifrm.setAttribute("name", 'bSecurePaymentPluginEmbeddedIframe'); |
||
42 | ifrm.style.position = "absolute"; |
||
43 | ifrm.style.border = "none"; |
||
44 | ifrm.style.top = "0"; |
||
45 | ifrm.style.left = "0"; |
||
46 | ifrm.style.width = "100%"; |
||
47 | ifrm.style.height = "100%"; |
||
48 | document.getElementById(id).appendChild(ifrm); |
||
49 | } |
||
50 | |||
51 | |||
52 | function resetFrame(id = "bSecurePaymentPluginContainer") { |
||
53 | document.getElementById(id).remove(); |
||
54 | } |
||
55 | |||
56 | module.exports = { |
||
57 | isEmpty: isEmpty, |
||
58 | isJson: isJson, |
||
59 | checkEmptyHtml: checkEmptyHtml, |
||
60 | prepareFrame: prepareFrame, |
||
61 | resetFrame: resetFrame, |
||
62 | }; |