caddy-website/src/old/resources/js/module-docs.js
Matt Holt 07c51663ab
New Website: Phase I (#357)
* Initial commit; starting new design

Dropdown menu

* Begin docs layout of new design

* Get themes under control; button hover splash

* Some basic responsiveness

* Finish responsive layout; several bug fixes

* Avoid flash during color scheme change

* Begin building top of homepage

* docs: Start building quick-assist feature

* Work on homepage a little more

* Keep working on homepage

* More homepage progress

* Some sponsor SVGs

* Add sponsor features

* Implement basic Sponsor Experience box

* Reorganize some styles

* WIP sponsors page

* Start features page WIP

* Minor improvements

* Fix headings; work on features page

* WIP features page

* Continue work on marketing pages

* Continue work on features page

* More features WIP

* Continue features page...

* More work on features page

* Keeping going  :)

* Continue home and features pages

* More homepage/features content, screenshots, tweaks

* Minor fixes to features page

* Minor tweaks

* Work on testimonials

* Work on homepage more

* More homepage work

* Continue work on homepage

* Add some sponsor logos

* Some citation screenshots

* Add citations

* Start making homepage responsive

* Re-add cache busting

Fix docs

* Use markdown syntax highlighting on frontpage

* Rework AJQuery to $_ to not interfere with jQuery

* Rewrite quick assist with AlpineJS, use markdown for contents

* More work on marketing pages

* Rebase and fix code displays

* Syntax highlight on-demand example, fix rollover

* Adjust on-demand demo

* Work on responsiveness

* Keep working on responsiveness

* Mainly finish making design responsive

* Thiccer favicon

* More work on marketing pages

* Keep on going

* Fix link

* Move new site into src folder

* Add open graph image

* Add recorded demo for homepage

* Tweak caption

* Fix Poppins font for now

* Minor tweaks

* Trim demo ending

* Remove unfinished pages

Also update Framer logo

---------

Co-authored-by: Francis Lavoie <lavofr@gmail.com>
2023-12-11 10:07:34 -07:00

92 lines
3 KiB
JavaScript

const moduleDocsPathPrefix = "/docs/modules/";
var moduleID = window.location.pathname.substr(moduleDocsPathPrefix.length);
if (moduleID) {
// update page title and load the docs for these modules (possibly more than 1 with this ID)
document.title = "Module " + moduleID + " - Caddy Documentation";
$.get("/api/docs/module/"+moduleID, function(json) {
var modules = json.result;
// wait until the DOM has finished loading before rendering the results
$(function() {
$('#module-docs-container').show();
$('.module-name').text("Module "+moduleID);
modules.forEach((module) => {
$tpl = $('#module-template').clone().attr('id', stripScheme(module.repo));
if (modules.length > 1) {
$('article', $tpl).hide();
}
beginRenderingInto($tpl, moduleID, module);
$('#module-docs-container').append($tpl);
});
if (modules.length > 1) {
$('#module-multiple-repos .module-name').text(moduleID);
$('#module-multiple-repos').show();
} else {
$('.module-repo-selector').hide();
}
// if a specific repo's module is wanted, expand and scroll to it
if (window.location.hash.length > 1) {
// TODO: weird bug in jQuery(??) that it can't select IDs with slashes in them, so we use vanilla JS
var container = document.getElementById(window.location.hash.substr(1));
$('.module-repo-selector', container).click();
container.scrollIntoView();
}
});
});
$(function() {
$('body').on('click', '.module-repo-selector', function() {
if ($(this).hasClass('expanded')) {
// collapse
$('.module-repo-selector-arrow', this).html('&#9656;');
} else {
// expand
$('.module-repo-selector-arrow', this).html('&#9662;');
}
$(this).toggleClass('expanded');
$(this).next('article').toggle();
});
});
} else {
// populate the module list
$.get("/api/modules", function(json) {
var moduleList = json.result;
console.log("MODULE LIST:", moduleList);
// wait until the DOM has finished loading before rendering the results
$(function() {
$('#module-list-container').show();
$table = $('#module-list');
for (modID in moduleList) {
var infos = moduleList[modID];
infos.forEach((info) => {
// refine a short preview of the module's docs
let shortDoc = truncate(info.docs, 200);
if (shortDoc && shortDoc.indexOf(modID) === 0) {
shortDoc = shortDoc.substr(modID.length).trim();
}
let modLink = "./"+modID;
if (infos.length > 1) {
modLink += "#"+stripScheme(info.repo);
}
var standard = isStandard(info.package);
var $tr = $('<tr/>');
$tr.append('<td>'+(standard ? standardFlag : nonStandardFlag)+'</td>');
var $tdLink = $('<td><a href="'+modLink+'" class="module-link">'+modID+'</a></td>');
if (infos.length > 1) {
$tdLink.append($('<div class="module-repo-differentiator">').text('('+stripScheme(info.repo)+')'));
}
$tr.append($tdLink);
$tr.append($('<td/>').text(shortDoc));
$table.append($tr);
});
}
});
});
}