-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatFull.js
More file actions
120 lines (106 loc) · 3.93 KB
/
chatFull.js
File metadata and controls
120 lines (106 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// chatFull.js
(() => {
"use strict";
// Constants
const FULL_CHAT_CLASS = "full-chat";
const POPUP_ID = "12698"; // Elementor popup ID
// Debounce utility
function debounce(func, wait) {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => func(...args), wait);
};
}
// Toggle full chat mode
function toggleFullChat(e) {
if (e && typeof e.preventDefault === "function") e.preventDefault();
const body = document.body;
const docEl = document.documentElement;
const isFullChat = body.classList.contains(FULL_CHAT_CLASS);
body.classList.toggle(FULL_CHAT_CLASS);
if (!isFullChat) {
docEl.style.overflow = "hidden";
body.style.overflow = "hidden";
} else {
docEl.style.overflow = "";
body.style.overflow = "";
const chatLog = document.getElementById("chat-log");
if (chatLog) {
chatLog.scrollTop = chatLog.scrollHeight; // Silent scroll restore
}
}
console.log(`chatFull.js: Full chat ${isFullChat ? "disabled..." : "enabled..."}`);
}
// Force open full chat if not already open
function forceOpenFullChat() {
if (!document.body.classList.contains(FULL_CHAT_CLASS)) {
toggleFullChat();
console.log("chatFull.js: Forced full chat open.");
}
}
// Attach event listeners
function attachListeners() {
const fullChatIcon = document.getElementById("fullChat");
if (fullChatIcon) {
if (!fullChatIcon.dataset.listenerAttached) {
fullChatIcon.addEventListener("click", debouncedToggleFullChat);
fullChatIcon.dataset.listenerAttached = "true";
console.log("chatFull.js: Full chat listener active...");
}
} else {
console.warn("chatFull.js: Full chat icon (#fullChat) not found.");
}
const closeButtons = document.querySelectorAll(".dialog-close-button");
if (closeButtons.length === 0) {
console.warn("chatFull.js: No close buttons (.dialog-close-button) found.");
}
closeButtons.forEach((button) => {
if (!button.dataset.listenerAttached) {
button.addEventListener("click", () => {
document.body.classList.remove(FULL_CHAT_CLASS);
document.documentElement.style.overflow = "";
document.body.style.overflow = "";
const chatLog = document.getElementById("chat-log");
if (chatLog) {
chatLog.scrollTop = chatLog.scrollHeight; // Silent scroll restore
}
// No console.log here
});
button.dataset.listenerAttached = "true";
}
});
// Check URL parameter for fullscreen
const forceFullScreen = window.location.search.includes("fullscreen=1");
if (forceFullScreen) {
forceOpenFullChat();
}
}
// Debounced toggle function
const debouncedToggleFullChat = debounce(toggleFullChat, 200);
// Trigger setup
document.addEventListener("DOMContentLoaded", () => {
// Manual trigger (e.g., <a href="#cloudie">)
document.querySelectorAll('a[href="#cloudie"]').forEach(trigger => {
trigger.addEventListener("click", (e) => {
e.preventDefault();
if (typeof elementorProFrontend?.modules?.popup?.showPopup === "function") {
elementorProFrontend.modules.popup.showPopup({ id: POPUP_ID });
}
setTimeout(() => attachListeners(), 300); // Matches chatMain.js delay
});
});
// Elementor popup event
document.addEventListener("elementor/popup/show", (event) => {
const { popupId } = event.detail || {};
if (popupId === POPUP_ID) {
setTimeout(() => attachListeners(), 300); // Matches chatMain.js delay
}
});
// Custom reinitialize event
document.addEventListener("chatReinitialize", () => {
console.log("chatFull.js: Reinitializing full chat...");
attachListeners();
});
});
})();