Skip to content

Commit 1d8b68f

Browse files
On Hover Footnote Preview (#2522)
1 parent c5efac7 commit 1d8b68f

File tree

11 files changed

+98
-8
lines changed

11 files changed

+98
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99

1010
* Added option `treat_markdown_warnings_as_error` which throws an error when encountering a markdown/interpolation warning ([#2792], [#2751])
11+
* Footnotes can now be previewed by hovering over the link. ([#2080])
1112

1213
### Changed
1314

@@ -1997,6 +1998,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19971998
[#2071]: https://github.com/JuliaDocs/Documenter.jl/issues/2071
19981999
[#2076]: https://github.com/JuliaDocs/Documenter.jl/issues/2076
19992000
[#2078]: https://github.com/JuliaDocs/Documenter.jl/issues/2078
2001+
[#2080]: https://github.com/JuliaDocs/Documenter.jl/issues/2080
20002002
[#2081]: https://github.com/JuliaDocs/Documenter.jl/issues/2081
20012003
[#2085]: https://github.com/JuliaDocs/Documenter.jl/issues/2085
20022004
[#2100]: https://github.com/JuliaDocs/Documenter.jl/issues/2100

assets/html/js/footnote.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// libraries: jquery
2+
// arguments: $
3+
$(document).ready(function () {
4+
$(".footnote-ref").hover(
5+
function () {
6+
var id = $(this).attr("href");
7+
var footnoteContent = $(id).clone().find("a").remove().end().html();
8+
9+
var $preview = $(this).next(".footnote-preview");
10+
11+
$preview.html(footnoteContent).css({
12+
display: "block",
13+
left: "50%",
14+
transform: "translateX(-50%)",
15+
});
16+
17+
repositionPreview($preview, $(this));
18+
},
19+
function () {
20+
var $preview = $(this).next(".footnote-preview");
21+
$preview.css({
22+
display: "none",
23+
left: "",
24+
transform: "",
25+
"--arrow-left": "",
26+
});
27+
},
28+
);
29+
30+
function repositionPreview($preview, $ref) {
31+
var previewRect = $preview[0].getBoundingClientRect();
32+
var refRect = $ref[0].getBoundingClientRect();
33+
var viewportWidth = $(window).width();
34+
35+
if (previewRect.right > viewportWidth) {
36+
var excessRight = previewRect.right - viewportWidth;
37+
$preview.css("left", `calc(50% - ${excessRight + 10}px)`);
38+
} else if (previewRect.left < 0) {
39+
var excessLeft = 0 - previewRect.left;
40+
$preview.css("left", `calc(50% + ${excessLeft + 10}px)`);
41+
}
42+
43+
var newPreviewRect = $preview[0].getBoundingClientRect();
44+
45+
var arrowLeft = refRect.left + refRect.width / 2 - newPreviewRect.left;
46+
47+
$preview.css("--arrow-left", arrowLeft + "px");
48+
}
49+
});

assets/html/scss/documenter/components/_all.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
@import "docstring";
33
@import "example";
44
@import "warner";
5+
@import "footnote";
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.footnote-reference {
2+
position: relative;
3+
display: inline-block;
4+
}
5+
6+
.footnote-preview {
7+
display: none;
8+
position: absolute;
9+
z-index: 1000;
10+
max-width: 300px;
11+
width: max-content;
12+
background-color: $body-background-color;
13+
border: 1px solid $link-hover;
14+
padding: 10px;
15+
border-radius: 5px;
16+
top: calc(100% + 10px);
17+
left: 50%;
18+
transform: translateX(-50%);
19+
box-sizing: border-box;
20+
/* Default arrow position */
21+
--arrow-left: 50%;
22+
}
23+
24+
.footnote-preview::before {
25+
content: "";
26+
position: absolute;
27+
top: -10px;
28+
left: var(--arrow-left);
29+
transform: translateX(-50%);
30+
border-left: 10px solid transparent;
31+
border-right: 10px solid transparent;
32+
border-bottom: 10px solid $link-hover;
33+
}

assets/html/themes/catppuccin-frappe.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/html/themes/catppuccin-latte.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/html/themes/catppuccin-macchiato.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/html/themes/catppuccin-mocha.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/html/themes/documenter-dark.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/html/themes/documenter-light.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)