Skip to content

Commit f35f663

Browse files
committed
fix: welcome card flip bug
1 parent 573dc4d commit f35f663

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

themes/welcome.js

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ class WelcomeMessage {
6767
this.card_array = [];
6868
this.static_welcome_message_previous = [];
6969
this.reflesh_time_interval = 15*1000;
70+
71+
72+
const reflesh_render_status = () => {
73+
for (let index = 0; index < this.card_array.length; index++) {
74+
const card = this.card_array[index];
75+
card.classList.remove('hide');
76+
card.classList.remove('show');
77+
}
78+
};
79+
const pageFocusHandler = new PageFocusHandler();
80+
pageFocusHandler.addFocusCallback(reflesh_render_status);
7081
}
7182

7283
begin_render() {
@@ -106,8 +117,12 @@ class WelcomeMessage {
106117
}
107118

108119
const card = this.card_array[index];
109-
card.classList.remove('hide');
110-
card.classList.remove('show');
120+
// 已经包含了 hide 属性?
121+
if (card.classList.contains('hide') || card.classList.contains('show')) {
122+
card.classList.remove('hide');
123+
card.classList.remove('show');
124+
continue;
125+
}
111126

112127
// 等待动画结束
113128
card.addEventListener('transitionend', () => {
@@ -158,7 +173,7 @@ class WelcomeMessage {
158173
}
159174

160175
async update() {
161-
console.log('update')
176+
// console.log('update')
162177
var page_width = document.documentElement.clientWidth;
163178
const width_to_hide_welcome = 1200;
164179
if (!await this.isChatbotEmpty() || page_width < width_to_hide_welcome) {
@@ -269,3 +284,34 @@ class WelcomeMessage {
269284

270285
}
271286

287+
288+
289+
290+
class PageFocusHandler {
291+
constructor() {
292+
this.hasReturned = false;
293+
this.focusCallbacks = [];
294+
295+
// Bind the focus and blur event handlers
296+
window.addEventListener('visibilitychange', this.handleFocus.bind(this));
297+
}
298+
299+
// Method to handle the focus event
300+
handleFocus() {
301+
if (this.hasReturned) {
302+
this.focusCallbacks.forEach(callback => callback());
303+
}
304+
this.hasReturned = true;
305+
}
306+
307+
// Method to add a custom callback function
308+
addFocusCallback(callback) {
309+
if (typeof callback === 'function') {
310+
this.focusCallbacks.push(callback);
311+
} else {
312+
throw new Error('Callback must be a function');
313+
}
314+
}
315+
}
316+
317+

0 commit comments

Comments
 (0)