AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"fullscreen.min.js","sources":["../../../src/local/layout/fullscreen.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Full screen window layout.\n *\n * @module mod_forum/local/layout/fullscreen\n * @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or la
ter\n */\n\nimport {addIconToContainer} from 'core/loadingicon';\nimport {addToastRegion} from 'core/toast';\nimport * as FocusLockManager from 'core/local/aria/focuslock';\n\n/**\n * Get the composed layout.\n *\n * @method\n * @param {string} templateName\n * @param {object} context\n * @returns {LayoutHelper}\n */\n\nexport const createLayout = ({\n fullscreen = true,\n showLoader = false,\n focusOnClose = null,\n} = {}) => {\n const container = document.createElement('div');\n document.body.append(container);\n container.classList.add('layout');\n container.classList.add('fullscreen');\n container.setAttribute('role', 'application');\n addToastRegion(container);\n\n // Lock scrolling on the document body.\n lockBodyScroll();\n\n // Lock tab control.\n FocusLockManager.trapFocus(container);\n\n const helpers = getLayoutHelpers(container, FocusLockManager, focusOnClose);\n\n if (showLoader) {\n helpers.showLoadingIcon();\n }\n\n if (fullscreen) {\n
helpers.requestFullscreen();\n }\n\n return helpers;\n};\n\n/**\n * LayoutHelper A helper object containing functions for managing the current fullscreen layout\n *\n * @typedef {object}\n * @property {Function} close A function to close the fullscreen layout\n * @property {Function} toggleFullscreen A function to toggle the fullscreen from active to disabled and back\n * @property {Function} requestFullscreen Make a request to the browser to make the window full screen.\n * Note: This must be called in response to a direct user action\n * @property {Function} exitFullscreen Exit the fullscreen mode\n * @property {Function} getContainer Get the container of the fullscreen layout\n * @property {Function} setContent Set the content of the fullscreen layout\n * @property {Function} showLoadingIcon Display the loading icon\n * @property {Function} hideLoadingIcon Hide the loading icon\n */\n\n/**\n * Get the layout helpers.\n *\n * @method\n * @private\n * @param {HTMLElement} layoutNode\n * @param
{FocusLockManager} FocusLockManager\n * @param {Boolean} focusOnClose\n * @returns {LayoutHelper}\n */\nconst getLayoutHelpers = (layoutNode, FocusLockManager, focusOnClose) => {\n const contentNode = document.createElement('div');\n layoutNode.append(contentNode);\n\n const loadingNode = document.createElement('div');\n layoutNode.append(loadingNode);\n\n /**\n * Close and destroy the window container.\n */\n const close = () => {\n exitFullscreen();\n unlockBodyScroll();\n FocusLockManager.untrapFocus();\n\n layoutNode.remove();\n\n if (focusOnClose) {\n try {\n focusOnClose.focus();\n } catch (e) {\n // eslint-disable-line\n }\n }\n };\n\n /**\n * Attempt to make the conatiner full screen.\n */\n const requestFullscreen = () => {\n if (layoutNode.requestFullscreen) {\n layoutNode.requestFullscreen();\n } else if (layoutNode.msRequestFu
llscreen) {\n layoutNode.msRequestFullscreen();\n } else if (layoutNode.mozRequestFullscreen) {\n layoutNode.mozRequestFullscreen();\n } else if (layoutNode.webkitRequestFullscreen) {\n layoutNode.webkitRequestFullscreen();\n } else {\n // Not supported.\n // Hack to make this act like full-screen as much as possible.\n layoutNode.setTop(0);\n }\n };\n\n /**\n * Exit full screen but do not close the container fully.\n */\n const exitFullscreen = () => {\n if (document.exitRequestFullScreen) {\n if (document.fullScreenElement !== layoutNode) {\n return;\n }\n document.exitRequestFullScreen();\n } else if (document.msExitFullscreen) {\n if (document.msFullscreenElement !== layoutNode) {\n return;\n }\n document.msExitFullscreen();\n } else if (document.mozCancelFullScreen) {\n
if (document.mozFullScreenElement !== layoutNode) {\n return;\n }\n document.mozCancelFullScreen();\n } else if (document.webkitExitFullscreen) {\n if (document.webkitFullscreenElement !== layoutNode) {\n return;\n }\n document.webkitExitFullscreen();\n }\n };\n\n const toggleFullscreen = () => {\n if (document.exitRequestFullScreen) {\n if (document.fullScreenElement === layoutNode) {\n exitFullscreen();\n } else {\n requestFullscreen();\n }\n } else if (document.msExitFullscreen) {\n if (document.msFullscreenElement === layoutNode) {\n exitFullscreen();\n } else {\n requestFullscreen();\n }\n } else if (document.mozCancelFullScreen) {\n if (document.mozFullScreenElement === layoutNode) {\n exitFullscreen();\n } else {\n
requestFullscreen();\n }\n } else if (document.webkitExitFullscreen) {\n if (document.webkitFullscreenElement === layoutNode) {\n exitFullscreen();\n } else {\n requestFullscreen();\n }\n }\n };\n\n /**\n * Get the Node which is fullscreen.\n *\n * @return {Element}\n */\n const getContainer = () => {\n return contentNode;\n };\n\n const setContent = (content) => {\n hideLoadingIcon();\n\n // Note: It would be better to use replaceWith, but this is not compatible with IE.\n let child = contentNode.lastElementChild;\n while (child) {\n contentNode.removeChild(child);\n child = contentNode.lastElementChild;\n }\n contentNode.append(content);\n };\n\n const showLoadingIcon = () => {\n addIconToContainer(loadingNode);\n };\n\n const hideLoadingIcon = () => {\n // Hide the loading conta
iner.\n let child = loadingNode.lastElementChild;\n while (child) {\n loadingNode.removeChild(child);\n child = loadingNode.lastElementChild;\n }\n };\n\n /**\n * @return {Object}\n */\n return {\n close,\n\n toggleFullscreen,\n requestFullscreen,\n exitFullscreen,\n\n getContainer,\n setContent,\n\n showLoadingIcon,\n hideLoadingIcon,\n };\n};\n\nconst lockBodyScroll = () => {\n document.querySelector('body').classList.add('overflow-hidden');\n};\n\nconst unlockBodyScroll = () => {\n document.querySelector('body').classList.remove('overflow-hidden');\n};\n"],"names":["fullscreen","showLoader","focusOnClose","container","document","createElement","body","append","classList","add","setAttribute","lockBodyScroll","FocusLockManager","trapFocus","helpers","getLayoutHelpers","showLoadingIcon","requestFullscreen","layoutNode","contentNode","loadingNode","msRequestFullscreen","mozRequestFulls
creen","webkitRequestFullscreen","setTop","exitFullscreen","exitRequestFullScreen","fullScreenElement","msExitFullscreen","msFullscreenElement","mozCancelFullScreen","mozFullScreenElement","webkitExitFullscreen","webkitFullscreenElement","hideLoadingIcon","child","lastElementChild","removeChild","close","unlockBodyScroll","untrapFocus","remove","focus","e","toggleFullscreen","getContainer","setContent","content","querySelector"],"mappings":";;;;;;;8CAoC4B,eAACA,WACzBA,YAAa,EADYC,WAEzBA,YAAa,EAFYC,aAGzBA,aAAe,6DACf,SACMC,UAAYC,SAASC,cAAc,OACzCD,SAASE,KAAKC,OAAOJ,WACrBA,UAAUK,UAAUC,IAAI,UACxBN,UAAUK,UAAUC,IAAI,cACxBN,UAAUO,aAAa,OAAQ,yCAChBP,WAGfQ,iBAGAC,iBAAiBC,UAAUV,iBAErBW,QAAUC,iBAAiBZ,UAAWS,iBAAkBV,qBAE1DD,YACAa,QAAQE,kBAGRhB,YACAc,QAAQG,oBAGLH,eA4BLC,iBAAmB,CAACG,WAAYN,iBAAkBV,sBAC9CiB,YAAcf,SAASC,cAAc,OAC3Ca,WAAWX,OAAOY,mBAEZC,YAAchB,SAASC,cAAc,OAC3Ca,WAAWX,OAAOa,mBAwBZH,kBAAoB,KAClBC,WAAWD,kBACXC,WAAWD,oBACJC,WAAWG,oBAClBH,WAAWG,sBACJH,WAAWI,qBAClBJ,WAAWI,uBACJJ,WAAWK,wBAClBL,WAAWK,0BAIXL,WAAWM,OAAO,IAO
pBC,eAAiB,QACfrB,SAASsB,sBAAuB,IAC5BtB,SAASuB,oBAAsBT,kBAGnCd,SAASsB,6BACN,GAAItB,SAASwB,iBAAkB,IAC9BxB,SAASyB,sBAAwBX,kBAGrCd,SAASwB,wBACN,GAAIxB,SAAS0B,oBAAqB,IACjC1B,SAAS2B,uBAAyBb,kBAGtCd,SAAS0B,2BACN,GAAI1B,SAAS4B,qBAAsB,IAClC5B,SAAS6B,0BAA4Bf,kBAGzCd,SAAS4B,yBAyDXE,gBAAkB,SAEhBC,MAAQf,YAAYgB,sBACjBD,OACHf,YA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