keyoxide-web/static/kx-key.js

57 lines
2.4 KiB
JavaScript
Raw Permalink Normal View History

class Key extends HTMLElement {
// Specify the attributes to observe
static get observedAttributes() {
return ['data-keydata'];
}
constructor() {
// Call super
super();
}
attributeChangedCallback(name, oldValue, newValue) {
this.updateContent(newValue);
}
updateContent(value) {
2021-05-04 05:57:33 -06:00
const root = this;
const data = JSON.parse(value);
2021-05-04 05:57:33 -06:00
root.querySelector('.info .subtitle').innerText = data.key.fetchMethod;
root.querySelector('.info .title').innerText = data.fingerprint;
2021-05-04 05:57:33 -06:00
const elContent = root.querySelector('.content');
elContent.innerHTML = ``;
// Link to key
2021-05-04 05:57:33 -06:00
const subsection_links = elContent.appendChild(document.createElement('div'));
subsection_links.setAttribute('class', 'subsection');
const subsection_links_icon = subsection_links.appendChild(document.createElement('img'));
subsection_links_icon.setAttribute('src', '/static/img/link.png');
2021-06-07 06:15:32 -06:00
subsection_links_icon.setAttribute('alt', '');
subsection_links_icon.setAttribute('aria-hidden', 'true');
2021-05-04 05:57:33 -06:00
const subsection_links_text = subsection_links.appendChild(document.createElement('div'));
2021-05-04 05:57:33 -06:00
const profile_link = subsection_links_text.appendChild(document.createElement('p'));
2021-06-09 05:58:36 -06:00
profile_link.innerHTML = `Key link: <a href="${data.key.uri}" aria-label="Link to cryptographic key">${data.key.uri}</a>`;
2021-05-03 04:06:37 -06:00
elContent.appendChild(document.createElement('hr'));
// QR Code
const subsection_qr = elContent.appendChild(document.createElement('div'));
subsection_qr.setAttribute('class', 'subsection');
const subsection_qr_icon = subsection_qr.appendChild(document.createElement('img'));
subsection_qr_icon.setAttribute('src', '/static/img/qrcode.png');
2021-06-07 06:15:32 -06:00
subsection_qr_icon.setAttribute('alt', '');
subsection_qr_icon.setAttribute('aria-hidden', 'true');
2021-05-03 04:06:37 -06:00
const subsection_qr_text = subsection_qr.appendChild(document.createElement('div'));
2021-06-09 05:58:36 -06:00
const button_fingerprintQR = subsection_qr_text.appendChild(document.createElement('button'));
button_fingerprintQR.innerText = `Show OpenPGP fingerprint QR`;
button_fingerprintQR.setAttribute('onClick', `showQR('${data.fingerprint}', 'fingerprint')`);
button_fingerprintQR.setAttribute('aria-label', `Show QR code for cryptographic fingerprint`);
}
}
customElements.define('kx-key', Key);