{"version":3,"file":"modal_factory.min.js","sources":["https:\/\/www.feeacademy.global\/lib\/amd\/src\/modal_factory.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 * Create a modal.\n *\n * @module core\/modal_factory\n * @copyright 2016 Ryan Wyllie \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n * @deprecated since Moodle 4.3\n * @todo Final deprecation in Moodle 4.7\/5.2. See MDL-79128\/\n *\/\n\nimport $ from 'jquery';\nimport ModalEvents from 'core\/modal_events';\nimport * as ModalRegistry from 'core\/modal_registry';\nimport Modal from 'core\/modal';\nimport ModalSaveCancel from 'core\/modal_save_cancel';\nimport ModalDeleteCancel from 'core\/modal_delete_cancel';\nimport ModalCancel from 'core\/modal_cancel';\nimport ModalAlert from 'core\/local\/modal\/alert';\nimport * as Notification from 'core\/notification';\nimport * as CustomEvents from 'core\/custom_interaction_events';\nimport Pending from 'core\/pending';\n\n\/**\n * The available standard modals.\n *\n * @property {String} DEFAULT The default modal\n * @property {String} SAVE_CANCEL A modal which can be used to either save, or cancel.\n * @property {String} DELETE_CANCEL A modal which can be used to either delete, or cancel.\n * @property {String} CANCEL A modal which displayed a cancel button\n * @property {String} ALERT An information modal which only displays information.\n *\/\nexport const types = {\n DEFAULT: 'DEFAULT',\n SAVE_CANCEL: ModalSaveCancel.TYPE,\n DELETE_CANCEL: ModalDeleteCancel.TYPE,\n CANCEL: ModalCancel.TYPE,\n ALERT: ModalAlert.TYPE,\n};\n\n\/\/ Most modals are self-registering.\n\/\/ We do not self-register the base Modal because we do not want to define a default TYPE\n\/\/ on the class that every other modal extends.\nModalRegistry.register(types.DEFAULT, Modal, Modal.TEMPLATE);\n\n\/**\n * Set up the events required to show the modal and return focus when the modal\n * is closed.\n *\n * @method setUpTrigger\n * @private\n * @param {Promise} modalPromise The modal instance\n * @param {object} triggerElement The jQuery element to open the modal\n * @param {object} modalConfig The modal configuration given to the factory\n *\/\nconst setUpTrigger = (modalPromise, triggerElement, modalConfig) => {\n \/\/ The element that actually shows the modal.\n let actualTriggerElement = null;\n \/\/ Check if the client has provided a callback function to be called\n \/\/ before the modal is displayed.\n const hasPreShowCallback = (typeof modalConfig.preShowCallback == 'function');\n \/\/ Function to handle the trigger element being activated.\n const triggeredCallback = (e, data) => {\n const pendingPromise = new Pending('core\/modal_factory:setUpTrigger:triggeredCallback');\n actualTriggerElement = $(e.currentTarget);\n\n \/\/ eslint-disable-next-line promise\/catch-or-return\n modalPromise.then(function(modal) {\n if (hasPreShowCallback) {\n \/\/ If the client provided a pre-show callback then execute\n \/\/ it now before showing the modal.\n modalConfig.preShowCallback(actualTriggerElement, modal);\n }\n\n modal.show();\n\n return modal;\n })\n .then(pendingPromise.resolve);\n data.originalEvent.preventDefault();\n };\n\n \/\/ The trigger element can either be a single element or it can be an\n \/\/ element + selector pair to create a delegated event handler to trigger\n \/\/ the modal.\n if (Array.isArray(triggerElement)) {\n const selector = triggerElement[1];\n triggerElement = triggerElement[0];\n\n CustomEvents.define(triggerElement, [CustomEvents.events.activate]);\n triggerElement.on(CustomEvents.events.activate, selector, triggeredCallback);\n } else {\n CustomEvents.define(triggerElement, [CustomEvents.events.activate]);\n triggerElement.on(CustomEvents.events.activate, triggeredCallback);\n }\n\n \/\/ eslint-disable-next-line promise\/catch-or-return\n modalPromise.then(function(modal) {\n modal.getRoot().on(ModalEvents.hidden, function() {\n \/\/ Focus on the trigger element that actually launched the modal.\n if (actualTriggerElement !== null) {\n actualTriggerElement.focus();\n }\n });\n\n return modal;\n });\n};\n\n\/**\n * Create a Modal instance.\n *\n * @method create\n * @param {object} modalConfig The configuration to create the modal instance\n * @param {object} triggerElement The trigger HTML jQuery object\n * @return {promise} Resolved with a Modal instance\n *\/\nexport const create = (modalConfig, triggerElement) => {\n window.console.warn(\n 'The modal_factory has been deprecated since Moodle 4.3. Please use the create method on your target modal type instead.',\n );\n \/\/ Use of the triggerElement has been deprecated.\n const type = modalConfig.type || types.DEFAULT;\n\n const registryConf = ModalRegistry.get(type);\n if (!registryConf) {\n Notification.exception({message: `Unable to find modal of type: ${type}`});\n }\n\n const modal = registryConf.module.create(modalConfig);\n\n if (triggerElement) {\n window.console.warn(\n 'The triggerElement feature of the modal_factory has been deprecated. Please use event listeners instead.',\n );\n setUpTrigger(modal, triggerElement, modalConfig);\n }\n\n return $.when(new Promise((resolve, reject) => {\n modal\n .then(resolve)\n .catch(reject);\n }));\n};\n\nexport default {\n create,\n types,\n};\n"],"names":["types","DEFAULT","SAVE_CANCEL","ModalSaveCancel","TYPE","DELETE_CANCEL","ModalDeleteCancel","CANCEL","ModalCancel","ALERT","ModalAlert","ModalRegistry","register","Modal","TEMPLATE","create","modalConfig","triggerElement","window","console","warn","type","registryConf","get","Notification","exception","message","modal","module","modalPromise","actualTriggerElement","hasPreShowCallback","preShowCallback","triggeredCallback","e","data","pendingPromise","Pending","currentTarget","then","show","resolve","originalEvent","preventDefault","Array","isArray","selector","CustomEvents","define","events","activate","on","getRoot","ModalEvents","hidden","focus","setUpTrigger","$","when","Promise","reject","catch"],"mappings":";;;;;;;;;2pBA8CaA,MAAQ,CACjBC,QAAS,UACTC,YAAaC,2BAAgBC,KAC7BC,cAAeC,6BAAkBF,KACjCG,OAAQC,sBAAYJ,KACpBK,MAAOC,eAAWN,2BAMtBO,cAAcC,SAASZ,MAAMC,QAASY,eAAOA,eAAMC,gBA0EtCC,OAAS,CAACC,YAAaC,kBAChCC,OAA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