Skip to content

Commit

Permalink
fix link wrap issue (#34)
Browse files Browse the repository at this point in the history
- ensures that font awesome icons don't wrap to their own line
  • Loading branch information
vincerubinetti authored Sep 17, 2019
1 parent e2d4550 commit f01e908
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
11 changes: 4 additions & 7 deletions global.css
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,9 @@ table *[data-disabled='false'],
/* -------------------------------------------------- */
/* icon styles */
/* -------------------------------------------------- */
/* prevent icon from wrapping to new line alone */
.icon {
white-space: nowrap;
}
/* prevent icon from wrapping to new line alone */
.icon:before {
content: '';
.fas,
.fab {
display: inline;
}
.fas[data-right],
.fab[data-right] {
Expand All @@ -456,6 +452,7 @@ table *[data-disabled='false'],
margin-left: 10px;
opacity: 0;
transition: opacity 0.25s ease;
text-decoration: none;
}
h3:hover .anchor,
.anchor:focus {
Expand Down
19 changes: 2 additions & 17 deletions scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ function createAnchors() {
while (!element.id && element !== document.body)
element = element.parentElement;
const id = element.id;
if (!id)
continue;
if (!id) continue;

// create link object
const link = document.createElement('a');
Expand All @@ -23,27 +22,13 @@ function createAnchors() {
function onHashChange() {
const id = window.location.hash.replace('#', '');
const element = document.getElementById(id);
if (!element)
return;
if (!element) return;

// start css glow animation
element.setAttribute('data-glow', 'true');
window.setTimeout(() => element.removeAttribute('data-glow'), 2000);
}

// prevent font awesome icons from wrapping to new line alone
function wrapIcons() {
const icons = document.querySelectorAll('i.fas, i.fab');
for (const icon of icons) {
const parent = icon.parentNode;
const wrapper = document.createElement('span');
parent.replaceChild(wrapper, icon);
wrapper.classList.add('icon');
wrapper.appendChild(icon);
}
}

window.addEventListener('load', createAnchors);
window.addEventListener('load', onHashChange);
window.addEventListener('load', wrapIcons);
window.addEventListener('hashchange', onHashChange);

0 comments on commit f01e908

Please sign in to comment.