From 03d9593be036e6d1023a783ac3388dd1b832f106 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 1 Aug 2024 17:50:29 +0200 Subject: [PATCH] wip #7032 @2 --- js/libs/fluidbook/fluidbook.keyboard.js | 6 ++--- js/libs/fluidbook/fluidbook.nav.js | 8 +++--- js/libs/fluidbook/fluidbook.support.js | 26 ++++++++++++++++--- js/libs/fluidbook/fluidbook.widget.js | 4 +-- .../fluidbook/stats/fluidbook.stats.esm.js | 2 +- js/libs/screenfull.min.js | 7 ----- 6 files changed, 32 insertions(+), 21 deletions(-) delete mode 100644 js/libs/screenfull.min.js diff --git a/js/libs/fluidbook/fluidbook.keyboard.js b/js/libs/fluidbook/fluidbook.keyboard.js index 5ff30d0f..597390b0 100644 --- a/js/libs/fluidbook/fluidbook.keyboard.js +++ b/js/libs/fluidbook/fluidbook.keyboard.js @@ -24,8 +24,8 @@ FluidbookKeyboard.prototype = { if ($this.fluidbook.nav.menuIsOpen) { $this.fluidbook.nav.closeMenu(); } - if (screenfull.isFullscreen) { - screenfull.exit(); + if ($this.fluidbook.support.isFullscreen()) { + document.exitFullscreen(); } }); this.keyShortcut('tab,shift+tab', function (e, handler) { @@ -38,7 +38,7 @@ FluidbookKeyboard.prototype = { if (this.fluidbook.settings.fullscreen) { this.keyShortcut('f11', function () { - screenfull.toggle(); + $this.fluidbook.support.toggleFullscreen(); }); } diff --git a/js/libs/fluidbook/fluidbook.nav.js b/js/libs/fluidbook/fluidbook.nav.js index a2f5ec89..0f88017a 100644 --- a/js/libs/fluidbook/fluidbook.nav.js +++ b/js/libs/fluidbook/fluidbook.nav.js @@ -770,16 +770,15 @@ FluidbookNav.prototype = { // Full screen toggle $(document).on(this.fluidbook.input.clickEvent, '.icon-fullscreen', function () { $this.closeMenu(); - screenfull.toggle(); + $this.fluidbook.support.toggleFullscreen(); return false; }); - // Toggle icon on fullscreen change (also handles exiting via ESC key) - screenfull.on('change', function () { + document.addEventListener('fullscreenchange', function () { resize(); // Slight delay to stop icon state flickering during fullscreen transition setTimeout(function () { - if (screenfull.isFullscreen) { + if ($this.fluidbook.support.isFullscreen()) { $('.icon-fullscreen').addClass('active'); } else { window.focus(); @@ -793,7 +792,6 @@ FluidbookNav.prototype = { }, 1000); window.focus(); }); - }, openSearch: function (q, cb) { diff --git a/js/libs/fluidbook/fluidbook.support.js b/js/libs/fluidbook/fluidbook.support.js index 7a09deaa..783c9d17 100644 --- a/js/libs/fluidbook/fluidbook.support.js +++ b/js/libs/fluidbook/fluidbook.support.js @@ -69,8 +69,8 @@ function FluidbookSupport(fluidbook) { this.screenWidth = Math.min(window.screen.availWidth, window.screen.availHeight); this.screenHeight = Math.max(window.screen.availWidth, window.screen.availHeight); - // See #2440 - this.fullscreen = screenfull.enabled && !this.iOS; + // See #2440, #7032 + this.fullscreen = document.fullscreenEnabled !== undefined && document.fullscreenEnabled === true && (!this.iOS || this.fluidbook.settings.fullscreeniOS); this._orientation = this.getOrientation(); this.initEvents(); @@ -225,5 +225,25 @@ FluidbookSupport.prototype = { } return false; - } + }, + + isFullscreen: function () { + return this.fullscreen && document.fullscreenElement && document.exitFullscreen; + }, + + toggleFullscreen: function () { + if (this.isFullscreen()) { + this.exitFullscreen(); + } else { + this.requestFullscreen(); + } + }, + + requestFullscreen: function () { + document.documentElement.requestFullscreen(); + }, + + exitFullscreen: function () { + document.exitFullscreen(); + }, } diff --git a/js/libs/fluidbook/fluidbook.widget.js b/js/libs/fluidbook/fluidbook.widget.js index 0ff39388..81d11def 100644 --- a/js/libs/fluidbook/fluidbook.widget.js +++ b/js/libs/fluidbook/fluidbook.widget.js @@ -38,7 +38,7 @@ FluidbookWidget.prototype = { var active = this.isWidgetModeActive(); if (active) { if (this.action === 'fullscreen') { - screenfull.toggle(); + $this.fluidbook.support.requestFullscreen(); } else if (this.action === 'tab') { window.open(window.location.toString().replace("widget=1", "widget=0"), '_blank'); } @@ -82,6 +82,6 @@ FluidbookWidget.prototype = { }, isWidgetModeActive: function () { - return this.featureEnabled && !screenfull.isFullscreen; + return this.featureEnabled && !this.fluidbook.support.isFullscreen(); } } \ No newline at end of file diff --git a/js/libs/fluidbook/stats/fluidbook.stats.esm.js b/js/libs/fluidbook/stats/fluidbook.stats.esm.js index ded04f9d..55ae3874 100644 --- a/js/libs/fluidbook/stats/fluidbook.stats.esm.js +++ b/js/libs/fluidbook/stats/fluidbook.stats.esm.js @@ -125,7 +125,7 @@ FluidbookStatsEsm.prototype = { getClickName: function (id) { if (id === 'fullscreen') { - if (screenfull.isFullscreen) { + if (this.fluidbook.support.isFullscreen()) { return 'reduire_ecran'; } else { return 'plein_ecran'; diff --git a/js/libs/screenfull.min.js b/js/libs/screenfull.min.js deleted file mode 100644 index 70b732e9..00000000 --- a/js/libs/screenfull.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! -* screenfull -* v4.2.0 - 2019-04-01 -* (c) Sindre Sorhus; MIT License -*/ - -!function(){"use strict";var u="undefined"!=typeof window&&void 0!==window.document?window.document:{},e="undefined"!=typeof module&&module.exports,t="undefined"!=typeof Element&&"ALLOW_KEYBOARD_INPUT"in Element,c=function(){for(var e,n=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],l=0,r=n.length,t={};l