Skip to content

Commit 5e9705f

Browse files
committed
Separate out CSS
1 parent 8ae6fd1 commit 5e9705f

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

assets/js/anchor.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,23 @@ document.addEventListener('DOMContentLoaded', () => {
1313
if (heading.id) {
1414
const a = document.createElement('a');
1515
a.setAttribute('aria-hidden', 'true');
16-
a.style.cssText = 'display: none; visibility: hidden; padding: 0rem .3rem .1rem .3rem; margin-left: .4rem; margin-top: -.5rem; margin-bottom: -.5rem; border-radius: 4px;';
17-
a.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" fill="var(--bs-body-color)" width="24" height="24" viewBox="0 0 32 32"><path d="M18.9001 7.22C20.5201 5.6 23.1601 5.6 24.7801 7.22C26.4001 8.84 26.4001 11.48 24.7801 13.1L20.4001 17.48L21.8101 18.89L26.1901 14.51C28.5901 12.11 28.5901 8.2 26.1901 5.8C23.7901 3.4 19.8801 3.4 17.4801 5.8L13.1001 10.18L14.5101 11.59L18.8901 7.21L18.9001 7.22Z"/><path d="M10.16 28C11.74 28 13.32 27.4 14.52 26.2L18.9 21.82L17.49 20.41L13.11 24.79C11.49 26.41 8.85002 26.41 7.23002 24.79C5.61002 23.17 5.61002 20.53 7.23002 18.91L11.61 14.53L10.2 13.12L5.82002 17.5C3.42002 19.9 3.42002 23.81 5.82002 26.21C7.02002 27.41 8.60002 28.01 10.18 28.01L10.16 28Z"/><path d="M9.44971 21.1336L21.124 9.45927L22.5383 10.8735L10.8639 22.5478L9.44971 21.1336Z"/></svg>';
16+
a.classList.add('anchor-icon'); // Add anchor-icon class (_styles_project.scss)
17+
a.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" fill="var(--bs-body-color)" width="20" height="20" viewBox="0 0 32 32"><path d="M18.9001 7.22C20.5201 5.6 23.1601 5.6 24.7801 7.22C26.4001 8.84 26.4001 11.48 24.7801 13.1L20.4001 17.48L21.8101 18.89L26.1901 14.51C28.5901 12.11 28.5901 8.2 26.1901 5.8C23.7901 3.4 19.8801 3.4 17.4801 5.8L13.1001 10.18L14.5101 11.59L18.8901 7.21L18.9001 7.22Z"/><path d="M10.16 28C11.74 28 13.32 27.4 14.52 26.2L18.9 21.82L17.49 20.41L13.11 24.79C11.49 26.41 8.85002 26.41 7.23002 24.79C5.61002 23.17 5.61002 20.53 7.23002 18.91L11.61 14.53L10.2 13.12L5.82002 17.5C3.42002 19.9 3.42002 23.81 5.82002 26.21C7.02002 27.41 8.60002 28.01 10.18 28.01L10.16 28Z"/><path d="M9.44971 21.1336L21.124 9.45927L22.5383 10.8735L10.8639 22.5478L9.44971 21.1336Z"/></svg>`;
1818
a.href = '#' + heading.id;
1919

2020
// Append anchor element to heading
2121
heading.appendChild(a);
2222

2323
// Show icon when hovering over heading
2424
heading.addEventListener('mouseenter', () => {
25-
a.style.visibility = 'initial';
26-
a.style.display = 'inline-block'
25+
a.style.display = 'inline-block';
2726
});
2827

2928
// Hide icon when mouse leaves heading
3029
heading.addEventListener('mouseleave', () => {
31-
a.style.visibility = 'hidden';
3230
a.style.display = 'none';
3331
});
3432

35-
// Show background when hovering over icon
36-
a.addEventListener('mouseenter', () => {
37-
a.style.background = 'var(--bs-gray-200)';
38-
});
39-
40-
// Hide background when mouse leaves icon
41-
a.addEventListener('mouseleave', () => {
42-
a.style.background = 'none';
43-
});
44-
4533
// Initialize Bootstrap tooltip
4634
const tooltip = new bootstrap.Tooltip(a, {
4735
title: 'Copy link to clipboard',

assets/scss/_styles_project.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@
100100
padding-bottom: 0px;
101101
}
102102

103+
// Anchor icon styling for anchor.js
104+
105+
.anchor-icon {
106+
display: none;
107+
padding: 0rem .3rem .1rem .3rem;
108+
margin: -.5rem 0rem -.5rem .3rem;
109+
border-radius: 4px;
110+
}
111+
112+
.anchor-icon:hover {
113+
background: $gray-light;
114+
}
115+
103116
// _code.scss - Code formatting
104117

105118
.td-content {

0 commit comments

Comments
 (0)