{"version":3,"file":"colourwidget.min.js","sources":["https:\/\/www.virtual.facen.una.py\/gradofacen\/local\/accessibility\/amd\/src\/colourwidget.js"],"sourcesContent":["\/\/ This file is part of Moodle - https:\/\/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 * Default script for colourpicker widgets\n *\n * @module local\/accessibility\n * @copyright 2023 Ponlawat Weerapanpisit \n * @license https:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport {saveWidgetConfig} from '.\/common';\nimport $ from 'jquery';\n\n\/**\n * Function to initialise a colour-picker widget\n * @param {string} widget plugin full name\n * @param {string} savewidgetname widget name to be saved as user config\n * @param {string} stylename css attribute name to be applied the colour value\n * @param {string} bodyclassname class name of default value in body tag\n * @param {string} selector css selector of affected elements\n *\/\nexport const init = (widget, savewidgetname, stylename, bodyclassname = undefined, selector = 'body, body *') => {\n $(() => {\n const revokedefault = () => {\n if (bodyclassname) {\n $('body').removeClass(bodyclassname);\n }\n };\n\n const defaultattrname = `data-default-${stylename}`;\n const $container = $(`#${widget}-container`);\n if (!$container.length) {\n return;\n }\n\n const $input = $container.find(`input[name=color]`);\n if (!$input.length) {\n return;\n }\n $input.on('change input', async() => {\n const colour = $input.val();\n if (!colour) {\n return;\n }\n if (!\/#[0-9a-f]{6}\/gi.exec(colour)) {\n return;\n }\n revokedefault();\n for (const $element of [...$(selector)].map(e => $(e))) {\n if (!$element.attr(defaultattrname)) {\n $element.attr(defaultattrname, $element.css(stylename));\n }\n $element.css(stylename, colour);\n }\n await saveWidgetConfig(savewidgetname, colour);\n });\n\n const $resetbtn = $container.find(`.${widget}-resetbtn`);\n if ($resetbtn.length) {\n $resetbtn.on('click', async() => {\n $input.val('');\n revokedefault();\n for (const element of [...$(selector)]) {\n const $element = $(element);\n const defaultcolour = $element.attr(defaultattrname) ?? '';\n $element.css(stylename, defaultcolour);\n $element.removeAttr(defaultattrname);\n }\n await saveWidgetConfig(savewidgetname, null);\n });\n }\n });\n};\n"],"names":["widget","savewidgetname","stylename","bodyclassname","undefined","selector","revokedefault","removeClass","defaultattrname","$container","length","$input","find","on","async","colour","val","exec","$element","map","e","attr","css","$resetbtn","element","defaultcolour","removeAttr"],"mappings":";;;;;;;wJAkCoB,SAACA,OAAQC,eAAgBC,eAAWC,0EAAgBC,EAAWC,gEAAW,oCACxF,WACQC,cAAgB,KACdH,mCACE,QAAQI,YAAYJ,gBAIxBK,uCAAkCN,WAClCO,YAAa,8BAAMT,0BACpBS,WAAWC,oBAIVC,OAASF,WAAWG,8BACrBD,OAAOD,cAGZC,OAAOE,GAAG,gBAAgBC,gBAChBC,OAASJ,OAAOK,SACjBD,QAGA,iBAAiBE,KAAKF,SAG3BT,oBACK,MAAMY,WAAY,KAAI,mBAAEb,WAAWc,KAAIC,IAAK,mBAAEA,KAC1CF,SAASG,KAAKb,kBACfU,SAASG,KAAKb,gBAAiBU,SAASI,IAAIpB,YAEhDgB,SAASI,IAAIpB,UAAWa,cAEtB,4BAAiBd,eAAgBc,kBAGrCQ,UAAYd,WAAWG,gBAASZ,qBAClCuB,UAAUb,QACVa,UAAUV,GAAG,SAASC,UAClBH,OAAOK,IAAI,IACXV,oBACK,MAAMkB,UAAW,KAAI,mBAAEnB,WAAY,0BAC9Ba,UAAW,mBAAEM,SACbC,qCAAgBP,SAASG,KAAKb,0DAAoB,GACxDU,SAASI,IAAIpB,UAAWuB,eACxBP,SAASQ,WAAWlB,uBAElB,4BAAiBP,eAAgB"}