From 86853cc6e6f6d78bb55bf435ce61c4d0d03573c4 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:15:19 +0100 Subject: [PATCH] Add option to collapse chapter groups by default --- DOCUMENTATION.md | 4 ++-- INSTALLATION.md | 2 +- includes/functions/_shortcodes.php | 4 ++++ includes/functions/settings/_register_settings.php | 7 +++++++ .../functions/settings/_settings_page_general.php | 9 +++++++++ partials/_story-content.php | 14 ++++++++++++-- 6 files changed, 35 insertions(+), 5 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index d32c6394..78039c68 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -483,14 +483,14 @@ Renders a list of chapters identical to those on story pages, ordered by sequenc * **offset:** Skip a number of chapters, which can make sense if you query all. * **heading:** Show a heading with collapse toggle above the list. * **group:** Only show chapters with a specific group name, which can transcend stories. -* **class:** Additional CSS classes, separated by whitespace. +* **class:** Additional CSS classes, separated by whitespace. `no-auto-collapse` prevents default group collapsing (if set). ``` [fictioneer_chapter_list story="69"] ``` ``` -[fictioneer_chapter_list story="69" count="10" offset="2"] +[fictioneer_chapter_list class="foobar no-auto-collapse" story="69" count="10" offset="2"] ``` ``` diff --git a/INSTALLATION.md b/INSTALLATION.md index b214ed34..bdd869d9 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -708,7 +708,7 @@ You can choose between three different header styles: **default**, **top**, and  -While the customization options are not as extensive as with multi-purpose themes or page builders, you can achieve quite a lot with some simple [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) snippets. Easy to learn, hard to master. However, following are several snippets you can use and modify to your needs. Just put them into **Customizer > Additional CSS** or a child theme. This is by far the most powerful way of customization — there are over 500 properties and near infinite possible values that can be assigned to each and every element (although not all are valid, never mind reasonable). +While the customization options are not as extensive as with multi-purpose themes or page builders, you can achieve quite a lot with some simple [CSS](https://developer.mozilla.org/en-US/docs/Web/CSS) snippets. Easy to learn, hard to master. However, following are several snippets you can use and modify to your needs. Just put them into **Customizer > Additional CSS** or a child theme. This is by far the most powerful way of customization — there are over 500 properties and virtually infinite possible values and combinations that can be assigned to each and every element. **Developer Tools:** Your very best friend! You can open them by right-clicking anywhere on the site and hitting **Inspect**, directly highlighting the element you are on. Hit **\[Option\] + \[⌘\] + \[J\]** (on macOS) or **\[Shift\] + \[CTRL\] + \[J\]** (on Windows/Linux) if you want to use the keyboard. Here you can see the HTML and applied CSS styles; you can even manipulate them to see what happens. There are many tutorials online on how to use the tools, please consult one first if you are new. diff --git a/includes/functions/_shortcodes.php b/includes/functions/_shortcodes.php index 362227a2..e56c687a 100644 --- a/includes/functions/_shortcodes.php +++ b/includes/functions/_shortcodes.php @@ -911,6 +911,10 @@ function fictioneer_shortcode_chapter_list( $attr ) { $classes .= ' _no-icons'; } + if ( get_option( 'fictioneer_collapse_groups_by_default' ) && ! str_contains( $classes, 'no-auto-collapse' ) ) { + $classes .= ' _closed'; + } + // Apply offset and count if ( ! $group ) { $chapters = array_slice( $chapters, $offset ); diff --git a/includes/functions/settings/_register_settings.php b/includes/functions/settings/_register_settings.php index 6a161840..168d31c7 100644 --- a/includes/functions/settings/_register_settings.php +++ b/includes/functions/settings/_register_settings.php @@ -474,6 +474,13 @@ define( 'FICTIONEER_OPTIONS', array( 'sanitize_callback' => 'fictioneer_sanitize_checkbox', 'label' => __( 'Disable collapsing of chapters', 'fictioneer' ), 'default' => 0 + ), + 'fictioneer_collapse_groups_by_default' => array( + 'name' => 'fictioneer_collapse_groups_by_default', + 'group' => 'fictioneer-settings-general-group', + 'sanitize_callback' => 'fictioneer_sanitize_checkbox', + 'label' => __( 'Collapse chapter groups by default', 'fictioneer' ), + 'default' => 0 ), 'fictioneer_enable_public_cache_compatibility' => array( 'name' => 'fictioneer_enable_public_cache_compatibility', diff --git a/includes/functions/settings/_settings_page_general.php b/includes/functions/settings/_settings_page_general.php index 6b439b5a..af20298c 100644 --- a/includes/functions/settings/_settings_page_general.php +++ b/includes/functions/settings/_settings_page_general.php @@ -159,6 +159,15 @@ ?> +