Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions site/src/_scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const fontWeights = document.querySelectorAll('.font-weights span');
const systemFont = document.querySelectorAll('.font-stack span');
const systemFontWeight = document.querySelectorAll('.font-stack var');
const fontCard = document.querySelectorAll('.font-card');
const copyButton = document.querySelectorAll('.btn.copy');

const changeSize = (newVal) => {
fonts.style.fontSize = `${newVal}em`;
Expand Down Expand Up @@ -172,6 +173,55 @@ Array.from(systemFont).forEach((el) => {
});
});

// copy to clipboard button
const displayCopySuccess = (el) => {
var innerHtmlToRestore = el.innerHTML;
el.innerHTML = '✓';
el.classList.add('success');
setTimeout(() => {
el.innerHTML = innerHtmlToRestore;
el.classList.remove('success');
}, 500);
};
Array.from(copyButton).forEach((el) => {
el.addEventListener('click', (event) => {
const codeEl = event.target.parentNode.querySelector('code');
try {
// try to use the Clipboard API;...
window.navigator.clipboard.writeText(codeEl.innerText)
.then(() => displayCopySuccess(event.target));
} catch (error) {
console.warn('Failed to copy CSS to clipboard using Clipboard API! '+
'...trying "execCommand". '+
`Original error:\n\t ${error}`);
try {
// ... otherwise, try to use document.execCommand as a fallback
const selectionRangesToRestore = [];
let selection = window.getSelection();
for (let i = 0; i < selection.rangeCount; ++i) {
selectionRangesToRestore.push(selection.getRangeAt(i));
}
selection.removeAllRanges();
const tempRange = document.createRange();
tempRange.setStart(codeEl, 0);
tempRange.setEnd(codeEl.nextSibling, 0);
selection.addRange(tempRange);
document.execCommand('copy');
selection.removeAllRanges();
selectionRangesToRestore.forEach((range) => selection.addRange(range));
displayCopySuccess(event.target);
} catch (error) {
console.error('Failed to copy CSS to clipboard using "execCommand"! '+
'...disabling copy buttons. '+
`Original error:\n\t ${error}`);
Array.from(copyButton).forEach((el) => {
el.setAttribute("disabled", "");
el.title = "Failed to copy CSS!";
});
}
}
});
});

// ----- PREVIEW ----- //
const preview = document.querySelector('#preview');
Expand Down
16 changes: 15 additions & 1 deletion site/src/_styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ section > h2 {

.font-stack {
display: flex;
justify-content: start;
justify-content: space-between;
align-items: center;
min-height: 5rem;
text-align: left;
Expand Down Expand Up @@ -540,6 +540,20 @@ section > h2 {
text-decoration-color: #26599799;
}

.btn.copy {
font-size: 1.5rem;
font-family: initial;
max-width: 48px;
min-width: 48px;
max-height: 48px;
min-height: 48px;
justify-self: end;
align-self: end;
}
.btn.copy.success {
color: #2A2;
border-color: #2A2;
}

/* === SECTION : PREVIEW : ARTICLE VIEW === */

Expand Down
15 changes: 15 additions & 0 deletions site/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ <h3>
<span>sans-serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -170,6 +171,7 @@ <h3>
<span>serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -207,6 +209,7 @@ <h3>
<span>serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -246,6 +249,7 @@ <h3>
<span>sans-serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -284,6 +288,7 @@ <h3>
<span>sans-serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -321,6 +326,7 @@ <h3>
<span>sans-serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -360,6 +366,7 @@ <h3>
<span>sans-serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -395,6 +402,7 @@ <h3>
<span>monospace</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -434,6 +442,7 @@ <h3>
<span>monospace</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -473,6 +482,7 @@ <h3>
<span>sans-serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -516,6 +526,7 @@ <h3>
<span>sans-serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -555,6 +566,7 @@ <h3>
<span>serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -595,6 +607,7 @@ <h3>
<span>serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -635,6 +648,7 @@ <h3>
<span>serif</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down Expand Up @@ -674,6 +688,7 @@ <h3>
<span>cursive</span>;
<strong>font-weight: <var>normal</var>;</strong>
</code>
<button class="btn copy" title="Click to copy CSS">⮺</button>
</div>
</div>

Expand Down