Merge branch 'MDL-78549-401' of https://github.com/junpataleta/moodle into MOODLE_401_STABLE

This commit is contained in:
Huong Nguyen 2023-09-08 10:58:37 +07:00 committed by Jun Pataleta
commit f8d8553da6
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
4 changed files with 63 additions and 2 deletions

View File

@ -0,0 +1,10 @@
define("qtype_multianswer/feedback",["exports","theme_boost/popover","jquery"],(function(_exports,_popover,_jquery){var obj;
/**
* Backward compatibility file for the old popover.js
*
* @module qtype_multianswer/feedback
* @copyright 2023 Jun Pataleta <jun@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_jquery=(obj=_jquery)&&obj.__esModule?obj:{default:obj};const SELECTORS_FEEDBACK_TRIGGER='.feedbacktrigger[data-toggle="popover"]';let feedbackInitialised=!1;var _default={initPopovers:()=>{feedbackInitialised||((0,_jquery.default)(SELECTORS_FEEDBACK_TRIGGER).popover(),feedbackInitialised=!0)}};return _exports.default=_default,_exports.default}));
//# sourceMappingURL=feedback.min.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"feedback.min.js","sources":["../src/feedback.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 <http://www.gnu.org/licenses/>.\n\n/**\n * Backward compatibility file for the old popover.js\n *\n * @module qtype_multianswer/feedback\n * @copyright 2023 Jun Pataleta <jun@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport 'theme_boost/popover';\nimport $ from 'jquery';\n\n/** @type {object} Contains the list of selectors for this module. */\nconst SELECTORS = {\n FEEDBACK_TRIGGER: '.feedbacktrigger[data-toggle=\"popover\"]',\n};\n\n/** @type {boolean} Flag to indicate whether the feedback popovers have been already initialised. */\nlet feedbackInitialised = false;\n\n/**\n * Function to initialise the feedback popovers.\n */\nconst initPopovers = () => {\n if (!feedbackInitialised) {\n $(SELECTORS.FEEDBACK_TRIGGER).popover();\n feedbackInitialised = true;\n }\n};\n\nexport default {\n initPopovers: initPopovers,\n};\n"],"names":["SELECTORS","feedbackInitialised","initPopovers","popover"],"mappings":";;;;;;;mJA2BMA,2BACgB,8CAIlBC,qBAAsB,eAYX,CACXC,aARiB,KACZD,0CACCD,4BAA4BG,UAC9BF,qBAAsB"}

View File

@ -0,0 +1,47 @@
// 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 <http://www.gnu.org/licenses/>.
/**
* Backward compatibility file for the old popover.js
*
* @module qtype_multianswer/feedback
* @copyright 2023 Jun Pataleta <jun@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import 'theme_boost/popover';
import $ from 'jquery';
/** @type {object} Contains the list of selectors for this module. */
const SELECTORS = {
FEEDBACK_TRIGGER: '.feedbacktrigger[data-toggle="popover"]',
};
/** @type {boolean} Flag to indicate whether the feedback popovers have been already initialised. */
let feedbackInitialised = false;
/**
* Function to initialise the feedback popovers.
*/
const initPopovers = () => {
if (!feedbackInitialised) {
$(SELECTORS.FEEDBACK_TRIGGER).popover();
feedbackInitialised = true;
}
};
export default {
initPopovers: initPopovers,
};

View File

@ -208,19 +208,22 @@ abstract class qtype_multianswer_subq_renderer_base extends qtype_renderer {
* @return string
*/
protected function get_feedback_image(string $icon, string $feedbackcontents): string {
global $PAGE;
if ($icon === '') {
return '';
}
$PAGE->requires->js_call_amd('qtype_multianswer/feedback', 'initPopovers');
return html_writer::link('#', $icon, [
'role' => 'button',
'tabindex' => 0,
'class' => 'btn btn-link p-0',
'class' => 'feedbacktrigger btn btn-link p-0',
'data-toggle' => 'popover',
'data-container' => 'body',
'data-content' => $feedbackcontents,
'data-placement' => 'right',
'data-trigger' => 'focus',
'data-trigger' => 'hover focus',
'data-html' => 'true',
]);
}