Skip to content

Commit

Permalink
Small improvments on js (async-aws#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse authored Apr 4, 2020
1 parent dea96cd commit fc99cd6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
23 changes: 10 additions & 13 deletions website/assets/script/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@

// The toggle button
document.getElementById("sidebarCollapse").addEventListener("click", function(){
document.getElementById("sidebar").classList.toggle("active");
document.getElementById('sidebarCollapse').addEventListener('click', () => {
document.getElementById('sidebar').classList.toggle('active');
});

let isUlHidden = function (ul) {
const isUlHidden = (ul) => {
return !ul.classList.contains('show');
};


// The submenu
const elements = document.getElementsByClassName('dropdown-toggle');
for (const element of elements) {
element.addEventListener("click", () => {
for (const element of document.getElementsByClassName('dropdown-toggle')) {
element.addEventListener('click', () => {
let el = element;
let ul = undefined;

while (el = el.nextSibling ) {
while (el = el.nextSibling) {
if (el.nodeName.toLowerCase() === 'ul') {
ul = el;
break;
Expand All @@ -30,12 +27,12 @@ for (const element of elements) {

// Start the toggle
if (isUlHidden(ul)) {
ul.classList.add("show");
element.classList.remove("collapsed");
ul.classList.add('show');
element.classList.remove('collapsed');
element.setAttribute('aria-expanded', true);
} else {
ul.classList.remove("show");
element.classList.add("collapsed");
ul.classList.remove('show');
element.classList.add('collapsed');
element.setAttribute('aria-expanded', false);
}
});
Expand Down
11 changes: 5 additions & 6 deletions website/post-process/header-links.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module.exports = function(dom) {
dom.window.document.querySelectorAll('h2, h3').forEach((headline) => {
for(const headline of dom.window.document.querySelectorAll('h2, h3')) {
const id = headline.getAttribute('id');
const link = dom.window.document.createElement('a');

let id = headline.getAttribute('id');
let link = dom.window.document.createElement('a');
link.setAttribute('href', '#' + id);
link.setAttribute('title', 'Permalink to this headline');
link.setAttribute('class', 'headerlink');
link.innerHTML = '¶';
headline.innerHTML = headline.innerHTML + link.outerHTML;
});
headline.append(link);
}
};

5 changes: 2 additions & 3 deletions website/post-process/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ highlight.registerLanguage('shell', require('highlight.js/lib/languages/bash'));
highlight.registerLanguage('yaml', require('highlight.js/lib/languages/yaml'));

module.exports = function(dom) {
dom.window.document.querySelectorAll('pre code').forEach((block) => {
for (const block of dom.window.document.querySelectorAll('pre code')) {
if (!block.classList.contains('hljs')) {
highlight.highlightBlock(block);
}
});
}
};

8 changes: 4 additions & 4 deletions website/post-process/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const fs = require('fs');
const jsdom = require("jsdom");
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const walk = require('./walk');

let highlight = require('./highlight')
let headerLinks = require('./header-links')
const highlight = require('./highlight')
const headerLinks = require('./header-links')

const outputDir = process.argv[2];
console.log('Dir: ', outputDir);
Expand All @@ -24,7 +24,7 @@ walk(outputDir, function (err, files) {
// Only write the file once
fs.writeFile(file, dom.serialize(), function (err) {
if (err) return console.log(err);
console.log("Done: "+file);
console.log('Done: '+file);
});
});
});
Expand Down
10 changes: 5 additions & 5 deletions website/post-process/walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const path = require('path');
* Read directory for files.
* @see https://stackoverflow.com/a/5827895/1526789
*/
let walk = function(dir, done) {
const walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var pending = list.length;
let pending = list.length;
if (!pending) return done(null, results);
list.forEach(function(file) {
file = path.resolve(dir, file);
for(const filePath of list) {
const file = path.resolve(dir, filePath);
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
Expand All @@ -24,7 +24,7 @@ let walk = function(dir, done) {
if (!--pending) done(null, results);
}
});
});
};
});
};

Expand Down

0 comments on commit fc99cd6

Please sign in to comment.