Skip to content

Commit

Permalink
Merge pull request #56 from curtismitchell/responsive_anchors
Browse files Browse the repository at this point in the history
Responsive anchors
  • Loading branch information
Dynalon committed Dec 2, 2013
2 parents 0237ef4 + d2bc364 commit 37456d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions js/basic_skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@
$pilcrow.appendTo($heading);
}

// adds a link to the navigation at the top of the page
function addJumpLinkToTOC($heading) {
var c = $.md.config.tocAnchor;
var $jumpLink = $('<a class="visible-xs visible-sm" href="#md-page-menu">' + c + '</a>');
$jumpLink.click(function(ev) {
ev.preventDefault();

$('body').scrollTop($('#md-page-menu').position().top);
});

$jumpLink.insertAfter($heading);
}

// adds a page inline anchor to each h1,h2,h3,h4,h5,h6 element
// which can be accessed by the headings text
$('h1,h2,h3,h4,h5,h6').not('#md-title h1').each (function () {
Expand All @@ -199,6 +212,10 @@
var text = $heading.clone().children('.anchor-highlight').remove().end().text();
var href = $.md.util.getInpageAnchorHref(text);
addPilcrow($heading, href);

//add jumplink to table of contents
addJumpLinkToTOC($heading);

});
}

Expand Down
3 changes: 2 additions & 1 deletion js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
useSideMenu: true,
lineBreaks: 'gfm',
additionalFooterText: '',
anchorCharacter: '&para;'
anchorCharacter: '&para;',
tocAnchor: '[&#11014;]'
};


Expand Down

0 comments on commit 37456d7

Please sign in to comment.