-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.js
109 lines (98 loc) · 3.44 KB
/
display.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
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
/**
* The MIT License (MIT)
*
* Copyright (c) 2023 Timothy Green
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
function calculate_iban(el) {
var val = el.value;
var note = document.getElementById('iban_valid');
var country = document.getElementById('iban_country');
var elementsDisplay = document.getElementById('iban_elements');
var display_style = document.querySelector('input[name=displaying]:checked').value;
el.className = 'neutral';
note.innerHTML = '';
country.innerHTML = '';
if (elementsDisplay) {
elementsDisplay.remove();
}
if (val.length > 5) {
var iban = val.toUpperCase();
var iban = iban.replace(/\s/g, '');
if (iban.length > 4) {
var resp = validateIban(iban);
var valid = resp[0];
var code = resp[1];
var name = resp[2];
var message = resp[3];
if (valid === false) {
el.className = 'invalid';
}
if (valid === true) {
el.className = 'valid';
var elements = resp[4];
if (display_style === 'table') {
elementsDisplay = document.createElement('table');
elementsDisplay.id = 'iban_elements';
elements.forEach(function(elm) {
var s = document.createElement('tr');
var l = document.createElement('th');
var v = document.createElement('td');
s.className = elm.type;
l.innerHTML = elm.label;
v.innerHTML = elm.value;
s.appendChild(l);
s.appendChild(v);
elementsDisplay.appendChild(s);
});
document.body.appendChild(elementsDisplay);
} else {
elementsDisplay = document.createElement('div');
elementsDisplay.id = 'iban_elements';
elements.forEach(function(elm) {
var s = document.createElement('span');
var l = document.createElement('span');
var v = document.createElement('span');
s.style.display = 'block';
s.className = elm.type;
l.style.fontWeight = 'bold';
l.innerHTML = elm.label + ':';
v.innerHTML = elm.value;
s.appendChild(l);
s.appendChild(v);
elementsDisplay.appendChild(s);
});
document.body.appendChild(elementsDisplay);
}
}
note.innerHTML = message;
country.innerHTML = name;
}
}
}
document.getElementById('iban_input').addEventListener('input', function() {
calculate_iban(this);
});
var displaying = document.qx.displaying;
displaying.forEach (display_option => {
display_option.addEventListener('change', function() {
var iban = document.getElementById('iban_input');
calculate_iban(iban);
});
});