keyoxide-web/static/kx-key.js

52 lines
2 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');
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'));
profile_link.innerHTML = `Key link: <a href="${data.key.uri}">${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');
const subsection_qr_text = subsection_qr.appendChild(document.createElement('div'));
const button_profileQR = subsection_qr_text.appendChild(document.createElement('button'));
button_profileQR.innerText = `Show OpenPGP fingerprint QR`;
button_profileQR.setAttribute('onClick', `showQR('${data.fingerprint}', 'fingerprint')`);
}
}
customElements.define('kx-key', Key);