From bb2a18722d52972e4f45835fb64c3559e994acc6 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sun, 8 Jan 2023 12:53:03 +0400 Subject: [PATCH] TS Fullscreen --- src/commands/view/{Fullscreen.js => Fullscreen.ts} | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) rename src/commands/view/{Fullscreen.js => Fullscreen.ts} (89%) diff --git a/src/commands/view/Fullscreen.js b/src/commands/view/Fullscreen.ts similarity index 89% rename from src/commands/view/Fullscreen.js rename to src/commands/view/Fullscreen.ts index 165b4d81e..14e7913fe 100644 --- a/src/commands/view/Fullscreen.js +++ b/src/commands/view/Fullscreen.ts @@ -1,4 +1,5 @@ import { isElement } from 'underscore'; +import { CustomCommand } from './CommandAbstract'; export default { /** @@ -7,6 +8,7 @@ export default { */ isEnabled() { const d = document; + // @ts-ignore if (d.fullscreenElement || d.webkitFullscreenElement || d.mozFullScreenElement) { return true; } @@ -18,7 +20,7 @@ export default { * @param {HTMLElement} el * @return {string} */ - enable(el) { + enable(el: any) { let pfx = ''; if (el.requestFullscreen) { @@ -40,7 +42,7 @@ export default { * Disable fullscreen mode */ disable() { - const d = document; + const d: any = document; if (this.isEnabled()) { if (d.exitFullscreen) d.exitFullscreen(); @@ -56,7 +58,7 @@ export default { * @param {strinf} pfx Browser prefix * @param {Event} e */ - fsChanged(pfx) { + fsChanged(pfx: string) { if (!this.isEnabled()) { this.stopCommand({ sender: this.sender }); document.removeEventListener(`${pfx || ''}fullscreenchange`, this.fsChanged); @@ -66,7 +68,7 @@ export default { run(editor, sender, opts = {}) { this.sender = sender; const { target } = opts; - const targetEl = isElement(target) ? target : document.querySelector(target); + const targetEl = isElement(target) ? target : document.querySelector(target!); const pfx = this.enable(targetEl || editor.getContainer()); this.fsChanged = this.fsChanged.bind(this, pfx); document.addEventListener(pfx + 'fullscreenchange', this.fsChanged); @@ -78,4 +80,4 @@ export default { this.disable(); if (editor) editor.trigger('change:canvasOffset'); }, -}; +} as CustomCommand<{ target?: HTMLElement | string }, { [k: string]: any }>;