-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (68 loc) · 2.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
(function () {
function warn() {
if (window.console && window.console.warn) {
window.console.warn.apply(window.console, arguments)
}
}
if (window.nodeless) {
warn('index.js attempted to initialize more than once.')
return
}
var modal = document.createElement('div');
modal.id = 'nodeless-modal';
modal.style.position = 'fixed';
modal.style.top = '0';
modal.style.left = '0';
modal.style.width = '100vw';
modal.style.height = '100vh';
modal.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
modal.style.display = 'none';
modal.style.justifyContent = 'center';
modal.style.alignItems = 'center';
modal.style.zIndex = '9999';
var iframe = document.createElement('iframe');
iframe.name = 'nodeless'
iframe.class = 'nodeless'
iframe.style.border = 0
iframe.style.position = 'absolute'
iframe.style.top = '50%'
iframe.style.left = '50%'
iframe.style.height = '80%'
iframe.style.maxWidth = '500px'
iframe.style.width = '100%'
iframe.style.zIndex = '2000'
iframe.style.transform = 'translate(-50%, -50%)'
iframe.style.borderRadius = '10px'
var close = document.createElement('span');
close.id = 'close';
close.innerHTML = '×';
close.style.position = 'absolute';
close.style.top = '10px';
close.style.right = '20px';
close.style.cursor = 'pointer';
close.style.color = 'white'
close.style.fontSize = '30px'
modal.appendChild(iframe);
modal.appendChild(close);
function showFrame(invoiceId) {
if (window.document.getElementsByName('nodeless').length === 0) {
document.body.appendChild(modal);
}
iframe.src = `http://localhost/checkout/${invoiceId}`;
modal.style.display = 'flex';
}
function closeFrame() {
modal.style.display = 'none';
iframe = window.document.body.removeChild(iframe);
}
window.addEventListener('load', function load() {
window.removeEventListener('load', load);
});
close.addEventListener('click', function () {
closeFrame()
});
window.nodeless = {
showFrame: showFrame,
closeFrame: closeFrame
}
})()