blob: 9ef592a3778b3ca09cc831c7b80fd1f2771c0b04 [file] [log] [blame]
/**
* @license
* Copyright 2020 The Go Authors. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
import { AccordionController } from './accordion.js';
/**
* Instantiates accordian controller for the left sidebar and sets
* the panel for the current location hash as active.
*/
const accordion = document.querySelector('.js-accordion');
if (accordion) {
const accordionCtlr = new AccordionController(accordion);
const activePanel =
window.location.hash &&
document.querySelector(`a[href=${JSON.stringify(window.location.hash)}]`);
if (activePanel) {
accordionCtlr.select(activePanel);
}
}
/**
* Event handlers for expanding and collapsing the readme section.
*/
const readme = document.querySelector('.js-readme');
const readmeExpand = document.querySelectorAll('.js-readmeExpand');
const readmeCollapse = document.querySelector('.js-readmeCollapse');
if (readmeExpand && readmeExpand && readmeCollapse) {
readmeExpand.forEach(el =>
el.addEventListener('click', e => {
e.preventDefault();
readme.classList.add('UnitReadme--expanded');
readme.scrollIntoView();
})
);
readmeCollapse.addEventListener('click', e => {
e.preventDefault();
readme.classList.remove('UnitReadme--expanded');
readme.scrollIntoView();
});
}