Skip to content

Commit 9cac649

Browse files
committed
anchor: use button implementation #1162
1 parent 72651f5 commit 9cac649

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

assets/css/theme.css

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ i.cstyle {
18041804
background-color: var(--VARIABLE-BOX-color);
18051805
border-radius: 4px;
18061806
display: inline-block;
1807-
font-size: 0.9rem;
1807+
font-size: 0.9em;
18081808
font-weight: 500;
18091809
line-height: 1.1;
18101810
margin-bottom: 0;
@@ -1904,14 +1904,9 @@ button.btn.noborder,
19041904

19051905
/* anchors */
19061906
.anchor {
1907-
-webkit-appearance: none;
1908-
appearance: none;
1909-
background-color: transparent;
1910-
color: var(--VARIABLE-LINK-color);
1911-
cursor: pointer;
19121907
font-size: 0.5em;
1913-
margin-inline-start: 0.66em;
1914-
margin-top: 0.9em;
1908+
margin-inline-start: 0.3em;
1909+
margin-top: 0.5em;
19151910
position: absolute;
19161911
visibility: hidden;
19171912
}
@@ -1921,12 +1916,6 @@ button.btn.noborder,
19211916
visibility: visible;
19221917
}
19231918
}
1924-
.anchor:hover,
1925-
.anchor:active,
1926-
.anchor:focus {
1927-
color: var(--VARIABLE-LINK-HOVER-color);
1928-
}
1929-
19301919
h2:hover .anchor,
19311920
h3:hover .anchor,
19321921
h4:hover .anchor,
@@ -1935,6 +1924,13 @@ h6:hover .anchor {
19351924
visibility: visible;
19361925
}
19371926

1927+
.anchor.btn > * {
1928+
height: calc(2em + 4px);
1929+
width: calc(2em + 4px);
1930+
box-sizing: border-box;
1931+
padding: 2px;
1932+
}
1933+
19381934
/* Redfines headers style */
19391935

19401936
h1 a,

assets/js/theme.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,14 +583,16 @@ function initAnchorClipboard() {
583583
var origin = document.location.origin == 'null' ? `${document.location.protocol}//${document.location.host}` : document.location.origin;
584584
var id = encodeURIComponent(element.id);
585585
var link = `${origin}${document.location.pathname}#${id}`;
586-
var new_element = document.createElement('button');
587-
new_element.classList.add('anchor');
586+
var span = document.createElement('span');
587+
span.classList.add('anchor', 'btn', 'cstyle', 'link', 'noborder', 'notitle', 'interactive');
588+
span.setAttribute('data-clipboard-text', link);
589+
var button = document.createElement('button');
588590
if (!window.relearn.disableAnchorCopy) {
589-
new_element.setAttribute('title', window.T_Copy_link_to_clipboard);
591+
button.setAttribute('title', window.T_Copy_link_to_clipboard);
590592
}
591-
new_element.setAttribute('data-clipboard-text', link);
592-
new_element.innerHTML = '<i class="fas fa-link fa-lg"></i>';
593-
element.appendChild(new_element);
593+
button.innerHTML = '<i class="fas fa-link fa-lg"></i>';
594+
span.appendChild(button);
595+
element.appendChild(span);
594596
});
595597

596598
var anchors = document.querySelectorAll('.anchor');
@@ -617,7 +619,7 @@ function initAnchorClipboard() {
617619
} else if (!window.relearn.disableAnchorScrolling) {
618620
for (var i = 0; i < anchors.length; i++) {
619621
anchors[i].addEventListener('click', function (e) {
620-
e.target.parentElement.parentElement.scrollIntoView({ behavior: 'smooth' });
622+
e.currentTarget.parentElement.scrollIntoView({ behavior: 'smooth' });
621623
var state = window.history.state || {};
622624
state = Object.assign({}, typeof state === 'object' ? state : {});
623625
history.replaceState({}, '', e.text);

layouts/partials/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.2.0+00a98acfe8fd40126ee740ffc8d1a31513e0933c
1+
8.2.0+72651f5c35b8fee9ba269d1afb36ebf963036474

0 commit comments

Comments
 (0)