Files

52 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

import Component from "@glimmer/component";
import { action } from "@ember/object";
2024-03-27 16:08:48 +01:00
import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
export default class TocMini extends Component {
@service tocProcessor;
2024-11-20 17:36:46 +00:00
willDestroy() {
super.willDestroy(...arguments);
this.removeClickOutsideListener();
}
@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);
}
<template>
{{#if this.tocProcessor.hasTOC}}
2024-08-07 15:40:11 +08:00
<span class="d-toc-mini">
<DButton
class="d-toc-mini__button"
@icon="bars-staggered"
@action={{this.toggleTOCOverlay}}
/>
2024-08-07 15:40:11 +08:00
</span>
{{/if}}
</template>
}