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: 8fb5dc693683b491097d4c49617f089b4fc6bff8 (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
51
52
53
import Vue from 'vue';
import TableOfContents from './components/table_of_contents.vue';
import StickToFooter from './directives/stick_to_footer';
import { parseTOC } from '../shared/dom_parse_toc';

const SIDEBAR_ID = 'doc-nav';
const MARKDOWN_TOC_ID = 'markdown-toc';
const HELP_AND_FEEDBACK_ID = 'help-and-feedback';
const MAIN_SELECTOR = '.js-main-wrapper';

export default () => {
  const sidebar = document.getElementById(SIDEBAR_ID);
  const menu = document.getElementById(MARKDOWN_TOC_ID);
  const main = document.querySelector(MAIN_SELECTOR);
  const hasHelpAndFeedback = Boolean(document.getElementById(HELP_AND_FEEDBACK_ID));

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

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

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

  const el = document.createElement('div');
  sidebar.appendChild(el);

  return new Vue({
    el,
    directives: {
      StickToFooter,
    },
    render(h) {
      return h(TableOfContents, {
        props: {
          items,
          helpAndFeedbackId: HELP_AND_FEEDBACK_ID,
          hasHelpAndFeedback,
        },
        directives: [
          {
            name: 'stick-to-footer',
            value: MAIN_SELECTOR,
            expression: MAIN_SELECTOR,
          },
        ],
      });
    },
  });
};