moodle/lib/amd/build/edit_switch.min.js.map
2021-09-29 09:25:36 +02:00

1 line
5.1 KiB
Plaintext

{"version":3,"sources":["../src/edit_switch.js"],"names":["setEditMode","context","setmode","methodname","args","toggleEditSwitch","editSwitch","checked","setAttribute","event","notifyEditModeSet","defaultPrevented","window","location","dataset","pageurl","eventTypes","editModeSet","container","editMode","cancelable","init","editingSwitchId","document","getElementById","addEventListener","then","result","success","catch","displayException"],"mappings":"6MAkCMA,CAAAA,CAAW,CAAG,SAACC,CAAD,CAAUC,CAAV,QAAsB,WAAU,CAAC,CACjDC,UAAU,CAAE,sBADqC,CAEjDC,IAAI,CAAE,CACFH,OAAO,CAAPA,CADE,CAEFC,OAAO,CAAPA,CAFE,CAF2C,CAAD,CAAV,EAMtC,CANsC,CAAtB,C,CAedG,CAAgB,CAAG,SAAAC,CAAU,CAAI,CACnC,GAAIA,CAAU,CAACC,OAAf,CAAwB,CACpBD,CAAU,CAACE,YAAX,CAAwB,cAAxB,IACH,CAFD,IAEO,CACHF,CAAU,CAACE,YAAX,CAAwB,cAAxB,IACH,CAED,GAAMC,CAAAA,CAAK,CAAGC,CAAiB,CAACJ,CAAD,CAAaA,CAAU,CAACC,OAAxB,CAA/B,CACA,GAAI,CAACE,CAAK,CAACE,gBAAX,CAA6B,CACzBC,MAAM,CAACC,QAAP,CAAkBP,CAAU,CAACQ,OAAX,CAAmBC,OACxC,CACJ,C,CAQYC,CAAU,CAAG,CAUtBC,WAAW,CAAE,8BAVS,C,mBA0BpBP,CAAAA,CAAiB,CAAG,SAACQ,CAAD,CAAYC,CAAZ,QAAyB,oBAC/CH,CAAU,CAACC,WADoC,CAE/C,CAACE,QAAQ,CAARA,CAAD,CAF+C,CAG/CD,CAH+C,CAI/C,CAACE,UAAU,GAAX,CAJ+C,CAAzB,C,QAYN,QAAPC,CAAAA,IAAO,CAAAC,CAAe,CAAI,CACnC,GAAMhB,CAAAA,CAAU,CAAGiB,QAAQ,CAACC,cAAT,CAAwBF,CAAxB,CAAnB,CACAhB,CAAU,CAACmB,gBAAX,CAA4B,QAA5B,CAAsC,UAAM,CACxCzB,CAAW,CAACM,CAAU,CAACQ,OAAX,CAAmBb,OAApB,CAA6BK,CAAU,CAACC,OAAxC,CAAX,CACCmB,IADD,CACM,SAAAC,CAAM,CAAI,CACZ,GAAIA,CAAM,CAACC,OAAX,CAAoB,CAChBvB,CAAgB,CAACC,CAAD,CACnB,CAFD,IAEO,CACHA,CAAU,CAACC,OAAX,GACH,CAEJ,CARD,EASCsB,KATD,CASOC,WATP,CAUH,CAXD,CAYH,C","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 * Controls the edit switch.\n *\n * @module core/edit_switch\n * @copyright 2021 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {call as fetchMany} from 'core/ajax';\nimport {dispatchEvent} from 'core/event_dispatcher';\nimport {exception as displayException} from 'core/notification';\n\n/**\n * Change the Edit mode.\n *\n * @param {number} context The contextid that editing is being set for\n * @param {bool} setmode Whether editing is set or not\n * @return {Promise} Resolved with an array file the stored file url.\n */\nconst setEditMode = (context, setmode) => fetchMany([{\n methodname: 'core_change_editmode',\n args: {\n context,\n setmode,\n },\n}])[0];\n\n/**\n * Toggle the edit switch\n *\n * @method\n * @protected\n * @param {HTMLElement} editSwitch\n */\nconst toggleEditSwitch = editSwitch => {\n if (editSwitch.checked) {\n editSwitch.setAttribute('aria-checked', true);\n } else {\n editSwitch.setAttribute('aria-checked', false);\n }\n\n const event = notifyEditModeSet(editSwitch, editSwitch.checked);\n if (!event.defaultPrevented) {\n window.location = editSwitch.dataset.pageurl;\n }\n};\n\n/**\n * Names of events for core/edit_switch.\n *\n * @static\n * @property {String} editModeSet See {@link event:core/edit_switch/editModeSet}\n */\nexport const eventTypes = {\n /**\n * An event triggered when the edit mode toggled.\n *\n * @event core/edit_switch/editModeSet\n * @type {CustomEvent}\n * @property {HTMLElement} target The switch used to toggle the edit mode\n * @property {object} detail\n * @property {bool} detail.editMode\n */\n editModeSet: 'core/edit_switch/editModeSet',\n};\n\n/**\n * Dispatch the editModeSet event after changing the edit mode.\n *\n * This event is cancelable.\n *\n * The default action is to reload the page after toggling the edit mode.\n *\n * @method\n * @protected\n * @param {HTMLElement} container\n * @param {bool} editMode\n * @returns {CustomEvent}\n */\nconst notifyEditModeSet = (container, editMode) => dispatchEvent(\n eventTypes.editModeSet,\n {editMode},\n container,\n {cancelable: true}\n);\n\n/**\n * Add the eventlistener for the editswitch.\n *\n * @param {string} editingSwitchId The id of the editing switch to listen for\n */\nexport const init = editingSwitchId => {\n const editSwitch = document.getElementById(editingSwitchId);\n editSwitch.addEventListener('change', () => {\n setEditMode(editSwitch.dataset.context, editSwitch.checked)\n .then(result => {\n if (result.success) {\n toggleEditSwitch(editSwitch);\n } else {\n editSwitch.checked = false;\n }\n return;\n })\n .catch(displayException);\n });\n};\n"],"file":"edit_switch.min.js"}