Browse Source

TS Fullscreen

ts-style-manager
Artur Arseniev 4 years ago
parent
commit
bb2a18722d
  1. 12
      src/commands/view/Fullscreen.ts

12
src/commands/view/Fullscreen.js → src/commands/view/Fullscreen.ts

@ -1,4 +1,5 @@
import { isElement } from 'underscore'; import { isElement } from 'underscore';
import { CustomCommand } from './CommandAbstract';
export default { export default {
/** /**
@ -7,6 +8,7 @@ export default {
*/ */
isEnabled() { isEnabled() {
const d = document; const d = document;
// @ts-ignore
if (d.fullscreenElement || d.webkitFullscreenElement || d.mozFullScreenElement) { if (d.fullscreenElement || d.webkitFullscreenElement || d.mozFullScreenElement) {
return true; return true;
} }
@ -18,7 +20,7 @@ export default {
* @param {HTMLElement} el * @param {HTMLElement} el
* @return {string} * @return {string}
*/ */
enable(el) { enable(el: any) {
let pfx = ''; let pfx = '';
if (el.requestFullscreen) { if (el.requestFullscreen) {
@ -40,7 +42,7 @@ export default {
* Disable fullscreen mode * Disable fullscreen mode
*/ */
disable() { disable() {
const d = document; const d: any = document;
if (this.isEnabled()) { if (this.isEnabled()) {
if (d.exitFullscreen) d.exitFullscreen(); if (d.exitFullscreen) d.exitFullscreen();
@ -56,7 +58,7 @@ export default {
* @param {strinf} pfx Browser prefix * @param {strinf} pfx Browser prefix
* @param {Event} e * @param {Event} e
*/ */
fsChanged(pfx) { fsChanged(pfx: string) {
if (!this.isEnabled()) { if (!this.isEnabled()) {
this.stopCommand({ sender: this.sender }); this.stopCommand({ sender: this.sender });
document.removeEventListener(`${pfx || ''}fullscreenchange`, this.fsChanged); document.removeEventListener(`${pfx || ''}fullscreenchange`, this.fsChanged);
@ -66,7 +68,7 @@ export default {
run(editor, sender, opts = {}) { run(editor, sender, opts = {}) {
this.sender = sender; this.sender = sender;
const { target } = opts; 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()); const pfx = this.enable(targetEl || editor.getContainer());
this.fsChanged = this.fsChanged.bind(this, pfx); this.fsChanged = this.fsChanged.bind(this, pfx);
document.addEventListener(pfx + 'fullscreenchange', this.fsChanged); document.addEventListener(pfx + 'fullscreenchange', this.fsChanged);
@ -78,4 +80,4 @@ export default {
this.disable(); this.disable();
if (editor) editor.trigger('change:canvasOffset'); if (editor) editor.trigger('change:canvasOffset');
}, },
}; } as CustomCommand<{ target?: HTMLElement | string }, { [k: string]: any }>;
Loading…
Cancel
Save