迁移游戏面板关闭事件
This commit is contained in:
@@ -33,6 +33,7 @@ export {
|
||||
} from "./chat-room/baccarat-loss-cover-admin.js";
|
||||
export { bindBaccaratLossCoverControls } from "./chat-room/baccarat-loss-cover.js";
|
||||
export { bindGameHallControls } from "./chat-room/game-hall.js";
|
||||
export { bindGamePanelControls } from "./chat-room/game-panels.js";
|
||||
export {
|
||||
bankAction,
|
||||
bankLoadInfo,
|
||||
@@ -106,6 +107,7 @@ import {
|
||||
} from "./chat-room/baccarat-loss-cover-admin.js";
|
||||
import { bindBaccaratLossCoverControls } from "./chat-room/baccarat-loss-cover.js";
|
||||
import { bindGameHallControls } from "./chat-room/game-hall.js";
|
||||
import { bindGamePanelControls } from "./chat-room/game-panels.js";
|
||||
import {
|
||||
bankAction,
|
||||
bankLoadInfo,
|
||||
@@ -182,6 +184,7 @@ if (typeof window !== "undefined") {
|
||||
closeCurrentBaccaratLossCoverEvent,
|
||||
bindBaccaratLossCoverControls,
|
||||
bindGameHallControls,
|
||||
bindGamePanelControls,
|
||||
loadAdminCurrentLossCoverEvent,
|
||||
openAdminBaccaratLossCoverModal,
|
||||
submitBaccaratLossCoverEvent,
|
||||
@@ -269,6 +272,7 @@ if (typeof window !== "undefined") {
|
||||
bindBaccaratLossCoverAdminControls();
|
||||
bindBaccaratLossCoverControls();
|
||||
bindGameHallControls();
|
||||
bindGamePanelControls();
|
||||
bindBankControls();
|
||||
bindFishingControls();
|
||||
bindMarriageStatusControls();
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
// 小型游戏弹窗通用事件代理,收口各游戏头部关闭按钮内联 onclick。
|
||||
|
||||
let gamePanelEventsBound = false;
|
||||
|
||||
/**
|
||||
* 关闭指定 Alpine 游戏面板。
|
||||
*
|
||||
* @param {string} panelId 面板 DOM ID
|
||||
* @returns {void}
|
||||
*/
|
||||
function closeAlpineGamePanel(panelId) {
|
||||
const panel = document.getElementById(panelId);
|
||||
const panelData = panel && typeof window.Alpine?.$data === "function"
|
||||
? window.Alpine.$data(panel)
|
||||
: null;
|
||||
|
||||
if (!panelData) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 多数游戏面板提供 close(),占卜面板只暴露 show 状态,因此保留 show=false 兜底。
|
||||
if (typeof panelData.close === "function") {
|
||||
panelData.close();
|
||||
return;
|
||||
}
|
||||
|
||||
panelData.show = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定小型游戏面板通用关闭事件。
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
export function bindGamePanelControls() {
|
||||
if (gamePanelEventsBound || typeof document === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
gamePanelEventsBound = true;
|
||||
document.addEventListener("click", (event) => {
|
||||
if (!(event.target instanceof Element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const closeButton = event.target.closest("[data-game-panel-close]");
|
||||
if (!closeButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
closeAlpineGamePanel(closeButton.getAttribute("data-game-panel-close") || "");
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user