groton-school / knowledgebase

Knowledgebase website
https://kb.groton.org
GNU General Public License v3.0
0 stars 0 forks source link

update TOC if scrolling through folder #3

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

https://api.github.com/groton-school/knowledgebase/blob/bf254e1df2af3aeae02f7fec48e6ffc3a20d4f16/src/UI/TOC.ts#L19


import Helper from '../Helper';
import * as OverDrive from '../OverDrive';
import './TOC.scss';

export default function TOC() {
  Helper.waitForSelector('h1, h2, h3' /*, h4, h5, h6'*/).then((headings) => {
    const panel = OverDrive.Panel.panel();
    panel.append(OverDrive.Panel.heading('On this page', '#'));
    const builder = new OverDrive.SubNav.Builder('gs-toc');
    headings.forEach((h) => {
      builder.add(h.innerText, `#${h.id}`, parseInt(h.tagName.substr(-1)) - 1);
    });
    panel.append(builder.finalize());
    document.querySelector('#od-col-subnav')?.prepend(panel);
    const subnav = document.querySelector('#od-subnav-heading');
    subnav!.innerHTML = 'Topics';
    Helper.log('TOC built');

    // FIXME update TOC if scrolling through folder
  });
}
battis commented 1 year ago

Probably a bunch of other things also need to be refreshed when the page is loaded dynamically. Set a watch on the location and re-call things?

github-actions[bot] commented 1 year ago

Closed in fe0ee88f3324b8c7d6e944456793479f46cf0413