Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FullScreen): remove FullScreen component #4537

Merged
merged 6 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
@RenderBody()

<EyeDropper></EyeDropper>
<FullScreen></FullScreen>
<Clipboard></Clipboard>
<Title></Title>

Expand Down
47 changes: 0 additions & 47 deletions src/BootstrapBlazor/Components/FullScreen/FullScreen.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ namespace BootstrapBlazor.Components;
/// <summary>
/// FullScreen 服务
/// </summary>
public class FullScreenService : BootstrapServiceBase<FullScreenOption>
public class FullScreenService(IJSRuntime jSRuntime)
{
[NotNull]
private JSModule? _module = null;

/// <summary>
/// 全屏方法,已经全屏时再次调用后退出全屏
/// </summary>
/// <param name="option"></param>
/// <param name="token"></param>
/// <returns></returns>
public Task Toggle(FullScreenOption? option = null) => Invoke(option ?? new());
public async Task Toggle(FullScreenOption? option = null, CancellationToken token = default)
{
_module ??= await jSRuntime.LoadModule("./_content/BootstrapBlazor/modules/fullscreen.js");
await _module.InvokeVoidAsync("toggle", token, option);
}
}
91 changes: 23 additions & 68 deletions src/BootstrapBlazor/wwwroot/modules/fullscreen.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,39 @@
import { isElement } from "./utility.js"
import Data from "./data.js"

export function init(id) {
const fs = { toggleElement: null };
Data.set(id, fs)

fs.toggle = options => {
if (options.id) {
fs.toggleElement = document.getElementById(options.id)
}
else if (options.element && isElement(options.element)) {
fs.toggleElement = el
}
else {
fs.toggleElement = document.documentElement
}
export async function toggle(options) {
let el = null;
if (options?.id) {
el = document.getElementById(options.id);
}
else if (options?.element && isElement(options.element)) {
el = options.element;
}
else {
el = document.documentElement
}

if (el !== null) {
if (isFullscreen()) {
exit()
await document.exitFullscreen()
}
else {
fs.enter()
await enterFullscreen(el);
}
}
}

fs.enter = () => {
fs.toggleElement.requestFullscreen() ||
fs.toggleElement.webkitRequestFullscreen ||
fs.toggleElement.mozRequestFullScreen ||
fs.toggleElement.msRequestFullscreen

// 处理 ESC 按键退出全屏
var handler = setTimeout(() => {
clearTimeout(handler);
const enterFullscreen = async el => {
await el.requestFullscreen();

const fullscreenCheck = () => {
if (!isFullscreen()) {
fs.toggleElement.classList.remove('bb-fs-open');
document.documentElement.classList.remove('bb-fs-open');
}
else {
fs.toggleElement.classList.add('bb-fs-open')
requestAnimationFrame(fullscreenCheck);
}
}
requestAnimationFrame(fullscreenCheck);
}, 200);
if (!isFullscreen()) {
el.classList.remove('bb-fs-open');
document.documentElement.classList.remove('bb-fs-open');
}
}

export function execute(id, options) {
const fs = Data.get(id)
if (fs) {
fs.toggle(options);
else {
el.classList.add('bb-fs-open')
}
}

export function dispose(id) {
Data.remove(id)
}

const isFullscreen = () => {
return document.fullscreen ||
document.webkitIsFullScreen ||
document.webkitFullScreen ||
document.mozFullScreen ||
document.msFullScreent
}

const exit = () => {
if (document.exitFullscreen) {
document.exitFullscreen()
}
else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen()
}
else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen()
}
else if (document.msExitFullscreen) {
document.msExitFullscreen()
}
return document.fullscreenElement !== null;
}
149 changes: 0 additions & 149 deletions test/UnitTest/Components/FullScreenTest.cs

This file was deleted.

Loading