From de8e8806da81961ab11e5c898ed1203a6017d0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Fri, 24 Jan 2025 12:57:14 +0100 Subject: [PATCH 1/2] MDL-84324 core: Add jQuery compatibility for BS5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit You don’t need jQuery in Bootstrap 5, but it’s still possible to use our components with jQuery. If Bootstrap detects jQuery in the window object, it’ll add all of our components in jQuery’s plugin system. This allows you to do the following: $('#myTooltip').tooltip('show') --- lib/amd/build/first.min.js | 2 +- lib/amd/build/first.min.js.map | 2 +- lib/amd/src/first.js | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/amd/build/first.min.js b/lib/amd/build/first.min.js index 159471424a8..5fffdf1868c 100644 --- a/lib/amd/build/first.min.js +++ b/lib/amd/build/first.min.js @@ -11,6 +11,6 @@ define("core/first",["jquery"],(function(_jquery){var obj; * @copyright 2015 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since 2.9 - */(0,(_jquery=(obj=_jquery)&&obj.__esModule?obj:{default:obj}).default)(document).bind("ajaxStart",(function(){M.util.js_pending("jq")})).bind("ajaxStop",(function(){M.util.js_complete("jq")}))})); + */(0,(_jquery=(obj=_jquery)&&obj.__esModule?obj:{default:obj}).default)(document).bind("ajaxStart",(function(){M.util.js_pending("jq")})).bind("ajaxStop",(function(){M.util.js_complete("jq")})),window.jQuery=_jquery.default})); //# sourceMappingURL=first.min.js.map \ No newline at end of file diff --git a/lib/amd/build/first.min.js.map b/lib/amd/build/first.min.js.map index 3c44137db98..f265fea6604 100644 --- a/lib/amd/build/first.min.js.map +++ b/lib/amd/build/first.min.js.map @@ -1 +1 @@ -{"version":3,"file":"first.min.js","sources":["../src/first.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 * This is an empty module, that is required before all other modules.\n * Because every module is returned from a request for any other module, this\n * forces the loading of all modules with a single request.\n *\n * This function also sets up the listeners for ajax requests so we can tell\n * if any requests are still in progress.\n *\n * @module core/first\n * @copyright 2015 Damyon Wiese \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 2.9\n */\n\nimport $ from 'jquery';\n\n$(document)\n.bind(\"ajaxStart\", function() {\n M.util.js_pending('jq');\n})\n.bind(\"ajaxStop\", function() {\n M.util.js_complete('jq');\n});\n"],"names":["document","bind","M","util","js_pending","js_complete"],"mappings":";;;;;;;;;;;;;2EA+BEA,UACDC,KAAK,aAAa,WACfC,EAAEC,KAAKC,WAAW,SAErBH,KAAK,YAAY,WACdC,EAAEC,KAAKE,YAAY"} \ No newline at end of file +{"version":3,"file":"first.min.js","sources":["../src/first.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 * This is an empty module, that is required before all other modules.\n * Because every module is returned from a request for any other module, this\n * forces the loading of all modules with a single request.\n *\n * This function also sets up the listeners for ajax requests so we can tell\n * if any requests are still in progress.\n *\n * @module core/first\n * @copyright 2015 Damyon Wiese \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 2.9\n */\n\nimport $ from 'jquery';\n\n$(document)\n.bind(\"ajaxStart\", function() {\n M.util.js_pending('jq');\n})\n.bind(\"ajaxStop\", function() {\n M.util.js_complete('jq');\n});\n\n// TODO: MDL-84465 Final deprecation in 6.0.\n// Attach jQuery to the window object for Bootstrap backwards compatibility.\n// Bootstrap 5 is designed to be used without jQuery, but it’s still possible to use our components with jQuery.\n// If Bootstrap detects jQuery in the window object it’ll add all of our components in jQuery’s plugin system.\nwindow.jQuery = $;\n"],"names":["document","bind","M","util","js_pending","js_complete","window","jQuery","$"],"mappings":";;;;;;;;;;;;;2EA+BEA,UACDC,KAAK,aAAa,WACfC,EAAEC,KAAKC,WAAW,SAErBH,KAAK,YAAY,WACdC,EAAEC,KAAKE,YAAY,SAOvBC,OAAOC,OAASC"} \ No newline at end of file diff --git a/lib/amd/src/first.js b/lib/amd/src/first.js index 1b35e752ed1..e83243bdc2a 100644 --- a/lib/amd/src/first.js +++ b/lib/amd/src/first.js @@ -36,3 +36,9 @@ $(document) .bind("ajaxStop", function() { M.util.js_complete('jq'); }); + +// TODO: MDL-84465 Final deprecation in 6.0. +// Attach jQuery to the window object for Bootstrap backwards compatibility. +// Bootstrap 5 is designed to be used without jQuery, but it’s still possible to use our components with jQuery. +// If Bootstrap detects jQuery in the window object it’ll add all of our components in jQuery’s plugin system. +window.jQuery = $; From ac146ac14e6b46837f1863092ff0f835196e992d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikel=20Mart=C3=ADn?= Date: Mon, 3 Feb 2025 15:30:46 +0100 Subject: [PATCH 2/2] MDL-84324 core: Fix Bootstrap dropdown key listeners Bootstrap EventHandler is managing the keydown event at document level in the capture phase. That is conflicting with dropdown elements with form autocomplete inputs inside, because when suggestions panel is open, pressing the "Esc" key will close the whole dropdown. This commit fixes that behaviour by realocating the Bootsrap dropdown event listener to the body instead of the document. --- lib/amd/build/form-autocomplete.min.js | 2 +- lib/amd/build/form-autocomplete.min.js.map | 2 +- lib/amd/src/form-autocomplete.js | 14 +++++++++++++- theme/boost/amd/build/aria.min.js | 2 +- theme/boost/amd/build/aria.min.js.map | 2 +- theme/boost/amd/build/loader.min.js | 4 ++-- theme/boost/amd/build/loader.min.js.map | 2 +- theme/boost/amd/src/aria.js | 17 ----------------- theme/boost/amd/src/loader.js | 19 +++++++++++++++++++ 9 files changed, 39 insertions(+), 25 deletions(-) diff --git a/lib/amd/build/form-autocomplete.min.js b/lib/amd/build/form-autocomplete.min.js index 7d3d7b497cd..df5994acbe3 100644 --- a/lib/amd/build/form-autocomplete.min.js +++ b/lib/amd/build/form-autocomplete.min.js @@ -6,6 +6,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @since 3.0 */ -define("core/form-autocomplete",["jquery","core/log","core/str","core/templates","core/notification","core/loadingicon","core/aria","core_form/changechecker","core/popper2"],(function($,log,str,templates,notification,LoadingIcon,Aria,FormChangeChecker,Popper){var KEYS_DOWN=40,KEYS_ENTER=13,KEYS_SPACE=32,KEYS_ESCAPE=27,KEYS_COMMA=44,KEYS_UP=38,KEYS_LEFT=37,KEYS_RIGHT=39,uniqueId=Date.now(),activateSelection=function(index,state){var selectionElement=$(document.getElementById(state.selectionId));index=wrapListIndex(index,selectionElement.children("[aria-selected=true]").length);var element=$(selectionElement.children("[aria-selected=true]").get(index)),itemId=state.selectionId+"-"+index;return selectionElement.children().attr("data-active-selection",null).attr("id",""),element.attr("data-active-selection",!0).attr("id",itemId),selectionElement.attr("aria-activedescendant",itemId),selectionElement.attr("data-active-value",element.attr("data-value")),$.Deferred().resolve()},updateActiveSelectionFromState=function(state){var activeElement=function(state){var _selectionRegion$attr,selectionRegion=$(document.getElementById(state.selectionId)),activeId=selectionRegion.attr("aria-activedescendant");if(activeId){var activeElement=$(document.getElementById(activeId));if(activeElement.length)return activeElement}var activeValue=null===(_selectionRegion$attr=selectionRegion.attr("data-active-value"))||void 0===_selectionRegion$attr?void 0:_selectionRegion$attr.replace(/"/g,'\\"');return selectionRegion.find('[data-value="'+activeValue+'"]')}(state),activeValue=activeElement.attr("data-value"),selectionRegion=$(document.getElementById(state.selectionId));if(activeValue){var activeIndex=selectionRegion.find("[aria-selected=true]").index(activeElement);if(-1!==activeIndex)return void activateSelection(activeIndex,state)}activateSelection(0,state)},updateSelectionList=function(options,state,originalSelect){var pendingKey="form-autocomplete-updateSelectionList-"+state.inputId;M.util.js_pending(pendingKey);var items=rebuildOptions(originalSelect.children("option:selected"),!1),newSelection=$(document.getElementById(state.selectionId));if(!hasItemListChanged(state,items))return M.util.js_complete(pendingKey),Promise.resolve();state.items=items;var context=$.extend(options,state);return templates.render(options.templates.items,context).then((function(html,js){templates.replaceNodeContents(newSelection,html,js),updateActiveSelectionFromState(state)})).then((function(){return M.util.js_complete(pendingKey)})).catch(notification.exception)},hasItemListChanged=function(state,items){return state.items.length!==items.length||state.items.filter((item=>-1===items.indexOf(item))).length>0},notifyChange=function(originalSelect){FormChangeChecker.markFormChangedFromNode(originalSelect[0]),originalSelect[0].dispatchEvent(new Event("change",{bubbles:!0}))},deselectItem=function(options,state,item,originalSelect){var selectedItemValue=$(item).attr("data-value");return void 0!==originalSelect.find("option").first().attr("value")&&originalSelect.prepend($("