From 21074e3e6e972656ce080f77b642022e33c22b96 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Wed, 4 Jun 2025 13:13:22 +0100 Subject: [PATCH] MDL-84804 javascript: new module for manipulating the page title. --- .upgradenotes/MDL-84804-2025060412115860.yml | 7 +++ lib/amd/build/page_title.min.js | 11 ++++ lib/amd/build/page_title.min.js.map | 1 + lib/amd/src/page_title.js | 64 ++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 .upgradenotes/MDL-84804-2025060412115860.yml create mode 100644 lib/amd/build/page_title.min.js create mode 100644 lib/amd/build/page_title.min.js.map create mode 100644 lib/amd/src/page_title.js diff --git a/.upgradenotes/MDL-84804-2025060412115860.yml b/.upgradenotes/MDL-84804-2025060412115860.yml new file mode 100644 index 00000000000..4bc9e66e5ed --- /dev/null +++ b/.upgradenotes/MDL-84804-2025060412115860.yml @@ -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 diff --git a/lib/amd/build/page_title.min.js b/lib/amd/build/page_title.min.js new file mode 100644 index 00000000000..f6c94928cf7 --- /dev/null +++ b/lib/amd/build/page_title.min.js @@ -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 + * @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 \ No newline at end of file diff --git a/lib/amd/build/page_title.min.js.map b/lib/amd/build/page_title.min.js.map new file mode 100644 index 00000000000..f7635d5debf --- /dev/null +++ b/lib/amd/build/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 .\n\n/**\n * Helper module for manipulating the current page title\n *\n * @module core/page_title\n * @copyright 2025 Paul Holden \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"} \ No newline at end of file diff --git a/lib/amd/src/page_title.js b/lib/amd/src/page_title.js new file mode 100644 index 00000000000..d602b580e02 --- /dev/null +++ b/lib/amd/src/page_title.js @@ -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 . + +/** + * Helper module for manipulating the current page title + * + * @module core/page_title + * @copyright 2025 Paul Holden + * @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; +};