summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHubert Argasinski <argasinski.hubert@gmail.com>2016-10-07 20:39:59 -0400
committerHubert Argasinski <argasinski.hubert@gmail.com>2016-10-07 20:39:59 -0400
commit0b7ebe43f0e18fe7894f52d018cb9846850fdca3 (patch)
treeb61209cae8e267216663557df6f5602b0e7d30d8
parent06b1c9c9f94a4c503426c1377cf89d7cce49f6a5 (diff)
downloadasync-0b7ebe43f0e18fe7894f52d018cb9846850fdca3.tar.gz
docs: added Bootstrap scroll-spy
-rw-r--r--support/jsdoc/jsdoc-fix-html.js44
-rw-r--r--support/jsdoc/theme/static/styles/jsdoc-default.css26
-rw-r--r--support/jsdoc/theme/tmpl/layout.tmpl10
3 files changed, 55 insertions, 25 deletions
diff --git a/support/jsdoc/jsdoc-fix-html.js b/support/jsdoc/jsdoc-fix-html.js
index b199d2a..531ba5a 100644
--- a/support/jsdoc/jsdoc-fix-html.js
+++ b/support/jsdoc/jsdoc-fix-html.js
@@ -11,6 +11,7 @@ var pageTitle = 'Methods:';
var docFilename = 'docs.html';
var mainModuleFile = 'module-async.html';
var mainSectionId = '#main';
+var mainScrollableSection = '#main-container';
var sectionTitleClass = '.page-title';
var HTMLFileBegin = '<!DOCTYPE html>\n<html lang="en">\n<head>\n';
@@ -74,7 +75,7 @@ function combineFakeModules(files, callback) {
var $modulePage = $(moduleData);
var moduleName = $modulePage.find(sectionTitleClass).text();
$modulePage.find(sectionTitleClass).attr('id', moduleName.toLowerCase());
- $mainPage.find(mainSectionId).append($modulePage.find(mainSectionId).html());
+ $mainPage.find(mainScrollableSection).append($modulePage.find(mainScrollableSection).html());
return fileCallback();
});
}, function(err) {
@@ -109,16 +110,7 @@ function applyPreCheerioFixes(data) {
}
-function fixToc($page, moduleFiles) {
- // remove `async` listing from toc
- $page.find('a[href="'+mainModuleFile+'"]').parent().remove();
-
- // change toc title
- var $nav = $page.find('nav');
- $nav.attr('id', 'toc');
- $nav.children('h3').text(pageTitle);
- $nav.children('h2').remove();
-
+function scrollSpyFix($page, $nav) {
// move everything into one big ul (for Bootstrap scroll-spy)
var $ul = $nav.children('ul');
$ul.addClass('nav').addClass('methods');
@@ -138,6 +130,26 @@ function fixToc($page, moduleFiles) {
$(this).addClass("toc-method");
});
+ $page.find('[id^="."]').each(function() {
+ var $ele = $(this);
+ var id = $(this).attr('id');
+ $ele.attr('id', id.replace('.', ''));
+ });
+}
+
+function fixToc(file, $page, moduleFiles) {
+ // remove `async` listing from toc
+ $page.find('a[href="'+mainModuleFile+'"]').parent().remove();
+
+ // change toc title
+ var $nav = $page.find('nav');
+ $nav.attr('id', 'toc');
+ $nav.children('h3').text(pageTitle);
+ $nav.children('h2').remove();
+
+ scrollSpyFix($page, $nav);
+
+ var prependFilename = (file === docFilename) ? '' : docFilename;
// make everything point to the same 'docs.html' page
_.each(moduleFiles, function(filename) {
$page.find('[href^="'+filename+'"]').each(function() {
@@ -147,10 +159,10 @@ function fixToc($page, moduleFiles) {
// category titles should sections title, while everything else
// points to the correct listing
if (href === filename) {
- var moduleName = $ele.text().toLowerCase().replace(/\s/g, '');
- $ele.attr('href', docFilename+'#'+moduleName);
+ var moduleName = $ele.text().toLowerCase().replace(/\s/g, '').replace('.', '');
+ $ele.attr('href', prependFilename+'#'+moduleName);
} else {
- $ele.attr('href', href.replace(filename, docFilename));
+ $ele.attr('href', href.replace(filename, prependFilename).replace('#.', '#'));
}
});
});
@@ -160,7 +172,7 @@ function fixFooter($page) {
// add a note to the footer that the documentation has been modified
var $footer = $page.find('footer');
$footer.append(additionalFooterText);
- $page.find('#main').append($footer);
+ $page.find(mainScrollableSection).append($footer);
}
function fixModuleLinks(files, callback) {
@@ -173,7 +185,7 @@ function fixModuleLinks(files, callback) {
if (err) return fileCallback(err);
var $file = $(applyPreCheerioFixes(fileData));
- fixToc($file, moduleFiles);
+ fixToc(file, $file, moduleFiles);
fixFooter($file);
$file.find('[href="'+mainModuleFile+'"]').attr('href', docFilename);
generateHTMLFile(filePath, $file, fileCallback);
diff --git a/support/jsdoc/theme/static/styles/jsdoc-default.css b/support/jsdoc/theme/static/styles/jsdoc-default.css
index 09825ff..703e85f 100644
--- a/support/jsdoc/theme/static/styles/jsdoc-default.css
+++ b/support/jsdoc/theme/static/styles/jsdoc-default.css
@@ -112,18 +112,25 @@ tt, code, kbd, samp {
bottom: 0;
float: none;
min-width: 360px;
- overflow-y: auto;
- padding-left: 16px;
- padding-right: 16px;
+ overflow-y: hidden;
+}
+
+#main-container {
+ position: relative;
+ width: 100%;
+ height: 100%;
+ overflow-y: scroll;
+ padding-left: 16px;
+ padding-right: 16px;
}
-#main h1 {
+#main-container h1 {
margin-top: 100px !important;
padding-top: 0px;
border-left: 2px solid #3391FE;
}
-#main h4 {
+#main-container h4 {
margin-top: 120px !important;
padding-top: 0px;
padding-left: 16px;
@@ -158,6 +165,11 @@ section, h1 {
margin-top: 10px;
}
+#toc > .methods > .toc-method {
+ padding: 0px;
+ margin: 0px 10px;
+}
+
#toc > .methods > .toc-method > a,
#toc > .methods > .toc-method > a.active {
padding: 0px 0px 0px 20px;
@@ -165,6 +177,10 @@ section, h1 {
color: #98999A;
}
+#toc > .methods > .toc-method.active {
+ background-color: #E8E8E8;
+}
+
.nav.navbar-right .navbar-form {
padding: 0;
margin: 6px 0px;
diff --git a/support/jsdoc/theme/tmpl/layout.tmpl b/support/jsdoc/theme/tmpl/layout.tmpl
index fd998bb..983562e 100644
--- a/support/jsdoc/theme/tmpl/layout.tmpl
+++ b/support/jsdoc/theme/tmpl/layout.tmpl
@@ -66,11 +66,13 @@
<label for="nav-trigger" class="overlay"></label>
<div id="main">
- <?js if (title != 'Home') { ?>
- <h1 class="page-title"><?js= title ?></h1>
- <?js } ?>
+ <div id="main-container" data-spy="scroll" data-target="#toc" data-offset="50">
+ <?js if (title != 'Home') { ?>
+ <h1 class="page-title"><?js= title ?></h1>
+ <?js } ?>
- <?js= content ?>
+ <?js= content ?>
+ </div>
</div>
<nav>