From f4d58a1ef7fafc19e97b9941f72f15c7fe3e8b95 Mon Sep 17 00:00:00 2001 From: Antoine Le Gonidec Date: Fri, 26 Jul 2024 12:39:19 +0200 Subject: [PATCH] Handle buttons with sub-buttons in CSS instead of JS --- css/index.css | 12 ++++++++++ index.template.php | 59 ++++++++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/css/index.css b/css/index.css index cfcc73e..12009e1 100644 --- a/css/index.css +++ b/css/index.css @@ -224,6 +224,18 @@ summary { margin: 5px 0; } +/* Handle buttons with sub-buttons in CSS instead of JS. */ +details > summary { + list-style: none; + margin: 0; +} +details > summary::before { + content: "▼"; +} +details[open] > summary::before { + content: "▲"; +} + /* Define strong as bold, and em as italics */ /* Note: in some particular places, strong has been redefined as font-weight: 600; */ /* This gives a better effect for those areas, and will default to bold for fonts which do not support numerical font-weight */ diff --git a/index.template.php b/index.template.php index b60d43f..a4d9950 100644 --- a/index.template.php +++ b/index.template.php @@ -670,39 +670,52 @@ function template_button_strip_single_button($key, $value, $buttons) { // As of 2.1, the 'test' for each button happens while the array is being generated. The extra 'test' check here is deprecated but kept for backward compatibility (update your mods, folks!) if (!isset($value['test']) || !empty($context[$value['test']])) { + // Buttons used to spawn another list of options are handled in a dedicated function. + if (!empty($value['sub_buttons'])) + return template_button_strip_single_button_with_sub_buttons($key, $value, $buttons); + if (!isset($value['id'])) $value['id'] = $key; $button = ' '.(!empty($value['icon']) ? '' : '').'' . $txt[$value['text']] . ''; - if (!empty($value['sub_buttons'])) - { - $button .= ' -
-
-
'; - foreach ($value['sub_buttons'] as $element) - { - if (isset($element['test']) && empty($context[$element['test']])) - continue; - - $button .= ' - ' . $txt[$element['text']] . ''; - if (isset($txt[$element['text'] . '_desc'])) - $button .= '
' . $txt[$element['text'] . '_desc'] . ''; - $button .= '
'; - } - $button .= ' -
-
-
'; - } - $buttons[] = $button; } return $buttons; } +function template_button_strip_single_button_with_sub_buttons($key, $value, $buttons) { + global $context, $txt; + + if (!isset($value['id'])) + $value['id'] = $key; + + $button = ' +
+ + '.(!empty($value['icon']) ? '' : '').'' . $txt[$value['text']] . ' + '; + + $button .= ' + +
'; + + $buttons[] = $button; + return $buttons; +} /** * Generate a list of quickbuttons.