mirror of
https://github.com/discourse/DiscoTOC.git
synced 2026-09-16 15:32:13 -04:00
* FEATURE: Allow TOC for replies This commit adds an optional setting that allows enabling a TOC for replies. TOCs for replies are not affected by autoTOC settings like `auto_TOC_tags` and must be inserted manually.
52 lines
1.1 KiB
Plaintext
52 lines
1.1 KiB
Plaintext
import Component from "@glimmer/component";
|
|
import { action } from "@ember/object";
|
|
import { service } from "@ember/service";
|
|
import DButton from "discourse/components/d-button";
|
|
|
|
export default class TocMini extends Component {
|
|
@service tocProcessor;
|
|
|
|
@action
|
|
clickOutside() {
|
|
this.tocProcessor.setOverlayVisible(false);
|
|
this.removeClickOutsideListener();
|
|
}
|
|
|
|
@action
|
|
addClickOutsideListener() {
|
|
document.addEventListener("click", this.clickOutside);
|
|
}
|
|
|
|
@action
|
|
toggleTOCOverlay() {
|
|
this.tocProcessor.toggleOverlay();
|
|
if (this.tocProcessor.isOverlayVisible) {
|
|
this.addClickOutsideListener();
|
|
} else {
|
|
this.removeClickOutsideListener();
|
|
}
|
|
}
|
|
|
|
@action
|
|
removeClickOutsideListener() {
|
|
document.removeEventListener("click", this.clickOutside);
|
|
}
|
|
|
|
willDestroy() {
|
|
super.willDestroy(...arguments);
|
|
this.removeClickOutsideListener();
|
|
}
|
|
|
|
<template>
|
|
{{#if this.tocProcessor.hasTOC}}
|
|
<span class="d-toc-mini">
|
|
<DButton
|
|
class="btn-primary"
|
|
@icon="stream"
|
|
@action={{this.toggleTOCOverlay}}
|
|
/>
|
|
</span>
|
|
{{/if}}
|
|
</template>
|
|
}
|