Skip to:
Content

bbPress.org


Ignore:
Timestamp:
05/26/2017 09:50:36 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Forms: Introduce bbp_tab_index_attribute() helpers to handle tabindex attribute output.

Note that these functions are used but normally their output is suppressed, because overriding the browser's natural tabindex order is impolite, and may introduce more issues than it actually fixes.

(Also includes some surrounding code clean-up.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/common/template.php

    r6415 r6433  
    13981398
    13991399        return apply_filters( 'bbp_get_tab_index', (int) $bbp->tab_index );
     1400    }
     1401
     1402/**
     1403 * Output a "tabindex" attribute for an element, if an index was passed.
     1404 *
     1405 * This helper function is in use, but it is generally considered impolite to
     1406 * override the "tabindex" attribute beyond what the browser naturally assigns.
     1407 *
     1408 * Most internal usages pass `false` which results in no attribute being used.
     1409 *
     1410 * @since 2.6.0 bbPress (r6424)
     1411 *
     1412 * @param mixed $tab False to skip, any integer to use
     1413 */
     1414function bbp_tab_index_attribute( $tab = false ) {
     1415    echo bbp_get_tab_index_attribute( $tab );
     1416}
     1417
     1418    /**
     1419     * Return a "tabindex" attribute for an element, if an index was passed.
     1420     *
     1421     * This helper function is in use, but it is generally considered impolite to
     1422     * override the "tabindex" attribute beyond what the browser naturally assigns.
     1423     *
     1424     * Most internal usages pass `false` which results in no attribute being used.
     1425     *
     1426     * @since 2.6.0 bbPress (r6424)
     1427     *
     1428     * @param mixed $tab False to skip, any integer to use
     1429     *
     1430     * @return string
     1431     */
     1432    function bbp_get_tab_index_attribute( $tab = false ) {
     1433
     1434        // Get attribute
     1435        $attr = is_numeric( $tab )
     1436            ? ' tabindex="' . (int) $tab . '"'
     1437            : '';
     1438
     1439        // Filter & return
     1440        return apply_filters( 'bbp_get_tab_index_attribute', $attr, $tab );
    14001441    }
    14011442
     
    18841925         * escaping the editable output, mucking up existing content.
    18851926         */
    1886         else :
    1887 
    1888             // Setup the tab index attribute
    1889             $tab = ! empty( $r['tab'] ) ? ' tabindex="' . intval( $r['tab'] ) . '"' : ''; ?>
    1890 
    1891             <textarea id="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" class="<?php echo esc_attr( $r['editor_class'] ); ?>" name="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" cols="60" rows="<?php echo esc_attr( $r['textarea_rows'] ); ?>" <?php echo $tab; ?>><?php echo $post_content; ?></textarea>
     1927        else : ?>
     1928
     1929            <textarea id="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" class="<?php echo esc_attr( $r['editor_class'] ); ?>" name="bbp_<?php echo esc_attr( $r['context'] ); ?>_content" cols="60" rows="<?php echo esc_attr( $r['textarea_rows'] ); ?>" <?php bbp_tab_index_attribute( $r['tab'] ); ?>><?php echo $post_content; ?></textarea>
    18921930
    18931931        <?php endif;
Note: See TracChangeset for help on using the changeset viewer.