2024-01-31 10:22:06 -05:00
|
|
|
import Component from "@glimmer/component";
|
|
|
|
|
import { action } from "@ember/object";
|
2024-03-27 16:08:48 +01:00
|
|
|
import { service } from "@ember/service";
|
2024-01-31 10:22:06 -05:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 10:22:06 -05:00
|
|
|
@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">
|
2024-01-31 10:22:06 -05:00
|
|
|
<DButton
|
2026-03-13 14:23:35 +01:00
|
|
|
class="d-toc-mini__button"
|
2024-12-09 05:12:39 +08:00
|
|
|
@icon="bars-staggered"
|
2024-01-31 10:22:06 -05:00
|
|
|
@action={{this.toggleTOCOverlay}}
|
|
|
|
|
/>
|
2024-08-07 15:40:11 +08:00
|
|
|
</span>
|
2024-01-31 10:22:06 -05:00
|
|
|
{{/if}}
|
|
|
|
|
</template>
|
|
|
|
|
}
|