Merge branch 'MDL-84804-405' of https://github.com/paulholden/moodle into MOODLE_405_STABLE
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
issueNumber: MDL-84804
|
||||
notes:
|
||||
core:
|
||||
- message: >-
|
||||
There is a new `core/page_title` Javascript module for manipulating the
|
||||
current page title
|
||||
type: improved
|
||||
Vendored
+2
-2
@@ -1,10 +1,10 @@
|
||||
define("core/dynamic_tabs",["exports","jquery","core/templates","core/loadingicon","core/notification","core/pending","core/str","core/local/repository/dynamic_tabs","core_form/changechecker"],(function(_exports,_jquery,_templates,_loadingicon,_notification,_pending,_str,_dynamic_tabs,_changechecker){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
|
||||
define("core/dynamic_tabs",["exports","jquery","core/templates","core/loadingicon","core/notification","core/page_title","core/pending","core/str","core/local/repository/dynamic_tabs","core_form/changechecker"],(function(_exports,_jquery,_templates,_loadingicon,_notification,_page_title,_pending,_str,_dynamic_tabs,_changechecker){function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
|
||||
/**
|
||||
* Dynamic Tabs UI element with AJAX loading of tabs content
|
||||
*
|
||||
* @module core/dynamic_tabs
|
||||
* @copyright 2021 David Matamoros <davidmc@moodle.com> based on code from Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_templates=_interopRequireDefault(_templates),_notification=_interopRequireDefault(_notification),_pending=_interopRequireDefault(_pending);const SELECTORS={dynamicTabs:".dynamictabs",activeTab:".dynamictabs .nav-link.active",allActiveTabs:'.dynamictabs .nav-link[data-toggle="tab"]:not(.disabled)',tabContent:".dynamictabs .tab-pane [data-tab-content]",tabToggle:'a[data-toggle="tab"]',tabPane:".dynamictabs .tab-pane",forTabName:tabName=>'.dynamictabs [data-tab-content="'.concat(tabName,'"]'),forTabId:tabName=>'.dynamictabs [data-toggle="tab"][href="#'.concat(tabName,'"]')};_exports.init=()=>{const tabToggle=(0,_jquery.default)(SELECTORS.tabToggle);if(tabToggle.on("click",(event=>{(0,_changechecker.isAnyWatchedFormDirty)()&&(event.preventDefault(),event.stopPropagation(),(0,_str.getStrings)([{key:"changesmade",component:"moodle"},{key:"changesmadereallygoaway",component:"moodle"},{key:"confirm",component:"moodle"}]).then((_ref=>{let[strChangesMade,strChangesMadeReally,strConfirm]=_ref;return _notification.default.confirm(strChangesMade,strChangesMadeReally,strConfirm,null,(()=>{(0,_changechecker.resetAllFormDirtyStates)(),(0,_jquery.default)(event.target).trigger(event.type)}))})).catch(_notification.default.exception))})),tabToggle.on("show.bs.tab",(function(){const previousTabName=getActiveTabName();if(previousTabName){document.querySelector(SELECTORS.forTabName(previousTabName)).textContent=""}})).on("shown.bs.tab",(function(){const tab=(0,_jquery.default)((0,_jquery.default)(this).attr("href"));1===tab.length&&loadTab(tab.attr("id"))})),!openTabFromHash()){const tabs=document.querySelector(SELECTORS.allActiveTabs);if(tabs)openTab(tabs.getAttribute("aria-controls"));else{const tabPane=document.querySelector(SELECTORS.tabPane);tabPane&&(tabPane.classList.add("active","show"),loadTab(tabPane.getAttribute("id")))}}};const getActiveTabName=()=>{const element=document.querySelector(SELECTORS.activeTab);return(null==element?void 0:element.getAttribute("aria-controls"))||null},loadTab=tabName=>{var _ref2,_tabName;tabName=null!==(_ref2=null!==(_tabName=tabName)&&void 0!==_tabName?_tabName:getActiveTabName())&&void 0!==_ref2?_ref2:(()=>{const element=document.querySelector(SELECTORS.tabContent);return(null==element?void 0:element.dataset.tabContent)||null})();const tab=document.querySelector(SELECTORS.forTabName(tabName));if(!tab)return;const pendingPromise=new _pending.default("core/dynamic_tabs:loadTab:"+tabName);(0,_loadingicon.addIconToContainer)(tab).then((()=>{let tabArgs={...tab.dataset};return delete tabArgs.tabClass,delete tabArgs.tabContent,(0,_dynamic_tabs.getContent)(tab.dataset.tabClass,JSON.stringify(tabArgs))})).then((response=>Promise.all([_jquery.default.parseHTML(response.javascript,null,!0).map((node=>node.innerHTML)).join("\n"),_templates.default.renderForPromise(response.template,JSON.parse(response.content))]))).then((_ref3=>{let[responseJs,{html:html,js:js}]=_ref3;return _templates.default.replaceNodeContents(tab,html,js+responseJs)})).then((()=>pendingPromise.resolve())).catch(_notification.default.exception)},openTab=tabName=>{const tab=(tabName=>document.querySelector(SELECTORS.forTabId(tabName)))(tabName);return!!tab&&(loadTab(tabName),tab.classList.add("active"),(tabName=>document.getElementById(tabName))(tabName).classList.add("active","show"),!0)},openTabFromHash=()=>{const hash=document.location.hash;return!!hash.match(/^#\w+$/g)&&openTab(hash.replace(/^#/g,""))}}));
|
||||
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),_templates=_interopRequireDefault(_templates),_notification=_interopRequireDefault(_notification),_pending=_interopRequireDefault(_pending);const SELECTORS={dynamicTabs:".dynamictabs",activeTab:".dynamictabs .nav-link.active",allActiveTabs:'.dynamictabs .nav-link[data-toggle="tab"]:not(.disabled)',tabContent:".dynamictabs .tab-pane [data-tab-content]",tabToggle:'a[data-toggle="tab"]',tabPane:".dynamictabs .tab-pane",forTabName:tabName=>'.dynamictabs [data-tab-content="'.concat(tabName,'"]'),forTabId:tabName=>'.dynamictabs [data-toggle="tab"][href="#'.concat(tabName,'"]')};_exports.init=()=>{const tabToggle=(0,_jquery.default)(SELECTORS.tabToggle);if(tabToggle.on("click",(event=>{(0,_changechecker.isAnyWatchedFormDirty)()&&(event.preventDefault(),event.stopPropagation(),(0,_str.getStrings)([{key:"changesmade",component:"moodle"},{key:"changesmadereallygoaway",component:"moodle"},{key:"confirm",component:"moodle"}]).then((_ref=>{let[strChangesMade,strChangesMadeReally,strConfirm]=_ref;return _notification.default.confirm(strChangesMade,strChangesMadeReally,strConfirm,null,(()=>{(0,_changechecker.resetAllFormDirtyStates)(),(0,_jquery.default)(event.target).trigger(event.type)}))})).catch(_notification.default.exception))})),tabToggle.on("show.bs.tab",(function(){const previousTabName=getActiveTabName();if(previousTabName){document.querySelector(SELECTORS.forTabName(previousTabName)).textContent=""}})).on("shown.bs.tab",(function(){const tab=(0,_jquery.default)((0,_jquery.default)(this).attr("href"));1===tab.length&&loadTab(tab.attr("id"))})),!openTabFromHash()){const tabs=document.querySelector(SELECTORS.allActiveTabs);if(tabs)openTab(tabs.getAttribute("aria-controls"));else{const tabPane=document.querySelector(SELECTORS.tabPane);tabPane&&(tabPane.classList.add("active","show"),loadTab(tabPane.getAttribute("id")))}}};const getActiveTabName=()=>{const element=document.querySelector(SELECTORS.activeTab);return(null==element?void 0:element.getAttribute("aria-controls"))||null},loadTab=tabName=>{var _ref2,_tabName;tabName=null!==(_ref2=null!==(_tabName=tabName)&&void 0!==_tabName?_tabName:getActiveTabName())&&void 0!==_ref2?_ref2:(()=>{const element=document.querySelector(SELECTORS.tabContent);return(null==element?void 0:element.dataset.tabContent)||null})();const tab=document.querySelector(SELECTORS.forTabName(tabName));if(!tab)return;const pendingPromise=new _pending.default("core/dynamic_tabs:loadTab:"+tabName),tabLabelledBy=document.getElementById(tab.getAttribute("aria-labelledby"));(0,_page_title.prependPageTitle)(tabLabelledBy.innerText),(0,_loadingicon.addIconToContainer)(tab).then((()=>{let tabArgs={...tab.dataset};return delete tabArgs.tabClass,delete tabArgs.tabContent,(0,_dynamic_tabs.getContent)(tab.dataset.tabClass,JSON.stringify(tabArgs))})).then((response=>Promise.all([_jquery.default.parseHTML(response.javascript,null,!0).map((node=>node.innerHTML)).join("\n"),_templates.default.renderForPromise(response.template,JSON.parse(response.content))]))).then((_ref3=>{let[responseJs,{html:html,js:js}]=_ref3;return _templates.default.replaceNodeContents(tab,html,js+responseJs)})).then((()=>pendingPromise.resolve())).catch(_notification.default.exception)},openTab=tabName=>{const tab=(tabName=>document.querySelector(SELECTORS.forTabId(tabName)))(tabName);return!!tab&&(loadTab(tabName),tab.classList.add("active"),(tabName=>document.getElementById(tabName))(tabName).classList.add("active","show"),!0)},openTabFromHash=()=>{const hash=document.location.hash;return!!hash.match(/^#\w+$/g)&&openTab(hash.replace(/^#/g,""))}}));
|
||||
|
||||
//# sourceMappingURL=dynamic_tabs.min.js.map
|
||||
File diff suppressed because one or more lines are too long
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
define("core/page_title",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.setPageTitleSeparator=_exports.setPageTitleRoot=_exports.setPageTitle=_exports.prependPageTitle=void 0;
|
||||
/**
|
||||
* Helper module for manipulating the current page title
|
||||
*
|
||||
* @module core/page_title
|
||||
* @copyright 2025 Paul Holden <paulh@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
let pageTitleRoot=document.title,pageTitleSeparator="|";const setPageTitle=pageTitle=>{document.title=pageTitle};_exports.setPageTitle=setPageTitle;_exports.prependPageTitle=pageTitlePrepend=>setPageTitle("".concat(pageTitlePrepend," ").concat(pageTitleSeparator," ").concat(pageTitleRoot));_exports.setPageTitleRoot=titleRoot=>{pageTitleRoot=titleRoot};_exports.setPageTitleSeparator=titleSeparator=>{pageTitleSeparator=titleSeparator}}));
|
||||
|
||||
//# sourceMappingURL=page_title.min.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"page_title.min.js","sources":["../src/page_title.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 * Helper module for manipulating the current page title\n *\n * @module core/page_title\n * @copyright 2025 Paul Holden <[email protected]>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nlet pageTitleRoot = document.title;\nlet pageTitleSeparator = '|';\n\n/**\n * Set the current page title\n *\n * @param {String} pageTitle\n */\nexport const setPageTitle = (pageTitle) => {\n document.title = pageTitle;\n};\n\n/**\n * Prepend value to the page title root, and set as the current page title\n *\n * @param {String} pageTitlePrepend\n */\nexport const prependPageTitle = (pageTitlePrepend) =>\n setPageTitle(`${pageTitlePrepend} ${pageTitleSeparator} ${pageTitleRoot}`);\n\n/**\n * Set the page title root, to be used later when prepending to the title\n *\n * By default, the page title root is the document title\n *\n * @param {String} titleRoot\n */\nexport const setPageTitleRoot = (titleRoot) => {\n pageTitleRoot = titleRoot;\n};\n\n/**\n * Set the page title separator\n *\n * By default, the page title separator is the pipe character\n *\n * @param {String} titleSeparator\n */\nexport const setPageTitleSeparator = (titleSeparator) => {\n pageTitleSeparator = titleSeparator;\n};\n"],"names":["pageTitleRoot","document","title","pageTitleSeparator","setPageTitle","pageTitle","pageTitlePrepend","titleRoot","titleSeparator"],"mappings":";;;;;;;;IAuBIA,cAAgBC,SAASC,MACzBC,mBAAqB,UAOZC,aAAgBC,YACzBJ,SAASC,MAAQG,wEAQYC,kBAC7BF,uBAAgBE,6BAAoBH,+BAAsBH,0CAS7BO,YAC7BP,cAAgBO,0CAUkBC,iBAClCL,mBAAqBK"}
|
||||
@@ -25,6 +25,7 @@ import $ from 'jquery';
|
||||
import Templates from 'core/templates';
|
||||
import {addIconToContainer} from 'core/loadingicon';
|
||||
import Notification from 'core/notification';
|
||||
import {prependPageTitle} from 'core/page_title';
|
||||
import Pending from 'core/pending';
|
||||
import {getStrings} from 'core/str';
|
||||
import {getContent} from 'core/local/repository/dynamic_tabs';
|
||||
@@ -139,6 +140,9 @@ const loadTab = (tabName) => {
|
||||
|
||||
const pendingPromise = new Pending('core/dynamic_tabs:loadTab:' + tabName);
|
||||
|
||||
const tabLabelledBy = document.getElementById(tab.getAttribute('aria-labelledby'));
|
||||
prependPageTitle(tabLabelledBy.innerText);
|
||||
|
||||
addIconToContainer(tab)
|
||||
.then(() => {
|
||||
let tabArgs = {...tab.dataset};
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
// 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/>.
|
||||
|
||||
/**
|
||||
* Helper module for manipulating the current page title
|
||||
*
|
||||
* @module core/page_title
|
||||
* @copyright 2025 Paul Holden <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
let pageTitleRoot = document.title;
|
||||
let pageTitleSeparator = '|';
|
||||
|
||||
/**
|
||||
* Set the current page title
|
||||
*
|
||||
* @param {String} pageTitle
|
||||
*/
|
||||
export const setPageTitle = (pageTitle) => {
|
||||
document.title = pageTitle;
|
||||
};
|
||||
|
||||
/**
|
||||
* Prepend value to the page title root, and set as the current page title
|
||||
*
|
||||
* @param {String} pageTitlePrepend
|
||||
*/
|
||||
export const prependPageTitle = (pageTitlePrepend) =>
|
||||
setPageTitle(`${pageTitlePrepend} ${pageTitleSeparator} ${pageTitleRoot}`);
|
||||
|
||||
/**
|
||||
* Set the page title root, to be used later when prepending to the title
|
||||
*
|
||||
* By default, the page title root is the document title
|
||||
*
|
||||
* @param {String} titleRoot
|
||||
*/
|
||||
export const setPageTitleRoot = (titleRoot) => {
|
||||
pageTitleRoot = titleRoot;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the page title separator
|
||||
*
|
||||
* By default, the page title separator is the pipe character
|
||||
*
|
||||
* @param {String} titleSeparator
|
||||
*/
|
||||
export const setPageTitleSeparator = (titleSeparator) => {
|
||||
pageTitleSeparator = titleSeparator;
|
||||
};
|
||||
Reference in New Issue
Block a user