0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 17:30:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/mixins/notice-message.js.es6

69 Zeilen
1,5 KiB
Text

2021-11-01 14:52:29 +01:00
import Mixin from "@ember/object/mixin";
import { bind, scheduleOnce } from "@ember/runloop";
import { cookAsync } from "discourse/lib/text";
import { createPopper } from "@popperjs/core";
export default Mixin.create({
showCookedMessage: false,
2021-11-17 13:48:11 +01:00
didReceiveAttrs() {
2021-11-01 14:52:29 +01:00
const message = this.notice.message;
cookAsync(message).then((cooked) => {
this.set("cookedMessage", cooked);
});
},
createMessageModal() {
2021-11-17 13:48:11 +01:00
let container = this.element.querySelector(".notice-message");
let modal = this.element.querySelector(".cooked-notice-message");
2021-11-01 14:52:29 +01:00
2021-11-17 13:48:11 +01:00
this._popper = createPopper(container, modal, {
strategy: "absolute",
placement: "bottom-start",
modifiers: [
{
name: "preventOverflow",
},
{
name: "offset",
options: {
offset: [0, 5],
2021-11-01 14:52:29 +01:00
},
2021-11-17 13:48:11 +01:00
},
],
});
2021-11-01 14:52:29 +01:00
},
didInsertElement() {
$(document).on("click", bind(this, this.documentClick));
},
willDestroyElement() {
$(document).off("click", bind(this, this.documentClick));
},
documentClick(event) {
2021-11-17 13:48:11 +01:00
if (this._state === "destroying") {
return;
}
2021-11-01 14:52:29 +01:00
2021-11-17 13:48:11 +01:00
if (
!event.target.closest(
`[data-notice-id="${this.notice.id}"] .notice-message`
)
) {
this.set("showCookedMessage", false);
2021-11-01 14:52:29 +01:00
}
},
actions: {
toggleCookedMessage() {
this.toggleProperty("showCookedMessage");
if (this.showCookedMessage) {
scheduleOnce("afterRender", this, this.createMessageModal);
}
2021-11-17 13:48:11 +01:00
},
},
});