{"version":3,"file":"rangewidget.min.js","sources":["https:\/\/moodle.a2u.fr\/local\/accessibility\/amd\/src\/rangewidget.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 range-selector 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 $ from 'jquery';\n\n\/**\n * Callback type after range value being changed\n *\n * @callback valueChangedCallback\n * @param {number} newvalue new value\n * @returns {void}\n *\/\n\n\/**\n * Initialise JS for a range-selector widget\n *\n * @param {string} name widget name\n * @param {valueChangedCallback} callback callback function when value changed\n * @param {string|number} userdefault default value of user\n * @returns {void}\n *\/\nexport const initrangewidget = (name, callback, userdefault = undefined) => {\n const $inputrange = $(`#${name}-input`);\n const $label = $(`#${name}-label`);\n const $btnup = $(`#${name}-btnup`);\n const $btndown = $(`#${name}-btndown`);\n const $btnreset = $(`#${name}-btnreset`);\n\n if (!$inputrange.length) {\n return;\n }\n\n const min = parseFloat($inputrange.attr('min'));\n const max = parseFloat($inputrange.attr('max'));\n const step = parseFloat($inputrange.attr('step'));\n const defaultvalue = parseFloat($inputrange.attr('data-default'));\n\n $inputrange.on('input', () => {\n if ($label.length) {\n $label.html($inputrange.val());\n }\n });\n\n $inputrange.on('change', () => {\n if ($label.length) {\n $label.html($inputrange.val());\n }\n if (callback) {\n callback(parseFloat($inputrange.val()));\n }\n });\n\n if ($btnup.length) {\n $btnup.on('click', () => {\n $inputrange.val(Math.min(max, parseFloat($inputrange.val()) + step));\n $inputrange.trigger('change');\n });\n }\n\n if ($btndown.length) {\n $btndown.on('click', () => {\n $inputrange.val(Math.max(min, parseFloat($inputrange.val()) - step));\n $inputrange.trigger('change');\n });\n }\n\n if ($btnreset.length) {\n $btnreset.on('click', () => {\n $inputrange.val(defaultvalue);\n $inputrange.trigger('change');\n });\n }\n\n if (userdefault) {\n $inputrange.val(parseFloat(userdefault));\n $inputrange.trigger('change');\n }\n};\n"],"names":["name","callback","userdefault","undefined","$inputrange","$label","$btnup","$btndown","$btnreset","length","min","parseFloat","attr","max","step","defaultvalue","on","html","val","Math","trigger"],"mappings":";;;;;;;8KAyC+B,SAACA,KAAMC,cAAUC,wEAAcC,QACpDC,aAAc,8BAAMJ,gBACpBK,QAAS,8BAAML,gBACfM,QAAS,8BAAMN,gBACfO,UAAW,8BAAMP,kBACjBQ,WAAY,8BAAMR,uBAEnBI,YAAYK,oBAIXC,IAAMC,WAAWP,YAAYQ,KAAK,QAClCC,IAAMF,WAAWP,YAAYQ,KAAK,QAClCE,KAAOH,WAAWP,YAAYQ,KAAK,SACnCG,aAAeJ,WAAWP,YAAYQ,KAAK,iBAEjDR,YAAYY,GAAG,SAAS,KAChBX,OAAOI,QACPJ,OAAOY,KAAKb,YAAYc,UAIhCd,YAAYY,GAAG,UAAU,KACjBX,OAAOI,QACPJ,OAAOY,KAAKb,YAAYc,OAExBjB,UACAA,SAASU,WAAWP,YAAYc,WAIpCZ,OAAOG,QACPH,OAAOU,GAAG,SAAS,KACfZ,YAAYc,IAAIC,KAAKT,IAAIG,IAAKF,WAAWP,YAAYc,OAASJ,OAC9DV,YAAYgB,QAAQ,aAIxBb,SAASE,QACTF,SAASS,GAAG,SAAS,KACjBZ,YAAYc,IAAIC,KAAKN,IAAIH,IAAKC,WAAWP,YAAYc,OAASJ,OAC9DV,YAAYgB,QAAQ,aAIxBZ,UAAUC,QACVD,UAAUQ,GAAG,SAAS,KAClBZ,YAAYc,IAAIH,cAChBX,YAAYgB,QAAQ,aAIxBlB,cACAE,YAAYc,IAAIP,WAAWT,cAC3BE,YAAYgB,QAAQ"}