Skip to content

Commit 9c0a0f4

Browse files
authored
Merge pull request #11 from internetarchive/clip
Copy to clipboard
2 parents 5d9ed39 + 993b0fe commit 9c0a0f4

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

webcomponent/cdxsummary.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,12 @@ ${this.sampleCapturesList()}
308308
margin: var(--cdxsummary-main-margin);
309309
padding: var(--cdxsummary-main-padding, 5px);
310310
}
311+
#container > *:first-child {
312+
margin-top: 0;
313+
}
314+
#container > *:last-child, .samples ul {
315+
margin-bottom: 0;
316+
}
311317
pre, code {
312318
font-family: var(--cdxsummary-mono-font-family, monospace);
313319
}

webcomponent/index.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@
4545
overflow: auto;
4646
white-space: pre-wrap;
4747
}
48+
#code-out {
49+
pointer-events: none;
50+
}
51+
#code-out::before {
52+
content: '🗎 COPY';
53+
float: right;
54+
background: #333;
55+
border: 1px dotted #fff;
56+
border-radius: 3px;
57+
font-size: 1em;
58+
line-height: 1em;
59+
margin-left: -20px;
60+
padding: 2px 2px 0;
61+
cursor: pointer;
62+
opacity: 0.5;
63+
pointer-events: all;
64+
}
4865
#summary-container {
4966
height: 100vh;
5067
overflow: auto;
@@ -89,7 +106,7 @@
89106
const s = a => `<br>&nbsp;&nbsp;--cdxsummary-${a}${'&nbsp;'.repeat(m+1-a.length)}:&nbsp;`;
90107
const d = a => `<datalist id="${a}-list">${lists[a].map(i => `<option value="${i}">`).join('')}</datalist>`;
91108
const stl = lists["vars"].filter(a => q.has(a)).map(i => ` --cdxsummary-${i}: ${r(i)};`).join('\n');
92-
const elm = `${stl ? ['<style>', 'cdx-summary {', stl, '}', '</style>', '', ''].join('\n') : ''}<cdx-summary ${lists["attr"].filter(a => q.has(a)).map(i => `${i}="${g(i)}"`).join(' ')}></cdx-summary>`;
109+
const elm = `${stl ? ['<style>', 'cdx-summary {', stl, '}', '</style>', '', ''].join('\n') : ''}<${['cdx-summary'].concat(lists["attr"].filter(a => q.has(a)).map(i => `${i}="${g(i)}"`)).join(' ')}></cdx-summary>`;
93110
const visf = `
94111
<form id="cdxsummary">
95112
&lt;cdx-summary
@@ -172,6 +189,11 @@
172189
document.getElementById('form-container').innerHTML = visf;
173190
document.getElementById('code-out').innerText = elm;
174191
document.getElementById('summary-container').innerHTML = elm;
192+
document.getElementById('code-out').addEventListener('click', e => {
193+
navigator.clipboard.writeText(e.target.innerText);
194+
e.target.style.opacity = 0.2;
195+
setTimeout(() => e.target.style.opacity = 1, 500);
196+
});
175197
};
176198
</script>
177199
</head>

webcomponent/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@internetarchive/cdxsummary",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "A Web Component to render CDX Summary JSON files",
55
"main": "cdxsummary.js",
66
"module": "cdxsummary.js",

0 commit comments

Comments
 (0)