From 8dd594a2b9d25cfb7c2c3a76576c9f5a4976a4d5 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 30 Oct 2020 17:24:19 -0300 Subject: [PATCH] Adds 0.17 feature of fixing filter panel aside. Creates option to disable it. --- src/assets/scss/_home-collection.scss | 3 +- src/functions/customizer.php | 62 +++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/assets/scss/_home-collection.scss b/src/assets/scss/_home-collection.scss index 4e3e2cd..fd95b95 100644 --- a/src/assets/scss/_home-collection.scss +++ b/src/assets/scss/_home-collection.scss @@ -308,4 +308,5 @@ $numOfElems: 8; transform: translateX(-4em) rotate($deg/2 - $deg * ($i - 2)); } } -} \ No newline at end of file +} + diff --git a/src/functions/customizer.php b/src/functions/customizer.php index 85db68f..2dd92ee 100644 --- a/src/functions/customizer.php +++ b/src/functions/customizer.php @@ -1159,6 +1159,26 @@ function tainacan_customize_register( $wp_customize ) { 'description' => __( 'Toggle to make filters start hidden by default.', 'tainacan-interface' ) ) ); + if (version_compare(TAINACAN_VERSION, '0.17RC') >= 0) { + /** + * Adds option to display filters as a modal on every items list. + */ + $wp_customize->add_setting( 'tainacan_items_page_filters_fixed_on_scroll', array( + 'type' => 'theme_mod', + 'capability' => 'edit_theme_options', + 'default' => true, + 'transport' => 'refresh', + 'sanitize_callback' => 'tainacan_callback_sanitize_checkbox' + ) ); + $wp_customize->add_control( 'tainacan_items_page_filters_fixed_on_scroll', array( + 'type' => 'checkbox', + 'priority' => 10, // Within the section. + 'section' => 'tainacan_items_page_filters_panel', + 'label' => __( 'Filters side panel fixed on scroll', 'tainacan-interface' ), + 'description' => __( 'Toggle to make filters get fixed on screen when scrolling down the items list. This will only take effect if the items list itself is taller than the screen height.', 'tainacan-interface' ) + ) ); + } + /** * Adds option to display filters as a modal on every items list. */ @@ -2350,3 +2370,45 @@ function tainacan_single_item_metadata_columns_count_output() { echo ''; } add_action( 'wp_head', 'tainacan_single_item_metadata_columns_count_output'); + +/** + * Enqueues front-end CSS for the items page fixed filters logic. + * + * @since Tainacan Theme + * + * @see wp_add_inline_style() + */ +function tainacan_items_page_filters_fixed_on_scroll_output() { + $should_use_fixed_filters_logic = get_theme_mod( 'tainacan_items_page_filters_fixed_on_scroll', true ); + + if (!$should_use_fixed_filters_logic) + return; + + $css = ' + /* Items list fixed filter logic (Introduced in Tainacan 0.17) */ + :not(.wp-block-tainacan-faceted-search)>.theme-items-list:not(.is-fullscreen).is-filters-menu-open.is-filters-menu-fixed-at-top .items-list-area { + margin-left: var(--tainacan-filter-menu-width-theme) !important; + } + :not(.wp-block-tainacan-faceted-search)>.theme-items-list:not(.is-fullscreen).is-filters-menu-open.is-filters-menu-fixed-at-top .filters-menu:not(.filters-menu-modal) { + position: fixed; + top: 0px !important; + } + :not(.wp-block-tainacan-faceted-search)>.theme-items-list:not(.is-fullscreen).is-filters-menu-open.is-filters-menu-fixed-at-top .filters-menu:not(.filters-menu-modal) .modal-content { + position: absolute; + top: 0px; + height: auto !important; + background: var(--tainacan-background-color, inherit); + } + :not(.wp-block-tainacan-faceted-search)>.theme-items-list:not(.is-fullscreen).is-filters-menu-open.is-filters-menu-fixed-at-top.is-filters-menu-fixed-at-bottom .filters-menu:not(.filters-menu-modal) { + position: absolute; + } + :not(.wp-block-tainacan-faceted-search)>.theme-items-list:not(.is-fullscreen).is-filters-menu-open.is-filters-menu-fixed-at-top.is-filters-menu-fixed-at-bottom .filters-menu:not(.filters-menu-modal) .modal-content { + top: auto; + bottom: 0; + } + '; + echo ''; + +} +add_action( 'wp_head', 'tainacan_items_page_filters_fixed_on_scroll_output'); +