diff --git a/mod/data/amd/build/dropdown_flip.min.js b/mod/data/amd/build/dropdown_flip.min.js new file mode 100644 index 0000000000000..9200b33e4aa2a --- /dev/null +++ b/mod/data/amd/build/dropdown_flip.min.js @@ -0,0 +1,10 @@ +define("mod_data/dropdown_flip",["exports","theme_boost/bootstrap/dropdown","jquery"],(function(_exports,_dropdown,_jquery){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} +/** + * Javascript module to enable dropdowns with flip modifier. + * + * @module mod_data/dropdown_flip + * @copyright 2024 Laurent David + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_dropdown=_interopRequireDefault(_dropdown),_jquery=_interopRequireDefault(_jquery);const SELECTORS_DATA_TOGGLE='[data-toggle="dropdown"]';var _default=()=>{document.querySelectorAll(SELECTORS_DATA_TOGGLE).forEach((dd=>{let dropdown=(0,_jquery.default)(dd),data=dropdown.data("bs.dropdown");data=new _dropdown.default(dd,{popperConfig:{modifiers:{flip:{enabled:!0}}}}),dropdown.data("bs.dropdown",data)}))};return _exports.default=_default,_exports.default})); + +//# sourceMappingURL=dropdown_flip.min.js.map \ No newline at end of file diff --git a/mod/data/amd/build/dropdown_flip.min.js.map b/mod/data/amd/build/dropdown_flip.min.js.map new file mode 100644 index 0000000000000..5f2f2b77bd7ec --- /dev/null +++ b/mod/data/amd/build/dropdown_flip.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"dropdown_flip.min.js","sources":["../src/dropdown_flip.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 * Javascript module to enable dropdowns with flip modifier.\n *\n * @module mod_data/dropdown_flip\n * @copyright 2024 Laurent David \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport Dropdown from 'theme_boost/bootstrap/dropdown';\nimport $ from 'jquery';\nconst DATA_KEY = 'bs.dropdown';\nconst SELECTORS = {\n DATA_TOGGLE: '[data-toggle=\"dropdown\"]',\n};\n/**\n * Init dropdowns with flip modifier.\n *\n * We need to use the flip modifier to avoid dropdowns to be cut off by the viewport.\n * Normally the default popperConfig is {modifiers: {flip: {enabled: true}}} but in\n * MDL-75957 and MDL-64887 we set it to false to avoid conflicts with the Boost theme\n * navigation bar going under (https://github.com/twbs/bootstrap/issues/25962).\n * Here we re-enable it for dropdowns in specific pages for the mod_data.\n *\n * Ideally this should be done in the Boost theme but this is not possible now because\n * it would mean resolving global conflicts with the Boost theme navigation bar, which\n * is a big task (MDL-64887) involving a substantial set of possible regression.\n * This is a temporary solution (z-index is wrong also with any navigation bar in our case)\n * and it is likely that we will migrate to a new Popper.js version in the future and look at it again.\n */\nconst init = () => {\n const dropdowns = document.querySelectorAll(SELECTORS.DATA_TOGGLE);\n dropdowns.forEach((dd) => {\n let dropdown = $(dd);\n let data = dropdown.data(DATA_KEY);\n data = new Dropdown(dd, {popperConfig: {modifiers: {flip: {enabled: true}}}});\n dropdown.data(DATA_KEY, data);\n });\n};\n\nexport default init;\n"],"names":["SELECTORS","document","querySelectorAll","forEach","dd","dropdown","data","Dropdown","popperConfig","modifiers","flip","enabled"],"mappings":";;;;;;;+KAyBMA,sBACW,wCAiBJ,KACSC,SAASC,iBAAiBF,uBAClCG,SAASC,SACXC,UAAW,mBAAED,IACbE,KAAOD,SAASC,KAvBX,eAwBTA,KAAO,IAAIC,kBAASH,GAAI,CAACI,aAAc,CAACC,UAAW,CAACC,KAAM,CAACC,SAAS,OACpEN,SAASC,KAzBA,cAyBeA"} \ No newline at end of file diff --git a/mod/data/amd/src/dropdown_flip.js b/mod/data/amd/src/dropdown_flip.js new file mode 100644 index 0000000000000..edea4a90129b3 --- /dev/null +++ b/mod/data/amd/src/dropdown_flip.js @@ -0,0 +1,54 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see . + +/** + * Javascript module to enable dropdowns with flip modifier. + * + * @module mod_data/dropdown_flip + * @copyright 2024 Laurent David + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +import Dropdown from 'theme_boost/bootstrap/dropdown'; +import $ from 'jquery'; +const DATA_KEY = 'bs.dropdown'; +const SELECTORS = { + DATA_TOGGLE: '[data-toggle="dropdown"]', +}; +/** + * Init dropdowns with flip modifier. + * + * We need to use the flip modifier to avoid dropdowns to be cut off by the viewport. + * Normally the default popperConfig is {modifiers: {flip: {enabled: true}}} but in + * MDL-75957 and MDL-64887 we set it to false to avoid conflicts with the Boost theme + * navigation bar going under (https://github.com/twbs/bootstrap/issues/25962). + * Here we re-enable it for dropdowns in specific pages for the mod_data. + * + * Ideally this should be done in the Boost theme but this is not possible now because + * it would mean resolving global conflicts with the Boost theme navigation bar, which + * is a big task (MDL-64887) involving a substantial set of possible regression. + * This is a temporary solution (z-index is wrong also with any navigation bar in our case) + * and it is likely that we will migrate to a new Popper.js version in the future and look at it again. + */ +const init = () => { + const dropdowns = document.querySelectorAll(SELECTORS.DATA_TOGGLE); + dropdowns.forEach((dd) => { + let dropdown = $(dd); + let data = dropdown.data(DATA_KEY); + data = new Dropdown(dd, {popperConfig: {modifiers: {flip: {enabled: true}}}}); + dropdown.data(DATA_KEY, data); + }); +}; + +export default init; diff --git a/mod/data/templates/presets.mustache b/mod/data/templates/presets.mustache index ebf1fbdeeaa85..4ea1ca37d1791 100644 --- a/mod/data/templates/presets.mustache +++ b/mod/data/templates/presets.mustache @@ -54,7 +54,7 @@ }} {{#str}}presetshelp, mod_data{{/str}} -
+ @@ -122,4 +122,8 @@ require(['mod_data/importmappingdialogue'], function(importPreset) { importPreset.init(); }); + + require(['mod_data/dropdown_flip'], function(flip) { + flip(); + }); {{/js}}