Files
DiscoTOC/javascripts/discourse/components/toc-mini.gjs
T
锦心 830c0436c8 FEATURE: Allow TOC for replies (#90)
* 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.
2024-08-07 15:40:11 +08:00

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>
}