{"version":3,"file":"events.min.js","sources":["https:\/\/www.alsg.org\/home\/lib\/amd\/src\/local\/inplace_editable\/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 * Inplace editable module events\n *\n * @module core\/local\/inplace_editable\/events\n * @copyright 2021 Paul Holden \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport $ from 'jquery';\nimport {dispatchEvent} from 'core\/event_dispatcher';\n\n\/**\n * Module events\n *\n * @constant\n * @property {String} elementUpdated See {@link event:core\/inplace_editable:updated}\n * @property {String} elementUpdateFailed See {@link event:core\/inplace_editable:updateFailed}\n *\/\nexport const eventTypes = {\n\n \/**\n * Event triggered when an element has been updated\n *\n * @event core\/inplace_editable:updated\n * @type {CustomEvent}\n * @property {HTMLElement} target The element that was updated\n * @property {Object} detail\n * @property {Object} detail.ajaxreturn The data returned from the update AJAX request\n * @property {String} detail.oldvalue The previous value of the element\n *\/\n elementUpdated: 'core\/inplace_editable:updated',\n\n \/**\n * Event triggered when an element update has failed\n *\n * @event core\/inplace_editable:updateFailed\n * @type {CustomEvent}\n * @property {HTMLElement} target The element that failed to update\n * @property {Object} detail\n * @property {Object} detail.exception The raised exception\n * @property {String} detail.newvalue The intended value of the element\n *\/\n elementUpdateFailed: 'core\/inplace_editable:updateFailed',\n};\n\n\/**\n * Notify element of successful update\n *\n * @method\n * @param {HTMLElement} element The element that was updated\n * @param {Object} ajaxreturn The data returned from the update AJAX request\n * @param {String} oldvalue The previous value of the element\n * @returns {CustomEvent}\n * @fires event:core\/inplace_editable:updated\n *\/\nexport const notifyElementUpdated = (element, ajaxreturn, oldvalue) => dispatchEvent(\n eventTypes.elementUpdated,\n {\n ajaxreturn,\n oldvalue,\n },\n element\n);\n\n\/**\n * Notify element of failed update\n *\n * @method\n * @param {HTMLElement} element The element that failed to update\n * @param {Object} exception The raised exception\n * @param {String} newvalue The intended value of the element\n * @returns {CustomEvent}\n * @fires event:core\/inplace_editable:updateFailed\n *\/\nexport const notifyElementUpdateFailed = (element, exception, newvalue) => dispatchEvent(\n eventTypes.elementUpdateFailed,\n {\n exception,\n newvalue,\n },\n element,\n {\n cancelable: true\n }\n);\n\nlet legacyEventsRegistered = false;\nif (!legacyEventsRegistered) {\n \/\/ The following event triggers are legacy and will be removed in the future.\n \/\/ The following approach provides a backwards-compatability layer for the new events.\n \/\/ Code should be updated to make use of native events.\n\n \/\/ Listen for the new native elementUpdated event, and trigger the legacy jQuery event.\n document.addEventListener(eventTypes.elementUpdated, event => {\n const legacyEvent = $.Event('updated', event.detail);\n $(event.target).trigger(legacyEvent);\n });\n\n \/\/ Listen for the new native elementUpdateFailed event, and trigger the legacy jQuery event.\n document.addEventListener(eventTypes.elementUpdateFailed, event => {\n const legacyEvent = $.Event('updatefailed', event.detail);\n $(event.target).trigger(legacyEvent);\n\n \/\/ If the legacy event is cancelled, so should the native event.\n if (legacyEvent.isDefaultPrevented()) {\n event.preventDefault();\n }\n });\n\n legacyEventsRegistered = true;\n}\n"],"names":["eventTypes","elementUpdated","elementUpdateFailed","element","ajaxreturn","oldvalue","exception","newvalue","cancelable","legacyEventsRegistered","document","addEventListener","event","legacyEvent","$","Event","detail","target","trigger","isDefaultPrevented","preventDefault"],"mappings":";;;;;;;uNAiCaA,WAAa,CAYtBC,eAAgB,gCAYhBC,oBAAqB,mGAaW,CAACC,QAASC,WAAYC,YAAa,mCACnEL,WAAWC,eACX,CACIG,WAAAA,WACAC,SAAAA,UAEJF,4CAaqC,CAACA,QAASG,UAAWC,YAAa,mCACvEP,WAAWE,oBACX,CACII,UAAAA,UACAC,SAAAA,UAEJJ,QACA,CACIK,YAAY,QAIhBC,wBAAyB,EACxBA,yBAMDC,SAASC,iBAAiBX,WAAWC,gBAAgBW,cAC3CC,YAAcC,gBAAEC,MAAM,UAAWH,MAAMI,4BAC3CJ,MAAMK,QAAQC,QAAQL,gBAI5BH,SAASC,iBAAiBX,WAAWE,qBAAqBU,cAChDC,YAAcC,gBAAEC,MAAM,eAAgBH,MAAMI,4BAChDJ,MAAMK,QAAQC,QAAQL,aAGpBA,YAAYM,sBACZP,MAAMQ,oBAIdX,wBAAyB"}