forked from restify/node-restify
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
107 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<script type="text/javascript" charset="utf-8"> | ||
$(function() { | ||
var headerHeight = $("#header").height(); | ||
|
||
var sections = $("#content h1[id], #content h2[id]"); | ||
var sectionOffsets = []; | ||
var slack = 100; // Give the section scroll some slack (in pixels). | ||
sections.each(function(elem) { | ||
sectionOffsets.push($(this).offset().top - headerHeight - slack); | ||
}); | ||
|
||
var currSectionIdx = -1; | ||
function getSectionIdx(scrollDistance) { | ||
if (scrollDistance < sectionOffsets[0]) { | ||
return -1; | ||
} else { | ||
for (var id = sectionOffsets.length; id > 0; id--) { | ||
if (scrollDistance > sectionOffsets[id - 1]) { | ||
return id - 1; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** {{{ http://code.activestate.com/recipes/577787/ (r2) */ | ||
_slugify_strip_re = /[^\w\s-]/g; | ||
_slugify_hyphenate_re = /[-\s]+/g; | ||
function slugify(s) { | ||
s = s.replace(_slugify_strip_re, '').trim().toLowerCase(); | ||
s = s.replace(_slugify_hyphenate_re, '-'); | ||
return s; | ||
} | ||
/** end of http://code.activestate.com/recipes/577787/ }}} */ | ||
|
||
|
||
$("#content").scroll(function() { | ||
var scrollDistance = $("#content").attr('scrollTop'); | ||
var sectionIdx = getSectionIdx(scrollDistance); | ||
|
||
if (sectionIdx !== currSectionIdx) { | ||
$("#sidebar li>div").removeClass("current"); | ||
currSectionIdx = sectionIdx; | ||
if (currSectionIdx >= 0) { | ||
var heading = $(sections[currSectionIdx]).text(); | ||
var possibleAnchors = [ | ||
slugify(heading), // h1 or non-method h2 | ||
heading.replace(/ /g, '-'), // h2 method, just name or just endpoint | ||
heading.slice(0, heading.lastIndexOf(' (')).trimRight().replace(/ /g, '-'), // h2 method, name and endpoint | ||
] | ||
for (var i=0; i < possibleAnchors.length; i++) { | ||
$("#sidebar a[href|=#" + possibleAnchors[i] + "]").parent().addClass("current"); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>%(title)s</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<link rel="stylesheet" type="text/css" href="%(mediaroot)s/css/restdown.css"> | ||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | ||
</head> | ||
<body> | ||
<a href="http://github.com/mcavage/node-restify"> | ||
<img style="position: absolute; top: 0; right: 0; border: 0; z-index: 3;" | ||
src="https://a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" | ||
alt="Fork me on GitHub"/ > | ||
</a> | ||
<div id="header"> | ||
<h1>%(title)s Documentation</h1> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Binary file not shown.