Skip to content

Commit 3b3da46

Browse files
iBugmmistakes
authored andcommittedOct 4, 2019
Show a permalink anchor when hovering over headings in main content (#2251)
* Implement heading permalinks, close #2246 Thanks to jekyll/jekyll for CSS. Link anchor is visible when the mouse hovers over the title line. * Build the updated _main.js
1 parent 6a3d325 commit 3b3da46

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ codekit-config.json
1212
example/_site
1313
Gemfile.lock
1414
node_modules
15-
npm-debug.log*
15+
npm-debug.log*
16+
vendor/bundle

‎_sass/minimal-mistakes/_page.scss

+17
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@
7272
border-bottom: 1px solid $border-color;
7373
}
7474

75+
h1, h2, h3, h4, h5, h6 {
76+
.header-link {
77+
position: relative;
78+
left: 0.5em;
79+
opacity: 0;
80+
font-size: 0.8em;
81+
-webkit-transition: opacity 0.2s ease-in-out 0.1s;
82+
-moz-transition: opacity 0.2s ease-in-out 0.1s;
83+
-o-transition: opacity 0.2s ease-in-out 0.1s;
84+
transition: opacity 0.2s ease-in-out 0.1s;
85+
}
86+
87+
&:hover .header-link {
88+
opacity: 1;
89+
}
90+
}
91+
7592
p,
7693
li,
7794
dl {

‎assets/js/_main.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ $(document).ready(function() {
9292
events: true // if true, emit custom events
9393
});
9494
}
95-
95+
9696
// add lightbox class to all image links
9797
$(
9898
"a[href$='.jpg'],a[href$='.jpeg'],a[href$='.JPG'],a[href$='.png'],a[href$='.gif']"
@@ -132,4 +132,17 @@ $(document).ready(function() {
132132
closeOnContentClick: true,
133133
midClick: true // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source.
134134
});
135+
136+
// Add anchors for headings
137+
$('.page__content').find('h1, h2, h3, h4, h5, h6').each(function() {
138+
var id = $(this).attr('id');
139+
if (id) {
140+
var anchor = document.createElement("a");
141+
anchor.className = 'header-link';
142+
anchor.href = '#' + id;
143+
anchor.innerHTML = '<span class=\"sr-only\">Permalink</span><i class=\"fa fa-link\"></i>';
144+
anchor.title = "Permalink";
145+
$(this).append(anchor);
146+
}
147+
});
135148
});

‎assets/js/main.min.js

+1-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.