Welcome to mirror list, hosted at ThFree Co, Russian Federation.

setup_table_of_contents.js « default « frontend « content - gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5f0c7d73e8d3aefa990b447a5cbea3459718eeaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* global Vue */
import { parseTOC } from '../shared/toc/parse_toc';
import TableOfContents from './components/table_of_contents.vue';
import { StickToFooter } from './directives/stick_to_footer';

const SIDEBAR_SELECTOR = '.doc-nav';
const MARKDOWN_TOC_ID = 'markdown-toc';
const MAIN_SELECTOR = '.js-main-wrapper';

export const setupTableOfContents = () => {
  const sidebar = document.querySelectorAll(SIDEBAR_SELECTOR);
  const menu = document.getElementById(MARKDOWN_TOC_ID);
  const main = document.querySelector(MAIN_SELECTOR);

  if (!sidebar || !menu) {
    return null;
  }

  if (main) {
    main.classList.add('has-toc');
  }

  const items = parseTOC(menu);
  menu.remove();

  const el = document.createElement('div');
  return sidebar.forEach((sidebarEl) => {
    sidebarEl.appendChild(el);
    return new Vue({
      el,
      directives: {
        StickToFooter,
      },
      render(h) {
        return h(TableOfContents, {
          props: {
            items,
          },
          directives: [
            {
              name: 'stick-to-footer',
              value: MAIN_SELECTOR,
              expression: MAIN_SELECTOR,
            },
          ],
        });
      },
    });
  });
};