main.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. // import '@webcomponents/custom-elements';
  2. import { SearchWidget } from './search-widget';
  3. import { TocHighlighter } from './toc-highlighter';
  4. // tslint:disable-next-line
  5. require('../styles/main.scss');
  6. document.addEventListener('DOMContentLoaded', () => {
  7. const topBar = document.querySelector('.top-bar');
  8. if (topBar) {
  9. window.addEventListener('scroll', (e) => {
  10. if (window.scrollY === 0) {
  11. topBar.classList.remove('floating');
  12. } else {
  13. topBar.classList.add('floating');
  14. }
  15. });
  16. }
  17. const toc = document.querySelector('#TableOfContents');
  18. if (toc) {
  19. const tocHighlighter = new TocHighlighter(toc);
  20. tocHighlighter.highlight();
  21. }
  22. const searchInput = document.querySelector('#searchInput') as HTMLInputElement;
  23. const searchWidget = new SearchWidget(searchInput);
  24. const searchButton = document.querySelector('button.search-icon') as HTMLButtonElement;
  25. searchButton.addEventListener('click', () => searchWidget.toggleActive());
  26. }, false);