Skip to content

Commit

Permalink
Re-enable in-page anchors
Browse files Browse the repository at this point in the history
* Fixes issue #19
* Shows a paragraph symbol when hovering over an in-page anchor (=heading)
* Adjust link when clicking on in-page anchor
  • Loading branch information
Dynalon committed Nov 5, 2013
1 parent d12eccf commit 6dd22fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
/* hide the main content while we assemble everything */
.md-hidden-load { display: none; }

#md-content h1:hover::after, #md-content h2:hover::after,
#md-content h3:hover::after, #md-content h4:hover::after {
content: ' \B6';
}
/* for pageContentMenu */
#md-page-menu {
position: static;
Expand Down
13 changes: 9 additions & 4 deletions js/basic_skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

$.md.stage('all_ready').subscribe(function(done) {
if ($.md.inPageAnchor !== '') {
$.md.scrollToInPageAnchor($.md.inPageAnchor);
$.md.util.wait(500).then(function () {
$.md.scrollToInPageAnchor($.md.inPageAnchor);
});
}
done();
});
Expand Down Expand Up @@ -155,6 +157,10 @@
$('h1,h2,h3,h4,h5,h6').each (function () {
var $heading = $(this);
$heading.addClass('md-inpage-anchor');
$heading.click (function (){
var subhash = $heading.text().replace(' ', '_');
window.location.hash = '#!' + $.md.mainHref + '#' + subhash;
});

//var name = $.trim ($heading.text ());
//var $anchor1 = $('<a />').attr ('name', name).addClass('md-inpage-anchor md-inpage-anchor-space');
Expand Down Expand Up @@ -206,9 +212,8 @@
var match = $this.text().toLowerCase().replace(/ /g, '_');
if (spaceAnchor === match || underscoreAnchor === match) {
this.scrollIntoView (true);
// TODO actually figure the real height of the navbar, because
// custom themes may have different height
window.scrollBy(0, -50);
var navbar_offset = $('.navbar-collapse').height() + 5;
window.scrollBy(0, -navbar_offset + 5);
doBreak = true;
}
});
Expand Down
2 changes: 1 addition & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
}

// extract possible in-page anchor
var ex_pos = href.indexOf('!');
var ex_pos = href.indexOf('#');
if (ex_pos !== -1) {
$.md.inPageAnchor = href.substring(ex_pos + 1);
$.md.mainHref = href.substring(0, ex_pos);
Expand Down

0 comments on commit 6dd22fe

Please sign in to comment.