MDL-84804 javascript: new module for manipulating the page title.

This commit is contained in:
Paul Holden
2025-06-04 14:06:20 +01:00
parent c39b737063
commit 21074e3e6e
4 changed files with 83 additions and 0 deletions
@@ -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
+11
View File
@@ -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
+1
View File
@@ -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"}
+64
View File
@@ -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;
};