1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 * Full screen window layout.
19 * @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>
20 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 import {addIconToContainer} from 'core/loadingicon';
26 * @param {string} templateName
27 * @param {object} context
30 const getComposedLayout = ({
34 const container = document.createElement('div');
35 document.body.append(container);
36 container.classList.add('layout');
37 container.classList.add('fullscreen');
38 container.setAttribute('aria-role', 'application');
40 // Lock scrolling on the document body.
43 const helpers = getLayoutHelpers(container);
46 helpers.showLoadingIcon();
50 helpers.requestFullscreen();
56 const getLayoutHelpers = (layoutNode) => {
57 const contentNode = document.createElement('div');
58 layoutNode.append(contentNode);
60 const loadingNode = document.createElement('div');
61 layoutNode.append(loadingNode);
64 * Close and destroy the window container.
74 * Attempt to make the conatiner full screen.
76 const requestFullscreen = () => {
77 if (layoutNode.requestFullscreen) {
78 layoutNode.requestFullscreen();
79 } else if (layoutNode.msRequestFullscreen) {
80 layoutNode.msRequestFullscreen();
81 } else if (layoutNode.mozRequestFullscreen) {
82 layoutNode.mozRequestFullscreen();
83 } else if (layoutNode.webkitRequestFullscreen) {
84 layoutNode.webkitRequestFullscreen();
87 // Hack to make this act like full-screen as much as possible.
93 * Exit full screen but do not close the container fully.
95 const exitFullscreen = () => {
96 if (document.exitRequestFullScreen) {
97 if (document.fullScreenElement !== layoutNode) {
100 document.exitRequestFullScreen();
101 } else if (document.msExitFullscreen) {
102 if (document.msFullscreenElement !== layoutNode) {
105 document.msExitFullscreen();
106 } else if (document.mozCancelFullScreen) {
107 if (document.mozFullScreenElement !== layoutNode) {
110 document.mozCancelFullScreen();
111 } else if (document.webkitExitFullscreen) {
112 if (document.webkitFullscreenElement !== layoutNode) {
115 document.webkitExitFullscreen();
119 const toggleFullscreen = () => {
120 if (document.exitRequestFullScreen) {
121 if (document.fullScreenElement === layoutNode) {
126 } else if (document.msExitFullscreen) {
127 if (document.msFullscreenElement === layoutNode) {
132 } else if (document.mozCancelFullScreen) {
133 if (document.mozFullScreenElement === layoutNode) {
138 } else if (document.webkitExitFullscreen) {
139 if (document.webkitFullscreenElement === layoutNode) {
148 * Get the Node which is fullscreen.
152 const getContainer = () => {
156 const setContent = (content) => {
159 // Note: It would be better to use replaceWith, but this is not compatible with IE.
160 let child = contentNode.lastElementChild;
162 contentNode.removeChild(child);
163 child = contentNode.lastElementChild;
165 contentNode.append(content);
168 const showLoadingIcon = () => {
169 addIconToContainer(loadingNode);
172 const hideLoadingIcon = () => {
173 // Hide the loading container.
174 let child = loadingNode.lastElementChild;
176 loadingNode.removeChild(child);
177 child = loadingNode.lastElementChild;
199 const lockBodyScroll = () => {
200 document.querySelector('body').classList.add('overflow-hidden');
203 const unlockBodyScroll = () => {
204 document.querySelector('body').classList.remove('overflow-hidden');
207 export const createLayout = getComposedLayout;