Created
September 28, 2017 15:58
-
-
Save paulwellnerbou/545ec5eae27b483ef4db7dda91cc63cc to your computer and use it in GitHub Desktop.
Create embedded hover-Footnotes for Ghost 1.0's default theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Thanks to w3schools for the base sample implementation: | |
https://www.w3schools.com/howto/howto_css_tooltip.asp | |
Put this in the "Code inject" of your Ghost 1.0 Blog Footer. --> | |
<style> | |
.tooltip { | |
position: relative; | |
} | |
.tooltip .tooltiptext { | |
visibility: hidden; | |
width: 240px; | |
background-color: #555; | |
color: #fff; | |
text-align: center; | |
border-radius: 6px; | |
padding: 5px 0; | |
position: absolute; | |
z-index: 1; | |
bottom: 90%; | |
left: 50%; | |
margin-left: -120px; | |
opacity: 0; | |
transition: opacity .5s; | |
line-height: 1.1em; | |
font-size: 90%; | |
padding: .5em; | |
} | |
.tooltip .tooltiptext * { | |
color: #fff; | |
} | |
.tooltip .tooltiptext::after { | |
content: ""; | |
position: absolute; | |
top: 100%; | |
left: 50%; | |
margin-left: -5px; | |
border-width: 5px; | |
border-style: solid; | |
border-color: #555 transparent transparent transparent; | |
} | |
.tooltip:hover .tooltiptext { | |
visibility: visible; | |
opacity: 1; | |
} | |
.tooltip a.footnote-backref { | |
display: none; | |
} | |
</style> | |
<script> | |
var createTooltip = function(tooltiptext) { | |
var tooltip = document.createElement('span'); | |
tooltip.setAttribute('class', 'tooltiptext'); | |
tooltip.innerHTML = tooltiptext; | |
return tooltip; | |
} | |
var appendTooltipTo = function(element, tooltipText) { | |
element.append(createTooltip(tooltipText)); | |
} | |
var processTooltip = function(footnoteid) { | |
var footnotep = document.getElementById(footnoteid).querySelector('p'); | |
var footnotetext = footnotep.innerHTML; | |
var footnoterefid = document.getElementById(footnoteid).querySelector('a.footnote-backref').getAttribute('href').substring(1); | |
var footnoteref = document.getElementById(footnoterefid); | |
footnoteref.setAttribute('class', 'tooltip'); | |
appendTooltipTo(footnoteref, footnotetext); | |
} | |
var footnotes = document.querySelectorAll('li.footnote-item'); | |
[].forEach.call(footnotes, function( element ) { | |
processTooltip(element.getAttribute('id')); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment