conventionalcommits.org/themes/conventional-commits/static/js/index.js
2018-09-16 23:40:02 +02:00

38 lines
815 B
JavaScript

import AnchorJS from 'anchor-js';
class App {
constructor(anchors) {
this.anchors = anchors;
this.onInit();
}
_addEventListeners() {
// using 'load' instead of 'DOMContentLoaded' because we want to wait the css
// https://javascript.info/onload-ondomcontentloaded
window.addEventListener('load', () => {
// wrapped in a timeout for wait css parsing
setTimeout(() => this._onPageLoaded(), 0);
});
}
_onPageLoaded() {
this.removeLoadingClass();
}
onInit() {
this.addAnchorsLinks();
this._addEventListeners();
}
addAnchorsLinks() {
this.anchors.options = {placement: 'left'};
this.anchors.add();
}
removeLoadingClass() {
document.body.classList.remove('conventional-commits--loading');
}
}
const app = new App(new AnchorJS());