Skip to content

Commit 403e870

Browse files
eksperimentalJosé Valim
authored and
José Valim
committed
jekyll-toc: fix css issue
Signed-off-by: José Valim <[email protected]>
1 parent 046cd48 commit 403e870

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

_includes/bottom.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
headers: 'h2, h3, h4, h5, h6',
3232
showSpeed: 0,
3333
linkHere: true,
34-
linkHereDuration: 600,
34+
linkHereDuration: 0,
3535
backToTop: true,
3636
backToTopSelector: '.toc',
37-
backToTopDuration: 100,
37+
backToTopDuration: 0,
3838
});
3939
$('.jekyll-toc-header a.jekyll-toc-link-here span.jekyll-toc-icon').addClass('icon icon-link');
4040
$('.jekyll-toc-header a.jekyll-toc-back-to-top span.jekyll-toc-icon').addClass('icon icon-chevron-up');

_includes/toc.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div class="toc"></div>
1+
<div id="toc" class="toc"></div>

css/style.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -914,9 +914,9 @@ li.image {
914914
}
915915

916916
/* extending jekyll-toc */
917-
.icon, .icon span {
917+
.icon {
918918
font: normal normal normal 16px/1 icons !important;
919-
display: inline-block !important;
919+
/* display: inline-block; */
920920
text-decoration: none;
921921
text-rendering: auto;
922922
-webkit-font-smoothing: antialiased;

js/toc/toc.js

+30-9
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,42 @@
6464
var back_to_top = '<a class="jekyll-toc-anchor jekyll-toc-back-to-top"><span class="jekyll-toc-icon">'+settings.backToTopText+'</span></a>';
6565
var link_here = '<a class="jekyll-toc-anchor jekyll-toc-link-here"><span class="jekyll-toc-icon">'+settings.linkHereText+'</span></a>';
6666

67+
function force_update_hash(hash) {
68+
window.location.hash = '';
69+
window.location.hash = hash;
70+
}
71+
72+
function update_hash(hash) {
73+
if(history.pushState) {
74+
history.pushState(null, null, '#'+hash);
75+
} else {
76+
force_update_hash(hash)
77+
}
78+
}
79+
6780
function animate_link_here(header_id) {
81+
update_hash( (typeof header_id === "undefined") ? '' : header_id );
6882
$('html,body').animate({scrollTop:$(document.getElementById(header_id)).offset().top}, settings.linkHereDuration);
69-
window.location.hash = ( header_id === "undefined" ) ? '' : header_id;
7083
}
71-
84+
7285
if (settings.backToTop) {
7386
$(document).on('click', '.jekyll-toc-back-to-top', function() {
74-
if ( settings.backToTopSelector == '' ) {
75-
$('html, body').animate({scrollTop: $('html, body').offset().top}, settings.backToTopDuration);
76-
window.location.hash = '';
87+
if ( settings.backToTopSelector == '' ) {
88+
if ( settings.backToTopDuration > 0 ) {
89+
update_hash('');
90+
$('html, body').animate({scrollTop: $('html, body').offset().top}, settings.backToTopDuration);
91+
} else {
92+
force_update_hash('');
93+
}
7794
} else {
78-
var top_element = $(settings.backToTopSelector).first();
79-
$('html, body').animate({scrollTop: top_element.offset().top}, settings.backToTopDuration);
95+
var top_element = ( $(settings.backToTopSelector).length ) ? $(settings.backToTopSelector).first() : $('html, body');
8096
var top_element_id = $(top_element).attr('id');
81-
window.location.hash = ( typeof top_element_id === "undefined" ) ? '' : top_element_id;
97+
update_hash ( (typeof top_element_id === "undefined") ? '' : top_element_id );
98+
if ( settings.backToTopDuration > 0 || window.location.hash == '' ) {
99+
$('html, body').animate({scrollTop: top_element.offset().top}, settings.backToTopDuration);
100+
} else {
101+
force_update_hash(window.location.hash);
102+
}
82103
}
83104
});
84105
}
@@ -132,4 +153,4 @@
132153

133154
render[settings.showEffect]();
134155
};
135-
})(jQuery);
156+
})(jQuery);

0 commit comments

Comments
 (0)