summaryrefslogtreecommitdiff
path: root/support/jsdoc/jsdoc-fix-html.js
diff options
context:
space:
mode:
Diffstat (limited to 'support/jsdoc/jsdoc-fix-html.js')
-rw-r--r--support/jsdoc/jsdoc-fix-html.js57
1 files changed, 47 insertions, 10 deletions
diff --git a/support/jsdoc/jsdoc-fix-html.js b/support/jsdoc/jsdoc-fix-html.js
index a45b383..903d546 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';
@@ -21,6 +22,12 @@ var additionalFooterText = ' Documentation has been modified from the original.
' For more information, please see the <a href="https://github.com/caolan/async">async</a> repository.';
function generateHTMLFile(filename, $page, callback) {
+ var methodName = filename.match(/\/(\w+)\.js\.html$/);
+ if (methodName) {
+ var $thisMethodDocLink = $page.find('#toc').find('a[href="'+docFilename+'#'+methodName[1]+'"]');
+ $thisMethodDocLink.parent().addClass('active');
+ }
+
// generate an HTML file from a cheerio object
var HTMLdata = HTMLFileBegin + $page.find('head').html()
+ HTMLFileHeadBodyJoin + $page.find('body').html()
@@ -74,7 +81,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,14 +116,44 @@ function applyPreCheerioFixes(data) {
}
-function fixToc($page, moduleFiles) {
+function scrollSpyFix($page, $nav) {
+ // move everything into one big ul (for Bootstrap scroll-spy)
+ var $ul = $nav.children('ul');
+ $ul.addClass('nav').addClass('methods');
+ $ul.find('.methods').each(function() {
+ var $methodsList = $(this);
+ var $methods = $methodsList.find('[data-type="method"]');
+ var $parentLi = $methodsList.parent();
+
+ $methodsList.remove();
+ $methods.remove();
+ $parentLi.after($methods);
+ $parentLi.addClass('toc-header');
+
+ });
+
+ $page.find('[data-type="method"]').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('li').find('a[href="'+mainModuleFile+'"]').parent().remove();
+ $page.find('a[href="'+mainModuleFile+'"]').parent().remove();
// change toc title
- $page.find('nav').children('h3').text(pageTitle);
- $page.find('nav').children('h2').remove();
+ 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() {
@@ -126,10 +163,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('#.', '#'));
}
});
});
@@ -139,7 +176,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) {
@@ -152,7 +189,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);