forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnsRecordHint.js
More file actions
49 lines (39 loc) · 1.08 KB
/
dnsRecordHint.js
File metadata and controls
49 lines (39 loc) · 1.08 KB
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
import { debounce } from './helpers';
// Attach listener to DNS "Record" field to update its hint
export default function handleDnsRecordHint() {
const recordInput = document.querySelector('.js-dns-record-input');
if (!recordInput) {
return;
}
if (recordInput.value.trim() !== '') {
updateHint(recordInput);
}
recordInput.addEventListener(
'input',
debounce((evt) => updateHint(evt.target)),
);
}
// Update DNS "Record" field hint
function updateHint(input) {
const domainInput = document.querySelector('.js-dns-record-domain');
const hintElement = input.parentElement.querySelector('.hint');
let hint = input.value.trim();
// Clear the hint if input is empty
if (hint === '') {
hintElement.textContent = '';
return;
}
// Set domain name without rec in case of @ entries
if (hint === '@') {
hint = '';
}
// Don't show prefix if domain name equals rec value
if (hint === domainInput.value) {
hint = '';
}
// Add dot at the end if needed
if (hint !== '' && hint.slice(-1) !== '.') {
hint += '.';
}
hintElement.textContent = hint + domainInput.value;
}