File : uis/fullScreenUI/FullScreenUI.js

1
/*
2
Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/
3
4
This  program is free software;
5
you can redistribute it and/or modify it under the terms of the
6
GNU General Public License as published by the Free Software Foundation;
7
either version 3 of the License, or any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
*/
18
/*
19
Changes:
20
    - v4.0.0:
21
        - created from v3.6.0
22
Doc reviewed 202208
23
 */
24
25
import theConfig from '../../data/Config.js';
26
import theHTMLElementsFactory from '../../core/uiLib/HTMLElementsFactory.js';
27
import theTranslator from '../../core/uiLib/Translator.js';
28
import { ZERO } from '../../main/Constants.js';
29
30
/* ------------------------------------------------------------------------------------------------------------------------- */
31
/**
32
This class show a message on the screen for the fullscreen activation
33
34
See theFullScreenUI for the one and only one instance of this class
35
*/
36
/* ------------------------------------------------------------------------------------------------------------------------- */
37
38
class FullScreenUI {
39
40
    /**
41
    The container
42
    @type {HTMLElement}
43
    */
44
45
    #mainHTMLElement;
46
47
    /**
48
    A timerId for the close UI timer
49
    @type {Number}
50
    */
51
52
    #timerId = null;
53
54
    /**
55
    Hide the UI
56
    */
57
58
    hide ( ) {
59
        if ( this.#timerId ) {
60
            clearTimeout ( this.#timerId );
61
            this.#timerId = null;
62
        }
63
        this.#mainHTMLElement.removeEventListener ( 'click', this.toggle, false );
64
        document.body.removeChild ( this.#mainHTMLElement );
65
    }
66
67
    /**
68
    The constructor
69
    */
70
71
    constructor ( ) {
72
        Object.freeze ( this );
73
    }
74
75
    /**
76
    Toggle the full screen mode
77
    */
78
79
    async toggle ( ) {
80
        if ( document.fullscreenElement ) {
81
            await document.exitFullscreen ();
82
        }
83
        else {
84
            await document.body.requestFullscreen ();
85
        }
86
    }
87
88
    /**
89
    Show the user interface
90
    */
91
92
    show ( ) {
93
        const timeOutDuration = theConfig.FullScreenUI.timeOut;
94
        if (
95
            ZERO === timeOutDuration
96
            ||
97
            ! document.fullscreenEnabled
98
            ||
99
            document.body.clientWidth > theConfig.FullScreenUI.screenMaxWidth
100
        ) {
101
            return;
102
        }
103
104
        this.#mainHTMLElement = theHTMLElementsFactory.create (
105
            'div',
106
            {
107
                id : 'TravelNotes-FullScreenUI',
108
                textContent : theTranslator.getText ( 'FullScreenUI - start full screen' )
109
            },
110
            document.body
111
        );
112
        this.#mainHTMLElement.addEventListener ( 'click', this.toggle, false );
113
        this.#timerId = setTimeout ( ( ) => this.hide ( ), timeOutDuration );
114
    }
115
}
116
117
/* ------------------------------------------------------------------------------------------------------------------------- */
118
/**
119
The one and only one instance of ErrorsUI class
120
@type {FullScreenUI}
121
*/
122
/* ------------------------------------------------------------------------------------------------------------------------- */
123
124
const theFullScreenUI = new FullScreenUI ( );
125
126
export default theFullScreenUI;
127
128
/* --- End of file --------------------------------------------------------------------------------------------------------- */
129