Commits

David Chambers committed d1b34fb

Added "pilcrow" permalinks to default template (à la djangoproject.com).

Comments (0)

Files changed (2)

static/default.css

 
 input[type="submit"]::-moz-focus-inner          { border: none; }
 
+.permalink                                      { visibility: hidden; margin: 0 0 0 0.25em; }
+h1:hover .permalink, h2:hover .permalink,
+h3:hover .permalink, h4:hover .permalink,
+h5:hover .permalink, h6:hover .permalink        { visibility: visible; }
+
 html                                            { height: 100%; }
 body                                            { margin: 0; height: 100%; background: rgb(5, 30, 40); padding: 0; font: 16px/1.5em Helvetica, Arial, sans-serif; color: #333; text-shadow: 0 1px 0 #fff; }
   #wrap                                         { margin: -48px auto 0; width: 70%; max-width: 48em; min-width: 504px; min-height: 100%;

templates/base.dhtml

 		<p>Powered by <a href="http://mango.io/">Mango</a></p>
 	</footer>{% for script in scripts %}
 	<script src="{{ script }}"></script>{% endfor %}
+	<script type="text/javascript">
+		(function () {
+
+			// thanks Douglas Crockford for this elegant function
+			function walkTheDOM(node, func) {
+				func(node);
+				node = node.firstChild;
+				while (node) {
+					walkTheDOM(node, func);
+					node = node.nextSibling;
+				}
+			}
+
+			var nodeNames = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
+			nodeNames.contains = function (nodeName) {
+				var i = this.length;
+				while (i--) {
+					if (this[i] === nodeName) return true;
+				}
+				return false;
+			};
+
+			walkTheDOM(document.body, function (node) {
+				if (node.id && nodeNames.contains(node.nodeName)) {
+					var a = document.createElement('a');
+					a.href = '#' + node.id;
+					a.className = 'permalink';
+					a.appendChild(document.createTextNode('\u00B6')); // pilcrow
+					node.appendChild(a);
+				}
+			});
+
+		}());
+	</script>
 	<!-- Generated by Mango -->
 </body>
 </html>