From 5d316201b4dd40ba8f2873b43772663819309d6a Mon Sep 17 00:00:00 2001 From: meirzamoodle Date: Sat, 29 Jun 2024 22:26:45 +0700 Subject: [PATCH] MDL-81129 hub: Update the intro paragraph on the site registration page I added a new javascript in admin to trigger a collapse element to be expanded using the URL hash. --- admin/amd/build/expand_hash.min.js | Bin 0 -> 1565 bytes admin/amd/build/expand_hash.min.js.map | Bin 0 -> 3773 bytes admin/amd/src/expand_hash.js | 74 +++++++++++++++++++++++++ admin/registration/index.php | 3 + admin/renderer.php | 12 ++-- lang/en/deprecated.txt | 1 + lang/en/hub.php | 17 +++--- 7 files changed, 91 insertions(+), 16 deletions(-) create mode 100644 admin/amd/build/expand_hash.min.js create mode 100644 admin/amd/build/expand_hash.min.js.map create mode 100644 admin/amd/src/expand_hash.js diff --git a/admin/amd/build/expand_hash.min.js b/admin/amd/build/expand_hash.min.js new file mode 100644 index 0000000000000000000000000000000000000000..e6d91b7003b5e268d8639bccbd88d36767fd120c GIT binary patch literal 1565 zcma)7(QcbC6n)QEc-}*yqNdWemu7V9GPYGpny6`|NmUiO*a3IOX0}O|wfXlM3?%8A ztq2L(oO|v)_Z|bGb0(+<6RGG7lbnf={wlB_vkdDD1~dul0dnrI;z z0muDbczDN^}NCcn8;$KSeh9N z98sozWAHw&p9m{0g=Lb2Q3&+WE#)x z&M3aPnnnjV1RH#0WSVjs*%`W)z}tgh6ZU01xSn2pi!b8ule3G@n`nsUGAZ?u>pARq zL#RjM`O)cvE1`xtR77k@-R7SqRja9OdSayV{-4h8i<0vw+9G>=+*%+^NW8EE95QXF zpvrpEw)h7Oyt#GU&igR2TfgS@xvcK>Pai*EIb;n|pAMxu!6RBF`~D$=C8f*+#p{ zv0}IxDbu$lXjDm`3EE$YZCK-$w*E%nK4Vl? zbRwL+x}`lQWliSZHZa5KC=G+bgxm4i$5C_Eg}E_ literal 0 HcmV?d00001 diff --git a/admin/amd/build/expand_hash.min.js.map b/admin/amd/build/expand_hash.min.js.map new file mode 100644 index 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EB8A7bo$^eeQ&zsu8}n^51JVF$43Yr9Sj)UBMncd18&XKz>n!HJ6~{p zRCc@Sa+2nIH&1fLv%>~6MrO{M*1)xE4qSj8zV{PqEPX9~zDy2Qe7(jIf&WTc@0-tn zZKDATzKd8~M8V%9*84qT!766SHVS@-*x={j3rl{EgKNgJIG8XtiGvK+mw}Ag#k)8T z1`MBo+izI$i=c=Y1DY`oKC`%j(bhit$-rEHHpV=V5#uWE8MGow@GM?OaWI3yaBrU! z_&`X41rY9{p5M-Ffn8z!rSJJHKzabStm;j?)y7#F*CM)f+uq^khbS1axbCIKocApD zqA>t;{I~dXU<_q6wOnR_U`(8Y{zch~?b01MWBXYQC^o_hSY95iBtgnp8vK)8EaRcy vW8_FUMp%mf5nuVGbRTXNA-U0ok9xkBkif**jWh4n`xY?vOF!)awjTcr;(XpY literal 0 HcmV?d00001 diff --git a/admin/amd/src/expand_hash.js b/admin/amd/src/expand_hash.js new file mode 100644 index 00000000000..77094466cb3 --- /dev/null +++ b/admin/amd/src/expand_hash.js @@ -0,0 +1,74 @@ +// 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 . + +/** + * Expand the collapse section element. + * + * @module core_admin/expand_hash + * @copyright Meirza + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since 4.5 + */ + +const SELECTORS = { + COLLAPSE_ELEMENTS: '[data-toggle="collapse"]', + FOCUSTHENEXPAND_ELEMENTS: '.focus-expand', +}; + +/** + * Initializes the focus and expand functionality. + */ +export const init = () => { + // Select all collapsible elements only. + const focusexpand = document.querySelector(SELECTORS.FOCUSTHENEXPAND_ELEMENTS); + + // Add click event listener to the anchor element + focusexpand?.addEventListener('click', () => { + expandSection(`${focusexpand.getAttribute('href')}`); + }); +}; + +/** + * Expands a section based on the provided URL hash. + * + * This function takes a hash string, finds the corresponding element in the DOM, + * and expands it if it is currently collapsed. It updates the necessary ARIA + * attributes and classes to reflect the expanded state. + * + * @param {string} hash - The hash (e.g., '#elementId') of the element to expand. + */ +export const expandSection = (hash) => { + const container = document.querySelector(hash); + const targetContainer = container?.querySelector(SELECTORS.COLLAPSE_ELEMENTS); + + if (targetContainer?.getAttribute('aria-expanded') === 'false') { + const collapseId = targetContainer.getAttribute('aria-controls'); + const collapseContainer = document.getElementById(collapseId); + + // Show the content. + collapseContainer.classList.remove('collapse'); + collapseContainer.classList.add('show'); + + // Update aria-expanded attribute to reflect the new state. + targetContainer.setAttribute('aria-expanded', 'true'); + targetContainer.classList.remove('collapsed'); + + // Get collapse expand menu element. + const collapseElement = document.querySelector('.collapseexpand.collapsemenu'); + // Ensure it gets noticed to make it work. + collapseElement.setAttribute('aria-expanded', 'true'); + collapseElement.classList.remove('collapsed'); + } +}; diff --git a/admin/registration/index.php b/admin/registration/index.php index ede6a67a47e..09b3e920871 100644 --- a/admin/registration/index.php +++ b/admin/registration/index.php @@ -125,4 +125,7 @@ if (\core\hub\registration::is_registered()) { echo html_writer::div(html_writer::link(new moodle_url($returnurl), get_string('skipregistration', 'hub')), 'skipregistration mt-2'); } + +$PAGE->requires->js_call_amd('core_admin/expand_hash', 'init'); + echo $OUTPUT->footer(); diff --git a/admin/renderer.php b/admin/renderer.php index 6e53a42ad2e..bc0eb4ea6e9 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -2206,14 +2206,10 @@ class core_admin_renderer extends plugin_renderer_base { * @return string */ public function moodleorg_registration_message() { - - $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub'), FORMAT_MARKDOWN); - - $out .= html_writer::link( - MOODLE_PRODUCTURL.'/solutions/moodle-app/', - $this->output->pix_icon('i/info', '').' '.get_string('registerwithmoodleorginfoapp', 'core_hub'), - ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href'] - ); + $a = new stdClass(); + $a->moreinformation = '#id_sitestats'; // More information anchor. + $a->moodleapp = HUB_MOODLEORGHUBURL . '/solutions/moodle-app/'; + $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub', $a), FORMAT_MARKDOWN); $out .= html_writer::link( HUB_MOODLEORGHUBURL, diff --git a/lang/en/deprecated.txt b/lang/en/deprecated.txt index 9b7bebd3cb5..8a5c144ea44 100644 --- a/lang/en/deprecated.txt +++ b/lang/en/deprecated.txt @@ -127,3 +127,4 @@ reviewbadge,core_badges myisamproblem,core_error newpasswordtext,core cannotsetpassword,core_error +registerwithmoodleorginfoapp,core_hub diff --git a/lang/en/hub.php b/lang/en/hub.php index a82ad1af2fc..ff27b209b12 100644 --- a/lang/en/hub.php +++ b/lang/en/hub.php @@ -105,15 +105,15 @@ $string['registeredactiveuserdevices'] = 'Number of active users with registered $string['registerwithmoodleorg'] = 'Register your site'; $string['registerwithmoodleorgupdate'] = 'Update your site registration'; $string['registerwithmoodleorgcomplete'] = 'Complete your site registration'; -$string['registerwithmoodleorginfo'] = 'We\'d love to stay in touch and provide you with important things for your Moodle site! By registering: +$string['registerwithmoodleorginfo'] = 'Registering your site involves periodically sending anonymised site stats to Moodle HQ. This helps us gain insights into how you\'re using Moodle, and make decisions about new features and plugins. -* You can subscribe to receive notifications of new Moodle releases, security alerts and other important news. -* You can access and activate mobile push notifications from your Moodle site through our free Moodle app. -* You are contributing to our Moodle statistics of the worldwide community, which help us improve Moodle and our community sites. -* If you wish, your site can be included in the list of registered Moodle sites in your country.'; -$string['registerwithmoodleorginfoapp'] = 'About the Moodle app'; -$string['registerwithmoodleorginfostats'] = 'Moodle statistics'; -$string['registerwithmoodleorginfosites'] = 'Other sites in my country'; +Plus, it enables you to: + +* Stay up to date with important updates, like security alerts and new available releases. +* Activate mobile push notifications for the Moodle App. +* Increase the visibility of your site by featuring it on the list of registered Moodle sites in your country (optional).'; +$string['registerwithmoodleorginfosites'] = 'Discover other sites in my country'; +$string['registerwithmoodleorginfostats'] = 'View global Moodle stats'; $string['registerwithmoodleorgremove'] = 'You are about to unregister your site. You will no longer receive security alert notifications and users will not be able to receive push notifications from your site to their Moodle app. However, you will be able to re-register at any time! Are you sure you want to continue?'; $string['registrationconfirmed'] = 'Site registration confirmed'; $string['registrationconfirmedon'] = 'Thank you for registering your site. Registration information will be kept up to date by the \'Site registration\' scheduled task.'; @@ -178,5 +178,6 @@ $string['wrongtoken'] = 'The registration failed for some unknown reason (networ $string['sitecommnewsno'] = 'No, I do not wish to receive any emails'; // Deprecated since 4.5. +$string['registerwithmoodleorginfoapp'] = 'About the Moodle app'; $string['siteregistrationcontact'] = 'Display contact form'; $string['siteregistrationcontact_help'] = 'If you allow it, other people in our Moodle community (who need a login account) can contact you via a form on our Moodle community site. However, they will never be able to see your email address.'; -- 2.43.0