From b13877834a798ae37b13c2dea4214e2ead93db88 Mon Sep 17 00:00:00 2001 From: Wehr Mario Date: Mon, 17 Jul 2023 11:23:33 +0200 Subject: [PATCH] Adds remembering of active admin tab on page reload. --- amd/build/admintabs.min.js | 10 +++++ amd/build/admintabs.min.js.map | 1 + amd/src/admintabs.js | 67 ++++++++++++++++++++++++++++++++++ settings.php | 4 ++ 4 files changed, 82 insertions(+) create mode 100644 amd/build/admintabs.min.js create mode 100644 amd/build/admintabs.min.js.map create mode 100644 amd/src/admintabs.js diff --git a/amd/build/admintabs.min.js b/amd/build/admintabs.min.js new file mode 100644 index 00000000000..2ba7e907b2d --- /dev/null +++ b/amd/build/admintabs.min.js @@ -0,0 +1,10 @@ +/** + * Theme Boost Union - JS code current admin tab selector + * + * @module theme_boost_union/admintab + * @copyright 2023 Mario Wehr + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +define("theme_boost_union/admintabs",["jquery"],(function($){function initAdminTabs(){whenBootstrapAvailable((()=>{$('a[href^="#theme_boost_union_"]').parent().on("shown.bs.tab",(function(){sessionStorage.setItem("boost_union_active_admin_tab",$(this).children("a").eq(0).attr("href"))}));const activeTab=sessionStorage.getItem("boost_union_active_admin_tab");activeTab&&$('a[href="'+activeTab+'"]').tab("show")}))}function whenBootstrapAvailable(callback){window.setTimeout((()=>{"function"==typeof $().tab?callback():whenBootstrapAvailable(callback)}),100)}return{init:function(){initAdminTabs()}}})); + +//# sourceMappingURL=admintabs.min.js.map \ No newline at end of file diff --git a/amd/build/admintabs.min.js.map b/amd/build/admintabs.min.js.map new file mode 100644 index 00000000000..5d3ef9eedf6 --- /dev/null +++ b/amd/build/admintabs.min.js.map @@ -0,0 +1 @@ +{"version":3,"file":"admintabs.min.js","sources":["../src/admintabs.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 * Theme Boost Union - JS code current admin tab selector\n *\n * @module theme_boost_union/admintab\n * @copyright 2023 Mario Wehr \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery'], function($) {\n \"use strict\";\n\n /**\n * Initialising.\n */\n function initAdminTabs() {\n // Wait for bootstrap\n whenBootstrapAvailable(() => {\n const sessionKey = \"boost_union_active_admin_tab\";\n // Register for all boost union tabs\n $('a[href^=\"#theme_boost_union_\"]').parent().on(\"shown.bs.tab\", function () {\n // Store active tab in session\n sessionStorage.setItem(sessionKey, $(this).children(\"a\").eq(0).attr(\"href\"));\n });\n // Get active tab from session\n const activeTab = sessionStorage.getItem(sessionKey);\n if (activeTab) {\n // Show active tab from session\n $('a[href=\"' + activeTab + '\"]').tab(\"show\");\n }\n });\n }\n\n /**\n * Wait for Bootstrap is finally loaded\n * @param {function} callback\n */\n function whenBootstrapAvailable(callback) {\n window.setTimeout(() => {\n if (typeof $().tab == \"function\") {\n callback();\n } else {\n whenBootstrapAvailable(callback);\n }\n }, 100);\n }\n\n return {\n init: function() {\n initAdminTabs();\n }\n };\n});"],"names":["define","$","initAdminTabs","whenBootstrapAvailable","parent","on","sessionStorage","setItem","this","children","eq","attr","activeTab","getItem","tab","callback","window","setTimeout","init"],"mappings":";;;;;;;AAuBAA,qCAAO,CAAC,WAAW,SAASC,YAMfC,gBAELC,wBAAuB,KAGnBF,EAAE,kCAAkCG,SAASC,GAAG,gBAAgB,WAE5DC,eAAeC,QAJA,+BAIoBN,EAAEO,MAAMC,SAAS,KAAKC,GAAG,GAAGC,KAAK,kBAGlEC,UAAYN,eAAeO,QAPd,gCAQfD,WAEAX,EAAE,WAAaW,UAAY,MAAME,IAAI,oBASxCX,uBAAuBY,UAC5BC,OAAOC,YAAW,KACQ,mBAAXhB,IAAIa,IACXC,WAEAZ,uBAAuBY,YAE5B,WAGA,CACHG,KAAM,WACFhB"} \ No newline at end of file diff --git a/amd/src/admintabs.js b/amd/src/admintabs.js new file mode 100644 index 00000000000..3342b17179c --- /dev/null +++ b/amd/src/admintabs.js @@ -0,0 +1,67 @@ +// 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 . + +/** + * Theme Boost Union - JS code current admin tab selector + * + * @module theme_boost_union/admintab + * @copyright 2023 Mario Wehr + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define(['jquery'], function($) { + "use strict"; + + /** + * Initialising. + */ + function initAdminTabs() { + // Wait for bootstrap + whenBootstrapAvailable(() => { + const sessionKey = "boost_union_active_admin_tab"; + // Register for all boost union tabs + $('a[href^="#theme_boost_union_"]').parent().on("shown.bs.tab", function() { + // Store active tab in session + sessionStorage.setItem(sessionKey, $(this).children("a").eq(0).attr("href")); + }); + // Get active tab from session + const activeTab = sessionStorage.getItem(sessionKey); + if (activeTab) { + // Show active tab from session + $('a[href="' + activeTab + '"]').tab("show"); + } + }); + } + + /** + * Wait for Bootstrap is finally loaded + * @param {function} callback + */ + function whenBootstrapAvailable(callback) { + window.setTimeout(() => { + if (typeof $().tab == "function") { + callback(); + } else { + whenBootstrapAvailable(callback); + } + }, 100); + } + + return { + init: function() { + initAdminTabs(); + } + }; +}); \ No newline at end of file diff --git a/settings.php b/settings.php index e902fbab462..92d019e1ac0 100644 --- a/settings.php +++ b/settings.php @@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die(); if ($hassiteconfig || has_capability('theme/boost_union:configure', context_system::instance())) { + global $PAGE; // How this file works: // This theme's settings are divided into multiple settings pages. @@ -44,6 +45,9 @@ // Avoid that the theme settings page is auto-created. $settings = null; + // Load admin tab remember js + $PAGE->requires->js_call_amd('theme_boost_union/admintabs', 'init'); + // Create custom admin settings category. $ADMIN->add('themes', new admin_category('theme_boost_union', get_string('pluginname', 'theme_boost_union', null, true)));