{"version":3,"file":"button.min.js","sources":["https:\/\/lms.well-done.kz\/local\/fullscreen\/amd\/src\/button.js"],"sourcesContent":["\/\/ This file is part of the fullscreen button plugin.\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 .\n\n\/**\n * A javascript module that adds the fullscreen button to a page.\n *\n * @module local_fullscreen\/button\n * @copyright 2018 University of Nottingham\n * @author Neill Magill \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport Log from 'core\/log';\nimport * as Templates from 'core\/templates';\nimport Notification from 'core\/notification';\nimport * as KeyParser from 'local_fullscreen\/keyparser';\nimport * as Str from 'core\/str';\nimport Pending from 'core\/pending';\nimport {setUserPreference} from 'core_user\/repository';\n\n\/**\n * Store of selectors for the fullscreen button.\n *\/\nconst SELECTORS = {\n \/** The attachment point. *\/\n attach: '#region-main',\n \/** Check if we are in a Boost based theme. *\/\n boost: '.local-fullscreen-boost',\n \/** The class of the fullscreen button. *\/\n button: '.local-fullscreen',\n \/** The area that scrolls in Boost. *\/\n scrollBoost: '#page',\n};\n\n\/**\n * Store of classes used by the fullscreen button.\n *\/\nconst CLASSES = {\n \/** Added to the body tag to switch fullscreen mode on. *\/\n toggle: 'fullscreenmode',\n \/** The button is fixed relative to it's container. *\/\n fixed: 'fixed',\n \/** The button floats at the top of the browser window. *\/\n 'float': 'float'\n};\n\n\/**\n * Store of template names used by the fullscreen button.\n *\/\nconst TEMPLATES = {\n \/** The name of the template that renders the fullscreen button. *\/\n button: 'local_fullscreen\/button'\n};\n\n\/**\n * Used to stop Fullscreen mode from toggling repeatedly if the keyboard combination is held down.\n *\n * @type Boolean\n *\/\nlet KEYPRESSED = false;\n\n\/**\n * The key combination used to toggle fullscreen mode.\n *\n * @type {String}\n *\/\nlet TOGGLE;\n\n\/**\n * Adds the full screen button to the page.\n *\n * @param {boolean} fullscreen Should the button will be initialised in fullscreen mode.\n * @param {String} toggle The toggle combination for the button.\n * @returns {undefined}\n *\/\nexport const init = async(fullscreen, toggle) => {\n const pendingPromise = new Pending('local_fullscreen\/setup');\n\n Log.debug('Adding fullscreen button to the page (fullscreen=' + fullscreen + ')', 'local_fullscreen\/button');\n\n TOGGLE = toggle;\n\n \/\/ Get the user's fullscreen preference.\n let variables = {\n fullscreen: false,\n toggle: TOGGLE\n };\n if (fullscreen == true) {\n document.querySelector('body').classList.add(CLASSES.toggle);\n variables.fullscreen = true;\n }\n\n \/\/ Find the attachment point.\n let attachPoint = document.querySelector(SELECTORS.attach);\n\n if (!attachPoint) {\n Log.debug('The fullscreen button is not compatible with the current theme', 'local_fullscreen\/button');\n pendingPromise.resolve();\n return;\n }\n\n \/\/ Attach the button to the page.\n let bottonString = await Templates.render(TEMPLATES.button, variables);\n let element = document.createRange().createContextualFragment(bottonString);\n attachPoint.prepend(element);\n\n let button = document.querySelector(SELECTORS.button);\n\n \/\/ Add handlers.\n button.addEventListener('click', toggleFullscreen);\n button.addEventListener('keydown', spaceDownHandler);\n button.addEventListener('keyup', spaceUpHandler);\n document.addEventListener('keydown', keyDownHandler);\n document.addEventListener('keyup', keyUpHandler);\n document.addEventListener('scroll', scrollHandler, {capture: true});\n\n pendingPromise.resolve();\n};\n\n\/**\n * Stop the page scrolling when the user presses space.\n *\n * @param {KeyboardEvent} event\n * @returns {undefined}\n *\/\nconst spaceDownHandler = (event) => {\n if (event.code !== 'Space') {\n return;\n }\n event.preventDefault();\n};\n\n\/**\n * Toggle fullscreen mode when space bar is used while focusing on the element.\n *\n * @param {KeyboardEvent} event\n * @returns {undefined}\n *\/\nconst spaceUpHandler = (event) => {\n if (event.code !== 'Space') {\n return;\n }\n event.preventDefault();\n toggleFullscreen();\n};\n\n\/**\n * Toggle fullscreen mode when Ctrl+Alt+b is pressed.\n *\n * @param {KeyboardEvent} event\n * @returns {undefined}\n *\/\nconst keyDownHandler = (event) => {\n if (KEYPRESSED === true || KeyParser.parse(event) !== TOGGLE) {\n return;\n }\n KEYPRESSED = true;\n toggleFullscreen();\n};\n\n\/**\n * Lets us know the keyboard toggle combination has stopped.\n *\n * @param {KeyboardEvent} event\n * @returns {undefined}\n *\/\nconst keyUpHandler = (event) => {\n if (KEYPRESSED === false || KeyParser.parse(event) !== TOGGLE) {\n return;\n }\n KEYPRESSED = false;\n};\n\n\/**\n * Changes the mode of the fullscreen button to either be relative to an element,\n * or floating at the top of the page, depending on how far a user has scrolled.\n *\n * @returns {undefined}\n *\/\nconst scrollHandler = () => {\n let button = document.querySelector(SELECTORS.button);\n let boostArea = document.querySelector(SELECTORS.scrollBoost);\n if (window.scrollY > 205 || boostArea.scrollTop > 205) {\n button.classList.add(CLASSES.float);\n } else {\n button.classList.remove(CLASSES.float);\n }\n};\n\n\/**\n * Toggles the fullscreen mode.\n *\n * @returns {undefined}\n *\/\nconst toggleFullscreen = async() => {\n const pendingPromise = new Pending('local_fullscreen\/toggle');\n\n let bodyelement = document.querySelector('body');\n let button = document.querySelector(SELECTORS.button);\n\n \/\/ We do this here so that both strings are chached in the browser the first time\n \/\/ the button is used, since it seems likely the other will be used at that point.\n let turnon;\n let turnoff;\n [turnon, turnoff] = await Str.get_strings(\n [\n {key: 'turnon', component: 'local_fullscreen', param: TOGGLE},\n {key: 'turnoff', component: 'local_fullscreen', param: TOGGLE},\n ]\n );\n\n let preference;\n if (bodyelement.classList.contains(CLASSES.toggle)) {\n bodyelement.classList.remove(CLASSES.toggle);\n button.setAttribute('aria-checked', 'false');\n button.setAttribute('title', turnon);\n preference = false;\n } else {\n bodyelement.classList.add(CLASSES.toggle);\n button.setAttribute('aria-checked', 'true');\n button.setAttribute('title', turnoff);\n preference = true;\n }\n updateUserPreference(preference);\n\n pendingPromise.resolve();\n};\n\n\/**\n * Updates the user's fullscreen preference.\n *\n * @param {boolean} fullscreen\n * @returns {Promise}\n *\/\nconst updateUserPreference = (fullscreen) => {\n let preferencePromise = setUserPreference('fullscreenmode', fullscreen);\n return preferencePromise.catch(Notification.exception);\n};\n"],"names":["SELECTORS","CLASSES","TEMPLATES","TOGGLE","KEYPRESSED","async","fullscreen","toggle","pendingPromise","Pending","debug","variables","document","querySelector","classList","add","attachPoint","resolve","bottonString","Templates","render","element","createRange","createContextualFragment","prepend","button","addEventListener","toggleFullscreen","spaceDownHandler","spaceUpHandler","keyDownHandler","keyUpHandler","scrollHandler","capture","event","code","preventDefault","KeyParser","parse","boostArea","window","scrollY","scrollTop","remove","turnon","turnoff","preference","bodyelement","Str","get_strings","key","component","param","contains","setAttribute","updateUserPreference","catch","Notification","exception"],"mappings":";;;;;;;;mVAmCMA,iBAEM,eAFNA,iBAMM,oBANNA,sBAQW,QAMXC,eAEM,iBAFNA,cAMO,QAMPC,iBAEM,8BAeRC,OAPAC,YAAa,gBAgBGC,MAAMC,WAAYC,gBAC5BC,eAAiB,IAAIC,iBAAQ,uCAE\/BC,MAAM,oDAAsDJ,WAAa,IAAK,2BAElFH,OAASI,WAGLI,UAAY,CACZL,YAAY,EACZC,OAAQJ,QAEM,GAAdG,aACAM,SAASC,cAAc,QAAQC,UAAUC,IAAId,gBAC7CU,UAAUL,YAAa,OAIvBU,YAAcJ,SAASC,cAAcb,sBAEpCgB,gCACGN,MAAM,iEAAkE,gCAC5EF,eAAeS,cAKfC,mBAAqBC,UAAUC,OAAOlB,iBAAkBS,WACxDU,QAAUT,SAASU,cAAcC,yBAAyBL,cAC9DF,YAAYQ,QAAQH,aAEhBI,OAASb,SAASC,cAAcb,kBAGpCyB,OAAOC,iBAAiB,QAASC,kBACjCF,OAAOC,iBAAiB,UAAWE,kBACnCH,OA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