-
Notifications
You must be signed in to change notification settings - Fork 9
/
demo.js
30 lines (23 loc) · 1019 Bytes
/
demo.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
window.NIMIQ_IDENTICONS_SVG_PATH = location.pathname.replace(/[^/]*$/, 'dist/identicons.min.svg');
import Identicons from './src/js/identicons.js';
import { name } from './src/js/name.js';
window.Identicons = Identicons;
function renderIdenticons(text) {
document.querySelectorAll('.identicons:not(.small)').forEach((e, i) => Identicons.render(text + (i === 0 ? '' : i), e));
// for testing render the small identicons as image
document.querySelectorAll('.identicons.small').forEach((e, i) => Identicons.image(text + i)
.then($img => {
e.textContent = ''; // clear old content
e.appendChild($img);
}));
}
function renderWords(text) {
document.getElementById('words-text').innerText = text ? name(text) : '';
}
const firstText = '' + Date.now();
renderIdenticons(firstText);
renderWords(firstText);
document.querySelector('#text-input').addEventListener('input', event => {
renderIdenticons(event.target.value);
renderWords(event.target.value);
});