Skip to content

Commit a460189

Browse files
committed
Add footnote tooltips with Bootstrap integration and styling
1 parent 31fe518 commit a460189

File tree

3 files changed

+184
-0
lines changed

3 files changed

+184
-0
lines changed

module/assets/css/style.css

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,86 @@ li input[type="checkbox"] + * {
512512
display: none;
513513
}
514514
}
515+
516+
/* ========================================
517+
Footnote Tooltips
518+
======================================== */
519+
520+
/* Footnote reference links with enhanced styling */
521+
a.footnote-tooltip {
522+
position: relative;
523+
color: #135289;
524+
text-decoration: none;
525+
font-weight: 600;
526+
padding: 0 2px;
527+
transition: all 0.2s ease;
528+
}
529+
530+
a.footnote-tooltip:hover {
531+
color: #0d3d63;
532+
text-decoration: underline;
533+
}
534+
535+
/* Custom tooltip styling for footnote content */
536+
.footnote-tooltip-content {
537+
--bs-tooltip-max-width: 400px;
538+
--bs-tooltip-bg: #353535;
539+
--bs-tooltip-color: #ffffff;
540+
--bs-tooltip-opacity: 0.98;
541+
}
542+
543+
.footnote-tooltip-content .tooltip-inner {
544+
text-align: left;
545+
padding: 0.75rem 1rem;
546+
font-size: 0.875rem;
547+
line-height: 1.5;
548+
max-width: 400px;
549+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
550+
}
551+
552+
/* Links within tooltip */
553+
.footnote-tooltip-content .tooltip-inner a {
554+
color: #6fb3f0;
555+
text-decoration: underline;
556+
word-break: break-all;
557+
}
558+
559+
.footnote-tooltip-content .tooltip-inner a:hover {
560+
color: #a0cdf5;
561+
}
562+
563+
/* Italic text in tooltips (book/article titles) */
564+
.footnote-tooltip-content .tooltip-inner em,
565+
.footnote-tooltip-content .tooltip-inner i {
566+
font-style: italic;
567+
color: #e0e0e0;
568+
}
569+
570+
/* Better text wrapping in tooltips */
571+
.footnote-tooltip-content .tooltip-inner {
572+
white-space: normal;
573+
word-wrap: break-word;
574+
}
575+
576+
/* Responsive tooltip sizing */
577+
@media (max-width: 768px) {
578+
.footnote-tooltip-content {
579+
--bs-tooltip-max-width: 280px;
580+
}
581+
582+
.footnote-tooltip-content .tooltip-inner {
583+
font-size: 0.8125rem;
584+
padding: 0.625rem 0.875rem;
585+
}
586+
}
587+
588+
@media (max-width: 480px) {
589+
.footnote-tooltip-content {
590+
--bs-tooltip-max-width: 240px;
591+
}
592+
593+
.footnote-tooltip-content .tooltip-inner {
594+
font-size: 0.75rem;
595+
padding: 0.5rem 0.75rem;
596+
}
597+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* Enhanced Footnote Citations with Bootstrap Tooltips
3+
*
4+
* Adds interactive tooltips to footnote references that show citation details
5+
* without requiring users to scroll to the bottom of the page.
6+
*
7+
* Features:
8+
* - Bootstrap 5 tooltip integration
9+
* - HTML content support for links and formatting
10+
* - Maintains click-through functionality
11+
* - Automatic initialization on page load
12+
*/
13+
14+
(function() {
15+
'use strict';
16+
17+
/**
18+
* Extract and format footnote reference content
19+
* @param {string} footnoteId - The footnote reference ID (e.g., "fn:1")
20+
* @returns {string|null} HTML formatted tooltip content
21+
*/
22+
function getFootnoteContent(footnoteId) {
23+
// Find the corresponding footnote definition
24+
const footnoteElement = document.getElementById(footnoteId);
25+
if (!footnoteElement) {
26+
return null;
27+
}
28+
29+
// Clone the content to avoid modifying the original
30+
const content = footnoteElement.cloneNode(true);
31+
32+
// Remove the back-reference link (↩︎) from tooltip
33+
const backRef = content.querySelector('.footnote-backref');
34+
if (backRef) {
35+
backRef.remove();
36+
}
37+
38+
// Get the text content and format it
39+
let html = content.innerHTML.trim();
40+
41+
// Limit length for tooltip (optional)
42+
const maxLength = 300;
43+
if (html.length > maxLength) {
44+
html = html.substring(0, maxLength) + '...';
45+
}
46+
47+
return html;
48+
}
49+
50+
/**
51+
* Initialize tooltips for all footnote references
52+
*/
53+
function initializeFootnoteTooltips() {
54+
// Find all footnote references in the content
55+
const footnoteRefs = document.querySelectorAll('a[href^="#fn:"]');
56+
57+
footnoteRefs.forEach(ref => {
58+
// Extract footnote ID from href
59+
const href = ref.getAttribute('href');
60+
const footnoteId = href.substring(1); // Remove the '#'
61+
62+
// Get the footnote content
63+
const tooltipContent = getFootnoteContent(footnoteId);
64+
65+
if (tooltipContent) {
66+
// Add Bootstrap tooltip attributes
67+
ref.setAttribute('data-bs-toggle', 'tooltip');
68+
ref.setAttribute('data-bs-placement', 'top');
69+
ref.setAttribute('data-bs-html', 'true');
70+
ref.setAttribute('data-bs-title', tooltipContent);
71+
72+
// Add custom class for styling
73+
ref.classList.add('footnote-tooltip');
74+
75+
// Initialize the tooltip
76+
new bootstrap.Tooltip(ref, {
77+
html: true,
78+
trigger: 'hover focus',
79+
container: 'body',
80+
boundary: 'viewport',
81+
customClass: 'footnote-tooltip-content'
82+
});
83+
}
84+
});
85+
}
86+
87+
/**
88+
* Initialize when DOM is ready
89+
*/
90+
if (document.readyState === 'loading') {
91+
document.addEventListener('DOMContentLoaded', initializeFootnoteTooltips);
92+
} else {
93+
// DOM already loaded
94+
initializeFootnoteTooltips();
95+
}
96+
97+
})();

module/layouts/baseof.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,5 +281,9 @@
281281
{{- if $submenuJs -}}
282282
<script src="{{ $submenuJs.RelPermalink }}"></script>
283283
{{- end -}}
284+
{{- $footnoteTooltipsJs := resources.Get "js/footnote-tooltips.js" -}}
285+
{{- if $footnoteTooltipsJs -}}
286+
<script src="{{ $footnoteTooltipsJs.RelPermalink }}"></script>
287+
{{- end -}}
284288
</body>
285289
</html>

0 commit comments

Comments
 (0)