{"version":3,"file":"events.min.js","sources":["https:\/\/lms.wuca.us\/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;\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 = async elementId => {\n \/\/ Add an additional check for changes made.\n changesMadeString = await getString('changesmadereallygoaway', 'moodle');\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","changesMadeCheck","e","returnValue","types","uploadStarted","uploadCompleted","uploadChanged","triggerUploadStarted","elementId","window","addEventListener","customEvent","CustomEvent","bubbles","cancellable","document","getElementById","dispatchEvent","removeEventListener"],"mappings":"ySA0BIA,+LAMEC,iBAAmB,SAAAC,GACjBA,IACAA,EAAEC,YAAcH,oBAOXI,MAAQ,CACjBC,cAAe,0BACfC,gBAAiB,4BACjBC,cAAe,4DASNC,kDAAuB,iBAAMC,wJAEZ,mBAAU,0BAA2B,wBAA\/DT,gCACAU,OAAOC,iBAAiB,eAAgBV,kBAClCW,YAAc,IAAIC,YAAYT,MAAMC,cAAe,CACrDS,SAAS,EACTC,aAAa,IAEDC,SAASC,eAAeR,WAChCS,cAAcN,sCAEfA,4fAS2B,SAAAH,WAElCC,OAAOS,oBAAoB,eAAgBlB,sBACrCW,YAAc,IAAIC,YAAYT,MAAME,gBAAiB,CACvDQ,SAAS,EACTC,aAAa,WAEDC,SAASC,eAAeR,WAChCS,cAAcN,aAEfA,0CAUyB,SAAAH,eAE1BG,YAAc,IAAIC,YAAYT,MAAMG,cAAe,CACrDO,SAAS,EACTC,aAAa,WAGDC,SAASC,eAAeR,WAChCS,cAAcN,aAEfA"}