The `break` in `Popover.ts` uses braces for all cases for consistency with the `State.None` case that introduces local variables.
function observe() {
document.querySelectorAll(".jsCollapsibleBbcode").forEach((container) => {
// find the matching toggle button
- const toggleButtons = [];
- container.querySelectorAll(".toggleButton:not(.jsToggleButtonEnabled)").forEach((button) => {
- if (button.closest(".jsCollapsibleBbcode") === container) {
- toggleButtons.push(button);
- }
+ const toggleButtons = Array.from(container.querySelectorAll(".toggleButton:not(.jsToggleButtonEnabled)")).filter((button) => {
+ return button.closest(".jsCollapsibleBbcode") === container;
});
const overflowContainer = container.querySelector(".collapsibleBbcodeOverflow") || container;
if (toggleButtons.length > 0) {
this.popover.appendChild(pointer);
document.body.appendChild(this.popover);
// event listener
- this.popover.addEventListener("mouseenter", this.popoverMouseEnter.bind(this));
+ this.popover.addEventListener("mouseenter", () => this.popoverMouseEnter());
this.popover.addEventListener("mouseleave", () => this.mouseLeave());
- this.popover.addEventListener("animationend", this.clearContent.bind(this));
+ this.popover.addEventListener("animationend", () => this.clearContent());
window.addEventListener("beforeunload", () => {
this.suspended = true;
if (this.timerEnter) {
}
const cacheId = elementData.element.dataset.cacheId;
const data = this.cache.get(cacheId);
- if (data.state === 2 /* Ready */) {
- this.popoverContent.appendChild(data.content);
- this.rebuild();
- }
- else if (data.state === 0 /* None */) {
- data.state = 1 /* Loading */;
- const handler = this.handlers.get(elementData.identifier);
- if (handler.loadCallback) {
- handler.loadCallback(elementData.objectId, this, elementData.element);
+ switch (data.state) {
+ case 2 /* Ready */: {
+ this.popoverContent.appendChild(data.content);
+ this.rebuild();
+ break;
+ }
+ case 0 /* None */: {
+ data.state = 1 /* Loading */;
+ const handler = this.handlers.get(elementData.identifier);
+ if (handler.loadCallback) {
+ handler.loadCallback(elementData.objectId, this, elementData.element);
+ }
+ else if (handler.dboAction) {
+ const callback = (data) => {
+ this.setContent(elementData.identifier, elementData.objectId, data.returnValues.template);
+ return true;
+ };
+ this.ajaxApi({
+ actionName: "getPopover",
+ className: handler.dboAction,
+ interfaceName: "wcf\\data\\IPopoverAction",
+ objectIDs: [elementData.objectId],
+ }, callback, callback);
+ }
+ break;
}
- else if (handler.dboAction) {
- const callback = (data) => {
- this.setContent(elementData.identifier, elementData.objectId, data.returnValues.template);
- return true;
- };
- this.ajaxApi({
- actionName: "getPopover",
- className: handler.dboAction,
- interfaceName: "wcf\\data\\IPopoverAction",
- objectIDs: [elementData.objectId],
- }, callback, callback);
+ case 1 /* Loading */: {
+ // Do not interrupt inflight requests.
+ break;
}
}
}
| any[];
}
-// Return `false` to suppress the error message.
+/** Return `false` to suppress the error message. */
export type CallbackFailure = (
data: ResponseData,
responseText: string,
export function observe(): void {
document.querySelectorAll(".jsCollapsibleBbcode").forEach((container: HTMLElement) => {
// find the matching toggle button
- const toggleButtons: HTMLElement[] = [];
- container.querySelectorAll(".toggleButton:not(.jsToggleButtonEnabled)").forEach((button: HTMLElement) => {
- if (button.closest(".jsCollapsibleBbcode") === container) {
- toggleButtons.push(button);
- }
+ const toggleButtons = Array.from<HTMLElement>(
+ container.querySelectorAll(".toggleButton:not(.jsToggleButtonEnabled)"),
+ ).filter((button) => {
+ return button.closest(".jsCollapsibleBbcode") === container;
});
const overflowContainer = (container.querySelector(".collapsibleBbcodeOverflow") as HTMLElement) || container;
document.body.appendChild(this.popover);
// event listener
- this.popover.addEventListener("mouseenter", this.popoverMouseEnter.bind(this));
+ this.popover.addEventListener("mouseenter", () => this.popoverMouseEnter());
this.popover.addEventListener("mouseleave", () => this.mouseLeave());
- this.popover.addEventListener("animationend", this.clearContent.bind(this));
+ this.popover.addEventListener("animationend", () => this.clearContent());
window.addEventListener("beforeunload", () => {
this.suspended = true;
const cacheId = elementData.element.dataset.cacheId!;
const data = this.cache.get(cacheId)!;
- if (data.state === State.Ready) {
- this.popoverContent.appendChild(data.content!);
-
- this.rebuild();
- } else if (data.state === State.None) {
- data.state = State.Loading;
-
- const handler = this.handlers.get(elementData.identifier)!;
- if (handler.loadCallback) {
- handler.loadCallback(elementData.objectId, this, elementData.element);
- } else if (handler.dboAction) {
- const callback = (data) => {
- this.setContent(elementData.identifier, elementData.objectId, data.returnValues.template);
-
- return true;
- };
-
- this.ajaxApi(
- {
- actionName: "getPopover",
- className: handler.dboAction,
- interfaceName: "wcf\\data\\IPopoverAction",
- objectIDs: [elementData.objectId],
- },
- callback,
- callback,
- );
+ switch (data.state) {
+ case State.Ready: {
+ this.popoverContent.appendChild(data.content!);
+
+ this.rebuild();
+
+ break;
+ }
+
+ case State.None: {
+ data.state = State.Loading;
+
+ const handler = this.handlers.get(elementData.identifier)!;
+ if (handler.loadCallback) {
+ handler.loadCallback(elementData.objectId, this, elementData.element);
+ } else if (handler.dboAction) {
+ const callback = (data) => {
+ this.setContent(elementData.identifier, elementData.objectId, data.returnValues.template);
+
+ return true;
+ };
+
+ this.ajaxApi(
+ {
+ actionName: "getPopover",
+ className: handler.dboAction,
+ interfaceName: "wcf\\data\\IPopoverAction",
+ objectIDs: [elementData.objectId],
+ },
+ callback,
+ callback,
+ );
+ }
+
+ break;
+ }
+
+ case State.Loading: {
+ // Do not interrupt inflight requests.
+ break;
}
}
}