Skip to:
Content

bbPress.org

Changeset 7230


Ignore:
Timestamp:
02/17/2022 06:36:20 PM (3 years ago)
Author:
johnjamesjacoby
Message:

Theme Compat: improve "no-js" body class swapping.

This change introduces a new helper function (bbp_swap_no_js_body_class()) which is used to output the <script> tag that was previously inside of the single template part that needed it.

It also adds a prefix (bbp) to those "no-js" body classes, with the intention of avoiding conflicts with other plugins & themes that may also be using the no-js body class for their own purposes.

Props dd32, r-a-y.

In branches/2.6 for 2.6.10. Fixes #3445.

Location:
branches/2.6/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/src/includes/common/template.php

    r7221 r7230  
    7171
    7272/**
    73  * Add our custom head action to wp_head
     73 * Add our custom footer action to wp_footer
    7474 *
    7575 * @since 2.0.0 bbPress (r2464)
     
    10831083    if ( ! empty( $bbp_classes ) ) {
    10841084        $bbp_classes[] = 'bbpress';
    1085         $bbp_classes[] = 'no-js';
     1085        $bbp_classes[] = 'bbp-no-js';
    10861086    }
    10871087
     
    10961096    // Filter & return
    10971097    return (array) apply_filters( 'bbp_body_class', $classes, $bbp_classes, $wp_classes, $custom_classes );
     1098}
     1099
     1100/**
     1101 * Output a small piece of JavaScript to replace the "bbp-no-js" body class
     1102 * with "bbp-js" to allow interactive & dynamic elements to work as intended.
     1103 *
     1104 * @since 2.6.10 bbPress (r7229)
     1105 */
     1106function bbp_swap_no_js_body_class() {
     1107    static $done = false;
     1108
     1109    // Bail if already done
     1110    if ( true === $done ) {
     1111        return;
     1112    }
     1113
     1114    // Mark as done
     1115    $done = true;
     1116
     1117?>
     1118
     1119<script type="text/javascript" id="bbp-swap-no-js-body-class">
     1120    document.body.className = document.body.className.replace( 'bbp-no-js', 'bbp-js' );
     1121</script>
     1122
     1123<?php
    10981124}
    10991125
  • branches/2.6/src/includes/core/actions.php

    r7087 r7230  
    130130add_action( 'bbp_init', 'bbp_topic_content_autoembed', 8 );
    131131
     132// <body> class swap from "bbp-no-js" to "bbp-js"
     133add_action( 'wp_body_open', 'bbp_swap_no_js_body_class' );
     134add_action( 'bbp_footer',   'bbp_swap_no_js_body_class' );
     135
    132136/**
    133137 * bbp_ready - attached to end 'bbp_init' above
     
    138142 */
    139143add_action( 'bbp_ready',  'bbp_setup_akismet',    2  ); // Spam prevention for topics and replies
     144
     145// Setup BuddyPress using its own hook
    140146add_action( 'bp_include', 'bbp_setup_buddypress', 10 ); // Social network integration
    141147
  • branches/2.6/src/templates/default/bbpress/form-user-passwords.php

    r7189 r7230  
    1313// Filters the display of the password fields
    1414if ( apply_filters( 'show_password_fields', true, bbpress()->displayed_user ) ) : ?>
    15 
    16 <script type="text/javascript">
    17     document.body.className = document.body.className.replace( 'no-js', 'js' );
    18 </script>
    1915
    2016<div id="password" class="user-pass1-wrap">
  • branches/2.6/src/templates/default/css/bbpress.css

    r7189 r7230  
    99-------------------------------------------------------------- */
    1010
     11/* Hide completely (including from screen readers) */
    1112.hidden,
    12 .no-js .hide-if-no-js,
    13 .js .hide-if-js {
     13.bbp-no-js .hide-if-no-js,
     14.bbp-js .hide-if-js {
    1415    display: none;
    1516}
    1617
    17 /* Hide visually but not from screen readers */
     18/* Hide visually (but not from screen readers) */
    1819.screen-reader-text,
    1920.screen-reader-text span,
Note: See TracChangeset for help on using the changeset viewer.