Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Anchor helpers for guide TOC

  • Loading branch information...
commit 9a63cd8a7d82bc16f182512f4eaa16413db693f6 1 parent 701a7b6
@stefanpenner stefanpenner authored
View
4 lib/highlighter.rb
@@ -31,7 +31,7 @@ class HighlightedHTML < Redcarpet::Render::HTML
include Helpers
def header(text, level)
- "<h#{level} id='toc_#{TOC::TableOfContents.anchorify(text)}'>#{text}</h#{level}>"
+ "<h#{level} class='anchorable-toc' id='toc_#{TOC::TableOfContents.anchorify(text)}'>#{text}</h#{level}>"
end
def block_code(code, language)
@@ -40,4 +40,4 @@ def block_code(code, language)
end
end
-::Middleman::Extensions.register(:highlighter, Highlighter)
+::Middleman::Extensions.register(:highlighter, Highlighter)
View
BIN  source/images/link.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
22 source/layouts/guide.erb
@@ -20,12 +20,26 @@
</div>
<script>
- $("#guide_list .level-1 > a").click(function() {
- $(this).parent().find('> ol').slideToggle(function() {
- positionBackToTop(true);
+ $(function(){
+ $("#guide_list .level-1 > a").click(function() {
+ $(this).parent().find('> ol').slideToggle(function() {
+ positionBackToTop(true);
+ });
+
+ return false;
+ });
+
+ $(function(){
+ $('.anchorable-toc').each(function(){
+ var toc = $(this),
+ id = toc.attr('id'),
+ href = "#" + id,
+ anchor = '<a class="toc-anchor" href="'+href+'"></a>';
+
+ toc.prepend(anchor);
+ });
});
- return false;
});
</script>
<% end %>
View
21 source/stylesheets/site.css.scss
@@ -724,6 +724,27 @@ $content-width: $page-width - $sidebar-width - $col-spacing * 2;
padding: 0px 0px 20px 0px;
}
+ .anchorable-toc {
+ position: relative;
+
+ &:hover a.toc-anchor {
+ display: block;
+ }
+ }
+
+ a.toc-anchor {
+ display: none;
+ position: absolute;
+ text-decoration: none;
+ left: -1em;
+ width: 30px;
+ height: 13px;
+ background: url(/images/link.png) no-repeat;
+ background-size: 18px 9px;
+ left: -21px;
+ margin-top: 5px;
+ }
+
#sidebar {
margin-top: 29px;
width: 218px;
Please sign in to comment.
Something went wrong with that request. Please try again.