Show:
(require("TableOfContents"))(props) → {TableOfContents}
...
Initializes the sidebar's Table of Contents.
Parameters:
Name | Type | Description |
---|---|---|
props |
TableOfContentsProps |
Returns:
- Type
- TableOfContents
Members
(inner) activeSubSection :HTMLElement|undefined
...
(inner) activeTopSection :HTMLElement|undefined
...
(inner) expandedSections :Array.<HTMLElement>
...
(inner, constant) tableOfContentsConfig
...
TableOfContents Config object for filling mustache templates
(inner, constant) templateTocContents
...
TableOfContents Mustache templates
Methods
(inner) activateSection(id)
...
Sets an `ACTIVE_SECTION_CLASS` on the element with an id that matches `id`.
Sets an `ACTIVE_TOP_SECTION_CLASS` on the top level heading (e.g. element with the
`TOP_SECTION_CLASS`).
If the element is a top level heading, the element will have both classes.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The id of the element to be activated in the Table of Contents. |
(inner) bindHashChangeListener()
...
Bind event listener for hash change events that match the hash of
LINK_CLASS.
Note that if the user clicks a link inside the TOC, the onHeadingClick
callback will fire instead of the onHashChange callback, since it takes
precedence.
(inner) bindPinnedToggleListeners()
...
Bind event listener for clicking on show/hide Table of Contents links.
(inner) bindSubsectionToggleListeners()
...
Bind event listeners for clicking on section headings and toggle buttons.
(inner) changeActiveSection(id)
...
(inner) collapseSections(selectedIdsopt)
...
Removes all `EXPANDED_SECTION_CLASS` CSS class names
from the top level sections in the ToC.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
selectedIds |
Array.<string> |
<optional> |
(inner) deactivateSections()
...
Removes the `ACTIVE_SECTION_CLASS` from all ToC sections.
(inner) expandSection(id)
...
Adds the `EXPANDED_SECTION_CLASS` CSS class name
to a top level heading in the ToC.
Parameters:
Name | Type | Description |
---|---|---|
id |
string |
(inner) getActiveSectionIds() → {activeSectionIds}
...
(inner) getExpandedSectionIds() → {Array.<string>}
...
Get the IDs of expanded sections.
Returns:
- Type
- Array.<string>
(inner) getTableOfContentsData(sections) → {SectionsListData}
...
(inner) getTableOfContentsHTML(sections) → {string}
...
Generates the HTML for the table of contents.
Parameters:
Name | Type | Description |
---|---|---|
sections |
Array.<Section> |
Returns:
- Type
- string
(inner) getTableOfContentsListHtml(data) → {string}
...
Generates the table of contents List HTML from the templates
Parameters:
Name | Type | Description |
---|---|---|
data |
Object |
Returns:
- Type
- string
(inner) getTableOfContentsSectionsData(sections, toclevel) → {Array.<Section>}
...
Prepares the data for rendering the table of contents,
nesting child sections within their parent sections.
This should yield the same result as the php function
VectorComponentTableOfContents::getTemplateData(),
please make sure to keep them in sync.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
sections |
Array.<Section> | ||
toclevel |
number | 1 |
Returns:
- Type
- Array.<Section>
(inner) handleHashChange()
...
Event handler for hash change event.
(inner) initialize()
...
Binds event listeners and sets the default state of the component.
(inner) initializeExpandedStatus()
...
Set aria-expanded attribute for all toggle buttons.
(inner) isTopLevelSection(id) → {boolean}
...
Parameters:
Name | Type | Description |
---|---|---|
id |
string |
Returns:
- Type
- boolean
(inner) prefersReducedMotion() → {boolean}
...
Does the user prefer reduced motion?
Returns:
- Type
- boolean
(inner) reExpandSections()
...
Reexpands all sections that were expanded before the table of contents was reloaded.
Edited Sections are not reexpanded, as the ID of the edited section is changed after reload.
(inner) reloadPartialHTML(elementId, html)
...
Replaces the contents of the given element with the given HTML
Parameters:
Name | Type | Description |
---|---|---|
elementId |
string | |
html |
string |
(inner) reloadTableOfContents(sections) → {Promise.<any>}
...
Reloads the table of contents from saved data
Parameters:
Name | Type | Description |
---|---|---|
sections |
Array.<Section> |
Returns:
- Type
- Promise.<any>
(inner) scrollToActiveSection(id)
...
Scroll active section into view if necessary
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The id of the element to be scrolled to in the Table of Contents. |
(inner) toggleExpandSection(id)
...
(inner) unbindHashChangeListener()
...
Unbinds event listener for hash change events.
(inner) updateTocToggleStyles(scrollBelow)
...
Updates button styling for the TOC toggle button when scrolled below the page title
Parameters:
Name | Type | Description |
---|---|---|
scrollBelow |
boolean |
Type Definitions
activeSectionIds
...
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
parent |
string
|
undefined
|
The active top level section ID |
child |
string
|
undefined
|
The active subsection ID |
ArraySectionsData
...
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
number-section-count |
number | |
array-sections |
Array.<Section> |
onHashChange(id)
...
Fired when the page's hash fragment has changed. Note that if the user clicks
a link inside the TOC, the `onHeadingClick` callback will fire instead of the
`onHashChange` callback to avoid redundant behavior.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The id of the list item that corresponds to the hash change event. |
onHeadingClick(id)
...
Fired when the user clicks a toc link. Note that this callback takes
precedence over the onHashChange callback. The onHashChange callback will not
be called when the user clicks a toc link.
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The id of the clicked list item. |
onToggleClick(id)
...
Parameters:
Name | Type | Description |
---|---|---|
id |
string | The id of the list item corresponding to the arrow. |
Section
...
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
toclevel |
number | |
anchor |
string | |
line |
string | |
number |
string | |
index |
string | |
byteoffset |
number | |
fromtitle |
string | |
is-parent-section |
boolean | |
is-top-level-section |
boolean | |
array-sections |
Array.<Section> | |
level |
string |
SectionsListData
...
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
is-vector-toc-beginning-enabled |
boolean | |
array-sections |
Array.<Section> | |
vector-is-collapse-sections-enabled |
boolean | |
msg-vector-toc-beginning |
string |
tableOfContents(props) → {TableOfContents}
...
TableOfContents
...
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
reloadTableOfContents |
reloadTableOfContents | |
changeActiveSection |
changeActiveSection | |
expandSection |
expandSection | |
toggleExpandSection |
toggleExpandSection | |
updateTocToggleStyles |
updateTocToggleStyles | |
unmount |
unmount | |
ACTIVE_SECTION_CLASS |
string | |
ACTIVE_TOP_SECTION_CLASS |
string | |
EXPANDED_SECTION_CLASS |
string | |
LINK_CLASS |
string | |
TOGGLE_CLASS |
string |
TableOfContentsProps
...
Type:
- Object
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
container |
HTMLElement | The container element for the table of contents. | |
onHeadingClick |
onHeadingClick | Called when an arrow is clicked. | |
onHashChange |
onHashChange | Called when a hash change event matches the id of a LINK_CLASS anchor element. | |
onToggleClick |
onToggleClick |
<optional> |
Called when an arrow is clicked. |
onTogglePinned |
onTogglePinned | Called when pinned toggle buttons are clicked. |