Commit 55de3b2d authored by taco@waag.org's avatar taco@waag.org
Browse files

copy quote

parent c9dc5fde
......@@ -11,6 +11,11 @@
font-family: monospace;
}
.pop-button {
margin-top: 10px;
float: right;
}
.pop-proof {
text-align: center;
background-color: lightgray;
......
......@@ -17,27 +17,47 @@ if (window.hasRun) {
let message = signature.message;
let result = JSON.parse(state.results[i][1]);
switch(fragmentType){
switch(fragmentType) {
case 'data-pop-v0-title':
renderTitle(fragmentType,message,result);
renderTitle(fragmentType,message,result,signature);
break;
case 'data-pop-v0-abstract':
renderAbstract(fragmentType,message,result);
renderAbstract(fragmentType,message,result,signature);
break;
case 'data-pop-v0-body':
renderBody(fragmentType,message,result);
renderBody(fragmentType,message,result,signature);
break;
case 'data-pop-v0-author':
renderAuthor(fragmentType,message,result);
renderAuthor(fragmentType,message,result,signature);
break;
case 'data-pop-v0-img':
renderImage(fragmentType,message,result);
renderImage(fragmentType,message,result,signature);
break;
}
}
}
//renders a copybutton for the fragment
function appendCopyButton(fragment, type, message, signature){
let button = document.createElement('button');
button.classList.add('pop-button');
button.type = "button";
button.textContent = "Copy";
button.onclick = function() {toClipboard(message,signature,type)};
fragment.appendChild(button);
}
//creates a blockquote for the message that contains the signature as attribute
function toClipboard(message,signature,type){
let serialized = btoa(JSON.stringify(signature));
let blockquote = document.createElement('blockquote');
blockquote.textContent = message;
blockquote.setAttribute(type,serialized);
navigator.clipboard.writeText(blockquote.outerHTML);
alert('Copied to clipboard');
}
function appendLabel(fragment,type){
let label = document.createElement('div');
label.classList.add('pop-label');
......@@ -53,22 +73,25 @@ if (window.hasRun) {
fragment.appendChild(proof);
}
function renderTitle(type, content, result){
function renderTitle(type, content, result, signature){
let fragment = document.createElement('div');
fragment.classList.add('pop-title');
appendLabel(fragment, type);
appendCopyButton(fragment,type,content,signature);
let header = document.createElement('h1');
header.textContent = content;
fragment.appendChild(header);
appendProof(fragment,result);
document.body.appendChild(fragment);
}
function renderAbstract(type, content, result){
function renderAbstract(type, content, result, signature){
let fragment = document.createElement('div');
fragment.classList.add('pop-abstract');
appendLabel(fragment, type);
appendCopyButton(fragment,type,content,signature);
let p = document.createElement('pre');
p.textContent = content;
......@@ -78,10 +101,11 @@ if (window.hasRun) {
document.body.appendChild(fragment);
}
function renderBody(type, content, result){
function renderBody(type, content, result, signature){
let fragment = document.createElement('div');
fragment.classList.add('pop-body');
appendLabel(fragment, type);
appendCopyButton(fragment,type,content,signature);
let p = document.createElement('pre');
p.textContent = content;
......@@ -91,10 +115,11 @@ if (window.hasRun) {
document.body.appendChild(fragment);
}
function renderAuthor(type, content, result){
function renderAuthor(type, content, result, signature){
let fragment = document.createElement('div');
fragment.classList.add('pop-author');
appendLabel(fragment, type);
appendCopyButton(fragment,type,content,signature);
let p = document.createElement('pre');
p.textContent = content;
......@@ -104,13 +129,14 @@ if (window.hasRun) {
document.body.appendChild(fragment);
}
function renderImage(type, content, result){
function renderImage(type, content, result, signature){
let fragment = document.createElement('div');
fragment.classList.add('pop-image');
appendLabel(fragment, type);
let p = document.createElement('img');
p.src = content;
appendCopyButton(fragment,type,content,signature);
fragment.appendChild(p);
appendProof(fragment,result);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment