Merge branch 'MDL-76783-master' of https://github.com/ferranrecio/moodle

This commit is contained in:
Andrew Nicols 2023-02-06 12:57:43 +08:00
commit 98b8ee2e1e
61 changed files with 1651 additions and 55 deletions

14
lib/amd/build/sticky-footer.min.js vendored Normal file
View file

@ -0,0 +1,14 @@
define("core/sticky-footer",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.registerManager=_exports.init=_exports.enableStickyFooter=_exports.disableStickyFooter=void 0;
/**
* Sticky footer wrapper module.
*
* Themes are responsible for implementing the sticky footer. However,
* modules can interact with the sticky footer using this module.
*
* @module core/sticky-footer
* @copyright 2023 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
let manager={},enabled=!1,initialized=!1;const SELECTORS_STICKYFOOTER=".stickyfooter",CLASSES_INVISIBLE="v-hidden",enableStickyFooter=()=>{var _document$querySelect;(enabled=!0,void 0!==manager.enableStickyFooter)?manager.enableStickyFooter():null===(_document$querySelect=document.querySelector(SELECTORS_STICKYFOOTER))||void 0===_document$querySelect||_document$querySelect.classList.remove(CLASSES_INVISIBLE)};_exports.enableStickyFooter=enableStickyFooter;const disableStickyFooter=()=>{var _document$querySelect2;(enabled=!1,void 0!==manager.disableStickyFooter)?manager.disableStickyFooter():null===(_document$querySelect2=document.querySelector(SELECTORS_STICKYFOOTER))||void 0===_document$querySelect2||_document$querySelect2.classList.add(CLASSES_INVISIBLE)};_exports.disableStickyFooter=disableStickyFooter;_exports.registerManager=themeManager=>{manager=themeManager,enabled&&enableStickyFooter()};_exports.init=()=>{var _document$querySelect3;if(initialized)return;initialized=!0;(null===(_document$querySelect3=document.querySelector(SELECTORS_STICKYFOOTER))||void 0===_document$querySelect3?void 0:_document$querySelect3.dataset.disable)?disableStickyFooter():enableStickyFooter()}}));
//# sourceMappingURL=sticky-footer.min.js.map

View file

@ -0,0 +1 @@
{"version":3,"file":"sticky-footer.min.js","sources":["../src/sticky-footer.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 * Sticky footer wrapper module.\n *\n * Themes are responsible for implementing the sticky footer. However,\n * modules can interact with the sticky footer using this module.\n *\n * @module core/sticky-footer\n * @copyright 2023 Ferran Recio <ferran@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\nlet manager = {};\n\nlet enabled = false;\n\nlet initialized = false;\n\nconst SELECTORS = {\n STICKYFOOTER: '.stickyfooter',\n};\n\nconst CLASSES = {\n INVISIBLE: 'v-hidden',\n};\n\n/**\n * Enable sticky footer in the page.\n */\nexport const enableStickyFooter = () => {\n enabled = true;\n if (manager.enableStickyFooter === undefined) {\n document.querySelector(SELECTORS.STICKYFOOTER)?.classList.remove(CLASSES.INVISIBLE);\n return;\n }\n manager.enableStickyFooter();\n};\n\n/**\n * Disable sticky footer in the page.\n */\nexport const disableStickyFooter = () => {\n enabled = false;\n if (manager.disableStickyFooter === undefined) {\n document.querySelector(SELECTORS.STICKYFOOTER)?.classList.add(CLASSES.INVISIBLE);\n return;\n }\n manager.disableStickyFooter();\n};\n\n/**\n * Register the theme sticky footer methods.\n *\n * @param {Object} themeManager the manager object with all the needed methods.\n * @param {Function} themeManager.enableStickyFooter enable sticky footer method\n * @param {Function} themeManager.disableStickyFooter disable sticky footer method\n */\nexport const registerManager = (themeManager) => {\n manager = themeManager;\n if (enabled) {\n enableStickyFooter();\n }\n};\n\n/**\n * Initialize the module if the theme does not implement its own init.\n */\nexport const init = () => {\n if (initialized) {\n return;\n }\n initialized = true;\n\n const isDisabled = document.querySelector(SELECTORS.STICKYFOOTER)?.dataset.disable;\n if (isDisabled) {\n disableStickyFooter();\n } else {\n enableStickyFooter();\n }\n};\n"],"names":["manager","enabled","initialized","SELECTORS","CLASSES","enableStickyFooter","undefined","document","querySelector","classList","remove","disableStickyFooter","add","themeManager","_document$querySelect3","dataset","disable"],"mappings":";;;;;;;;;;;IA2BIA,QAAU,GAEVC,SAAU,EAEVC,aAAc,QAEZC,uBACY,gBAGZC,kBACS,WAMFC,mBAAqB,gCAC9BJ,SAAU,OACyBK,IAA/BN,QAAQK,oBAIZL,QAAQK,mDAHJE,SAASC,cAAcL,gFAAyBM,UAAUC,OAAON,yEAS5DO,oBAAsB,iCAC/BV,SAAU,OAC0BK,IAAhCN,QAAQW,qBAIZX,QAAQW,qDAHJJ,SAASC,cAAcL,kFAAyBM,UAAUG,IAAIR,8FAatCS,eAC5Bb,QAAUa,aACNZ,SACAI,oCAOY,mCACZH,mBAGJA,aAAc,kCAEKK,SAASC,cAAcL,iEAAvBW,uBAAgDC,QAAQC,SAEvEL,sBAEAN"}

View file

@ -0,0 +1,95 @@
// 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/>.
/**
* Sticky footer wrapper module.
*
* Themes are responsible for implementing the sticky footer. However,
* modules can interact with the sticky footer using this module.
*
* @module core/sticky-footer
* @copyright 2023 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
let manager = {};
let enabled = false;
let initialized = false;
const SELECTORS = {
STICKYFOOTER: '.stickyfooter',
};
const CLASSES = {
INVISIBLE: 'v-hidden',
};
/**
* Enable sticky footer in the page.
*/
export const enableStickyFooter = () => {
enabled = true;
if (manager.enableStickyFooter === undefined) {
document.querySelector(SELECTORS.STICKYFOOTER)?.classList.remove(CLASSES.INVISIBLE);
return;
}
manager.enableStickyFooter();
};
/**
* Disable sticky footer in the page.
*/
export const disableStickyFooter = () => {
enabled = false;
if (manager.disableStickyFooter === undefined) {
document.querySelector(SELECTORS.STICKYFOOTER)?.classList.add(CLASSES.INVISIBLE);
return;
}
manager.disableStickyFooter();
};
/**
* Register the theme sticky footer methods.
*
* @param {Object} themeManager the manager object with all the needed methods.
* @param {Function} themeManager.enableStickyFooter enable sticky footer method
* @param {Function} themeManager.disableStickyFooter disable sticky footer method
*/
export const registerManager = (themeManager) => {
manager = themeManager;
if (enabled) {
enableStickyFooter();
}
};
/**
* Initialize the module if the theme does not implement its own init.
*/
export const init = () => {
if (initialized) {
return;
}
initialized = true;
const isDisabled = document.querySelector(SELECTORS.STICKYFOOTER)?.dataset.disable;
if (isDisabled) {
disableStickyFooter();
} else {
enableStickyFooter();
}
};

View file

@ -46,6 +46,11 @@ class sticky_footer implements named_templatable, renderable {
*/
protected $stickyclasses = 'justify-content-end';
/**
* @var bool if the footer should auto enable or not.
*/
protected $autoenable = true;
/**
* @var array extra HTML attributes (attribute => value).
*/
@ -75,6 +80,15 @@ class sticky_footer implements named_templatable, renderable {
$this->stickycontent = $stickycontent;
}
/**
* Set the auto enable value.
*
* @param bool $autoenable the footer content
*/
public function set_auto_enable(bool $autoenable) {
$this->autoenable = $autoenable;
}
/**
* Add extra classes to the sticky footer.
*
@ -111,11 +125,15 @@ class sticky_footer implements named_templatable, renderable {
'value' => $value,
];
}
return [
$data = [
'stickycontent' => (string)$this->stickycontent,
'stickyclasses' => $this->stickyclasses,
'extras' => $extras,
];
if (!$this->autoenable) {
$data['disable'] = true;
}
return $data;
}
/**

View file

@ -22,6 +22,15 @@
Sticky footer behaviour depends on the theme. The default template is
a regular element.
Classes required for JS:
* none
Data attributes optional for JS:
* data-disable Number|String - If the sticky footer should be disabled by default
Context variables required for this template:
* disable Boolean - if the sticky footer should be loaded hidden
Example context (json):
{
"stickycontent" : "<a href=\"#\">Moodle</a>",
@ -37,6 +46,9 @@
<div
id="sticky-footer"
class="{{$ stickyclasses }}{{stickyclasses}}{{/ stickyclasses }}"
{{$ disable }}
{{#disable}} data-disable="true" {{/disable}}
{{/ disable }}
{{#extras}}
{{attribute}}="{{value}}"
{{/extras}}
@ -45,3 +57,9 @@
{{{stickycontent}}}
{{/ stickycontent }}
</div>
{{#js}}
require(['core/sticky-footer'], function(footer) {
footer.init();
});
{{/js}}