Making WordPress.org

Changeset 13306


Ignore:
Timestamp:
03/11/2024 11:26:16 PM (3 years ago)
Author:
adamwood
Message:

wporg-bbp-also-viewing: Handle block themes

Insert the banner below the local nav or lang guess blocks if present

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.js

    r12577 r13306  
    1212                $adminbar = false,
    1313                $header = false,
     14                $localNavBar = false,
     15                $langBanner = false,
    1416                bannerOffset = 200,
    1517                isTyping = false,
    … …  
    2527                $adminbar = jQuery('#wpadminbar');
    2628                $header = jQuery('header.global-header');
     29                $localNavBar = jQuery('.wp-block-wporg-local-navigation-bar');
     30                $langBanner = jQuery('.wp-block-wporg-language-suggest');
    2731
    2832                maybeDisplay();
    … …  
    4852                        }
    4953
    50                         jQuery('#main').before(
    51                                 '<div id="also-viewing-banner" style="display: none; font-size: 0.8rem; color: #fff; line-height: 2rem; background: #d54e21; width:100%; text-align: center; position: initial; top: 32px; left: 0; z-index: 150;"></div>'
    52                         );
     54                        // If using a block based theme with the local nav bar block
     55                        if ( $localNavBar.length ) {
     56                                // Insert the banner after the language banner if present,
     57                                // otherwise after the local nav
     58                                $element = $langBanner.length ? $langBanner : $localNavBar;
     59
     60                                $element.after(
     61                                        '<div id="also-viewing-banner" style="display: none; font-size: var(--wp--preset--font-size--extra-small, 12px); color: var(--wp--preset--color--charcoal-1, #1E1E1E); line-height: 18px; padding-top: 8px; padding-bottom: 8px; background: var(--wp--preset--color--acid-green-3, #E2FFED); width: 100%; text-align: center; position: initial; top: 32px; left: 0; z-index: 150;"></div>'
     62                                );
     63                        } else {
     64                                jQuery('#main').before(
     65                                        '<div id="also-viewing-banner" style="display: none; font-size: 0.8rem; color: #fff; line-height: 2rem; background: #d54e21; width:100%; text-align: center; position: initial; top: 32px; left: 0; z-index: 150;"></div>'
     66                                );
     67                        }
     68
    5369                        banner = jQuery( '#also-viewing-banner' );
    5470                }
    … …  
    106122                }
    107123
    108                 var offset = 'var(--wp-admin--admin-bar--height, 0px)';
    109                 if ( 'fixed' === $header.css('position') ) {
    110                         offset = 'var(--wp-global-header-offset, 0px)';
    111                 }
    112 
    113                 if ( jQuery(window).scrollTop() > bannerOffset ) {
    114                         banner.css( 'position', 'fixed' );
    115                         banner.css( 'top', offset );
     124                if ( $localNavBar.length ) {
     125                        // Local nav bar position is set to relative on small screens to stop it being sticky
     126                        if ( $localNavBar.hasClass( 'is-sticking' ) && $localNavBar.css( 'position' ) !== 'relative' ) {
     127                                banner.css( 'position', 'sticky' );
     128                                banner.css( 'top', 'calc(var(--wp-admin--admin-bar--height, 0px) + var(--wp--custom--local-navigation-bar--spacing--height, 60px))' );
     129                        } else {
     130                                banner.css( 'position', 'initial' );
     131                                banner.css( 'top', '' );
     132                        }
    116133                } else {
    117                         banner.css( 'position', 'initial' );
    118                         banner.css( 'top', '' );
     134                        var offset = 'var(--wp-admin--admin-bar--height, 0px)';
     135                        if ( 'fixed' === $header.css('position') ) {
     136                                offset = 'var(--wp-global-header-offset, 0px)';
     137                        }
     138
     139                        if ( jQuery(window).scrollTop() > bannerOffset ) {
     140                                banner.css( 'position', 'fixed' );
     141                                banner.css( 'top', offset );
     142                        } else {
     143                                banner.css( 'position', 'initial' );
     144                                banner.css( 'top', '' );
     145                        }
    119146                }
    120147        } );
Note: See TracChangeset for help on using the changeset viewer.