From a4084e7b820fb6fb45524aae29a3a8e91e65ce5d Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sun, 10 Nov 2024 21:22:06 -0800 Subject: [PATCH] fix(FullScreenButton): update fullscreen state icon (#4642) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: update fullscreen state icon * refactor: 重构代码提高可读性 --- .../wwwroot/modules/fullscreen.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/BootstrapBlazor/wwwroot/modules/fullscreen.js b/src/BootstrapBlazor/wwwroot/modules/fullscreen.js index c97ff3219..695f772ae 100644 --- a/src/BootstrapBlazor/wwwroot/modules/fullscreen.js +++ b/src/BootstrapBlazor/wwwroot/modules/fullscreen.js @@ -14,7 +14,7 @@ export async function toggle(options) { if (el !== null) { if (isFullscreen()) { - await document.exitFullscreen() + await exitFullscreen(el); } else { await enterFullscreen(el); @@ -25,12 +25,22 @@ export async function toggle(options) { const enterFullscreen = async el => { await el.requestFullscreen(); - if (!isFullscreen()) { - el.classList.remove('bb-fs-open'); - document.documentElement.classList.remove('bb-fs-open'); + updateFullscreenState(el); +} + +const exitFullscreen = async el => { + await document.exitFullscreen() + + updateFullscreenState(el); +} + +const updateFullscreenState = el => { + if (isFullscreen()) { + el.classList.add('bb-fs-open') } else { - el.classList.add('bb-fs-open') + el.classList.remove('bb-fs-open'); + document.documentElement.classList.remove('bb-fs-open'); } }