main.ts 1.2 KB

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