-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
123 lines (101 loc) · 4.07 KB
/
index.html
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Simple widget embedded - Clicksign</title>
<script src="https://cdn-public-library.clicksign.com/embedded/embedded.min-1.0.0.js"></script>
<link href="./style.css" rel="stylesheet" />
</head>
<body>
<header class="settings closed">
<h2>⚙️ Configurações</h2>
<fieldset class="form">
<div class="field batch-key">
<label>Request Signature Key</label>
<input type="text" id="request_signature_key" value="" />
</div>
<div class="field enviroment">
<label>Environment</label>
<select id="request_enviroment">
<option value="http://127.0.0.1:3000">Local</option>
<option value="https://sandbox.clicksign.com">Sandbox</option>
<option value="https://app.clicksign.com">Produção</option>
<option value="https://vivo-sandbox.clicksign.com">Vivo Sandbox</option>
<option value="https://vivo.clicksign.com">Vivo Produção</option>
</select>
</div>
<div class="action">
<button id="setButton" type="submit" class="button" onclick="setWidget()">
Carregar
</button>
<button id="removeButton" class="button remove" type="submit" onclick="removeWidget()">
Remover
</button>
</div>
<div class="options">
<label for="redirect_option">
<input type="checkbox" id="redirect_option" /> Ativar redirecionamento ao assinar
</label>
</div>
</fieldset>
</header>
<main class="main">
<div class="loadingText" id="loading" style="display: none">Carregando...</div>
<div class="container" id="widget" style="display: none; height: 600px;"></div>
</main>
<script type="text/javascript">
let widget,
signature_request_key_element = document.getElementById('request_signature_key'),
environment_element = document.getElementById('request_enviroment'),
redirect_option_element = document.getElementById('redirect_option');
container_element = document.getElementById('widget');
loading_element = document.getElementById('loading');
const ENVIRONMENTS_COUNT = 20;
for (let index = 1; index <= ENVIRONMENTS_COUNT; index++) {
let option = document.createElement('option');
option.text = `Staging ${index}`;
option.value = `https://${index}.clicksign.dev`;
environment_element.appendChild(option);
}
function debugEvent(eventName, data) {
console.info(`Event: ${event.name || event}`);
if (event.data) console.table(event.data);
}
function setWidget() {
let request_signature_key = signature_request_key_element.value;
try {
if (widget) widget.unmount();
widget = new Clicksign(request_signature_key);
widget.endpoint = environment_element.value;
widget.origin = window.origin;
widget.mount('widget');
container_element.style.display = 'none';
loading_element.style.display = 'block';
} catch (error) {
console.log('error:', error);
} finally {
loading_element.style.display = 'none';
}
widget.on('loaded', function(event) {
debugEvent('loaded');
container_element.style.display = 'block';
});
widget.on('signed', function(event) {
debugEvent('signed');
if (redirect_option_element.checked) window.location.assign('https://clicksign.com');
});
widget.on('resized', function(event) {
debugEvent({ name: 'resized', height: event });
container_element.style.height = event + 'px';
});
widget.on('error', function(event) {
debugEvent('error');
container_element.style.display = 'block';
});
}
function removeWidget() {
if (widget) widget.unmount();
}
</script>
</body>
</html>