{"version":3,"file":"events.min.js","sources":["https:\/\/m2.ompec.ru\/lib\/form\/amd\/src\/events.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 .\n\n\/**\n * Contain the events the form component can trigger.\n *\n * @module core_form\/events\n * @copyright 2021 Huong Nguyen \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n * @since 3.10\n *\/\n\nimport {get_string as getString} from 'core\/str';\n\nlet changesMadeString;\ngetString('changesmadereallygoaway', 'moodle').then(string => {\n changesMadeString = string;\n return string;\n}).catch();\n\n\/**\n * Prevent user navigate away when upload progress still running.\n * @param {Event} e The event\n *\/\nconst changesMadeCheck = e => {\n if (e) {\n e.returnValue = changesMadeString;\n }\n};\n\n\/**\n * List of the events.\n **\/\nexport const types = {\n uploadStarted: 'core_form\/uploadStarted',\n uploadCompleted: 'core_form\/uploadCompleted',\n uploadChanged: 'core_form\/uploadChanged'\n};\n\n\/**\n * Trigger upload start event.\n *\n * @param {String} elementId\n * @returns {CustomEvent}\n *\/\nexport const triggerUploadStarted = elementId => {\n \/\/ Add an additional check for changes made.\n window.addEventListener('beforeunload', changesMadeCheck);\n const customEvent = new CustomEvent(types.uploadStarted, {\n bubbles: true,\n cancellable: false\n });\n const element = document.getElementById(elementId);\n element.dispatchEvent(customEvent);\n\n return customEvent;\n};\n\n\/**\n * Trigger upload complete event.\n *\n * @param {String} elementId\n * @returns {CustomEvent}\n *\/\nexport const triggerUploadCompleted = elementId => {\n \/\/ Remove the additional check for changes made.\n window.removeEventListener('beforeunload', changesMadeCheck);\n const customEvent = new CustomEvent(types.uploadCompleted, {\n bubbles: true,\n cancellable: false\n });\n const element = document.getElementById(elementId);\n element.dispatchEvent(customEvent);\n\n return customEvent;\n};\n\n\/**\n * Trigger an event to notify the file upload field has been changed.\n *\n * @method\n * @param {String} elementId The element which was changed\n * @returns {CustomEvent}\n *\/\n export const notifyUploadChanged = elementId => {\n\n const customEvent = new CustomEvent(types.uploadChanged, {\n bubbles: true,\n cancellable: false\n });\n\n const element = document.getElementById(elementId);\n element.dispatchEvent(customEvent);\n\n return customEvent;\n};\n"],"names":["changesMadeString","then","string","catch","changesMadeCheck","e","returnValue","types","uploadStarted","uploadCompleted","uploadChanged","elementId","window","addEventListener","customEvent","CustomEvent","bubbles","cancellable","document","getElementById","dispatchEvent","removeEventListener"],"mappings":";;;;;;;;;IA0BIA,+MACM,0BAA2B,UAAUC,MAAK,SAAAC,eAChDF,kBAAoBE,OACbA,UACRC,YAMGC,iBAAmB,SAAAC,GACjBA,IACAA,EAAEC,YAAcN,oBAOXO,MAAQ,CACjBC,cAAe,0BACfC,gBAAiB,4BACjBC,cAAe,8EASiB,SAAAC,WAEhCC,OAAOC,iBAAiB,eAAgBT,sBAClCU,YAAc,IAAIC,YAAYR,MAAMC,cAAe,CACrDQ,SAAS,EACTC,aAAa,WAEDC,SAASC,eAAeR,WAChCS,cAAcN,aAEfA,6CAS2B,SAAAH,WAElCC,OAAOS,oBAAoB,eAAgBjB,sBACrCU,YAAc,IAAIC,YAAYR,MAAME,gBAAiB,CACvDO,SAAS,EACTC,aAAa,WAEDC,SAASC,eAAeR,WAChCS,cAAcN,aAEfA,0CAUyB,SAAAH,eAE1BG,YAAc,IAAIC,YAAYR,MAAMG,cAAe,CACrDM,SAAS,EACTC,aAAa,WAGDC,SAASC,eAAeR,WAChCS,cAAcN,aAEfA"}