Permalink
Browse files

Show anchor links on section headers.

  • Loading branch information...
1 parent 26b8bf4 commit 9f8eb99468157786aeb5b3878d08b483c0d20364 @jasoncodes committed Feb 5, 2011
Showing with 39 additions and 0 deletions.
  1. +1 −0 _layouts/default.html
  2. +21 −0 javascripts/main.js
  3. +17 −0 stylesheets/screen.sass
View
@@ -11,6 +11,7 @@
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
{% stylesheet screen media="screen" %}
{% stylesheet source-mac_classic media="screen" %}
+ {% javascript main %}
<meta content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport" />
</head>
<body>
View
@@ -0,0 +1,21 @@
+// add anchors to each section header
+(function()
+{
+
+ // old browsers suck. not using jQuery here to keep things snappy
+ if (!document.addEventListener || !document.querySelectorAll) return;
+
+ document.addEventListener("DOMContentLoaded", function()
+ {
+ var headers = document.querySelectorAll('h1[id],h2[id],h3[id]');
+ for (var idxHeader = 0; idxHeader < headers.length; ++idxHeader)
+ {
+ var header = headers[idxHeader];
+ var anchor = document.createElement('a');
+ anchor.href = '#'+header.id;
+ anchor.className = 'section_anchor';
+ header.appendChild(anchor);
+ }
+ }, false);
+
+})();
View
@@ -28,6 +28,23 @@ h1, h2, h3, h4, h5, h6
& + *
margin-top: 0
+a.section_anchor
+ display: none
+ margin-left: 0.5em
+ font-size: 80%
+ position: relative
+ top: -0.15em
+ &:before
+ content: "\00B6"
+h1, h2, h3, h4, h5, h6
+ &:hover a.section_anchor
+ display: inline
+ color: #ccc
+ text-decoration: none
+ &:hover
+ color: #33c
+ text-decoration: none
+
article > header
h1
margin-bottom: 0

0 comments on commit 9f8eb99

Please sign in to comment.