Skip to content

Commit 7e15628

Browse files
author
Igor Alexey
committed
anchors
1 parent af56dc4 commit 7e15628

4 files changed

Lines changed: 44 additions & 12 deletions

File tree

index.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,6 @@ function formatFileSize($bytes) {
231231
</p>
232232
</footer>
233233
</div>
234-
<!-- Right column -->
235-
<div>
236-
</div>
237234
<?php
238235
echo $additionalBody;
239236
?>

js/cms.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const contentDiv = document.getElementsByClassName('content')[0];
99
const headings = contentDiv.querySelectorAll('h1, h2, h3, h4, h5, h6');
1010
let tocHTML = '';
1111
let currentLevel = 0;
12-
headings.forEach((heading) => {
12+
headings.forEach(heading => {
1313
const level = parseInt(heading.tagName[1], 10);
1414
// Adjust indentation levels based on the heading hierarchy
1515
if (level > currentLevel) {
@@ -24,4 +24,29 @@ headings.forEach((heading) => {
2424
});
2525
tocHTML += '</li>'.repeat(currentLevel);
2626
const firstDiv = document.getElementById('toc-content');
27-
firstDiv.insertAdjacentHTML('beforeend', tocHTML);
27+
firstDiv.insertAdjacentHTML('beforeend', tocHTML);
28+
29+
// Function to scroll to the heading anchor
30+
function scrollToHeadingAnchor() {
31+
const hash = window.location.hash;
32+
console.log('Hash:', hash);
33+
if (hash) {
34+
const headings = contentDiv.querySelectorAll('h1, h2, h3, h4, h5, h6');
35+
headings.forEach(heading => {
36+
if (toSnakeCase(heading.innerText) === hash.substring(1)) {
37+
const yOffset = -50; // Adjust this value if you want to offset the scroll position
38+
const y = heading.getBoundingClientRect().top + window.pageYOffset + yOffset;
39+
console.log('Scrolling to Y:', y);
40+
window.scrollTo({ top: y, behavior: 'smooth' });
41+
}
42+
});
43+
} else {
44+
console.log('No hash found in the URL.');
45+
}
46+
}
47+
48+
// Call the function on page load
49+
scrollToHeadingAnchor();
50+
51+
// Add an event listener to scroll to the heading when the URL hash changes
52+
window.addEventListener('hashchange', scrollToHeadingAnchor);

styles/main.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
body {
44
display: flex;
5+
margin: 0.5em;
56
}
67

78
:root {
@@ -14,14 +15,14 @@ body > div:nth-child(2) {
1415
}
1516

1617
/* Left and right columns */
17-
body > div:nth-child(1), body > div:nth-child(3) {
18-
width: 25%;
18+
body > div:nth-child(1) {
19+
width: 10em;
20+
margin-right: 0.5em;
1921
}
2022

2123
/* Content styles to fill the columns */
2224
body > div {
2325
box-sizing: border-box;
24-
padding: 10px;
2526
}
2627

2728
/* Responsive styles */

styles/themes/Legacy.css

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,23 @@ a:hover {
3131
display: flow-root;
3232
}
3333

34-
.content, #toc {
35-
background-color: #fff;
34+
.content {
3635
padding-left: 1em;
3736
padding-right: 1em;
37+
}
38+
39+
.content, #toc {
40+
background-color: #fff;
3841
border-width: 1px;
3942
border-style: solid;
4043
border-color: var(--border-color);
4144
border-radius: 2px;
4245
}
4346

47+
#toc {
48+
float: right;
49+
}
50+
4451
#toc h2 {
4552
display: inline-block;
4653
width: 100%;
@@ -53,8 +60,9 @@ a:hover {
5360
}
5461

5562
ul {
56-
padding-left: 10px;
63+
padding-left: 0.5em;
5764
margin: 0;
65+
list-style: none;
5866
}
5967

6068
.navigation .right {
@@ -99,9 +107,10 @@ ul {
99107
#eee 12px,
100108
transparent 12px,
101109
transparent 20px);
102-
padding: 1.22em;
110+
padding: 0.5em;
103111
margin-bottom: 0.5em;
104112
border: 1px solid var(--border-color);
113+
height: 19px;
105114
}
106115

107116
/* Page Content */

0 commit comments

Comments
 (0)