Making WordPress.org

Changeset 6841


Ignore:
Timestamp:
03/08/2018 02:51:43 AM (9 years ago)
Author:
SergeyBiryukov
Message:

Breathe: Convert close button for Welcome box to a toggle.

Props dotrex, boemedia.
Fixes #3393.

Location:
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-breathe
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-breathe/functions.php

    r6563 r6841  
    4747
    4848        // Cacheing hack
    49         wp_enqueue_style( 'wporg-breathe', get_stylesheet_uri(), array( 'p2-breathe' ), '20180207a' );
     49        wp_enqueue_style( 'wporg-breathe', get_stylesheet_uri(), array( 'p2-breathe' ), '20180208a' );
    5050}
    5151add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\styles', 11 );
    … …  
    6060        ?>
    6161        <script type="text/javascript">
    62                 var el = document.getElementById( 'make-welcome-hide' );
     62                var el = document.getElementById( 'make-welcome-toggle' );
    6363                if ( el ) {
    6464                        el.addEventListener( 'click', function( e ) {
    65                                 document.cookie = el.dataset.cookie + '=' + el.dataset.hash +
    66                                         '; expires=Fri, 31 Dec 9999 23:59:59 GMT' +
    67                                         '; domain=<?php echo esc_js( $current_site->domain ); ?>' +
    68                                         '; path=<?php echo esc_js( $current_site->path ); ?>';
    69                                 jQuery( '.make-welcome' ).slideUp();
     65                                if ( jQuery( '.make-welcome .entry-content' ).is( ':hidden' ) ) {
     66                                        document.cookie = el.dataset.cookie + '=' +
     67                                                '; expires=Thu, 01 Jan 1970 00:00:00 GMT' +
     68                                                '; domain=<?php echo esc_js( $current_site->domain ); ?>' +
     69                                                '; path=<?php echo esc_js( $current_site->path ); ?>';
     70                                        jQuery( '#make-welcome-toggle' ).text( '<?php esc_attr_e( 'Hide welcome box', 'wporg' ); ?>' );
     71                                } else {
     72                                        document.cookie = el.dataset.cookie + '=' + el.dataset.hash +
     73                                                '; expires=Fri, 31 Dec 9999 23:59:59 GMT' +
     74                                                '; domain=<?php echo esc_js( $current_site->domain ); ?>' +
     75                                                '; path=<?php echo esc_js( $current_site->path ); ?>';
     76                                        jQuery( '#make-welcome-toggle' ).text( '<?php esc_attr_e( 'Show welcome box', 'wporg' ); ?>' );
     77                                }
     78
     79                                jQuery( '.make-welcome .entry-content' ).slideToggle();
     80                                jQuery( '.make-welcome .post-edit-link' ).toggle();
    7081                        } );
    7182                }
    … …  
    7687
    7788function welcome_box() {
    78         $welcome = get_page_by_path( 'welcome' );
    79         $cookie  = 'welcome-' . get_current_blog_id();
    80         $hash    = isset( $_COOKIE[ $cookie ] ) ? $_COOKIE[ $cookie ] : '';
     89        $welcome      = get_page_by_path( 'welcome' );
     90        $cookie       = 'welcome-' . get_current_blog_id();
     91        $hash         = isset( $_COOKIE[ $cookie ] ) ? $_COOKIE[ $cookie ] : '';
    8192        $content_hash = $welcome ? md5( $welcome->post_content ) : '';
    8293
    83         if ( $welcome && ( empty( $hash ) || $content_hash !== $hash ) ) :
    84                 $columns = preg_split( '|<hr\s*/?>|', $welcome->post_content );
    85                 if ( count( $columns ) === 2 ) {
    86                         $welcome->post_content = "<div class='content-area'>\n\n{$columns[0]}</div><div class='widget-area'>\n\n{$columns[1]}</div>";
    87                 }
    88 
    89                 setup_postdata( $welcome );
    90 
    91                 // Disable Jetpack sharing buttons
    92                 add_filter( 'sharing_show', '__return_false' );
     94        if ( ! $welcome ) {
     95                return;
     96        }
     97
     98        if ( ! $hash || $content_hash !== $hash ) {
     99                $class = '';
     100                $label = __( 'Hide welcome box', 'wporg' );
     101        } else {
     102                $class = 'hidden';
     103                $label = __( 'Show welcome box', 'wporg' );
     104        }
     105
     106        $columns = preg_split( '|<hr\s*/?>|', $welcome->post_content );
     107        if ( count( $columns ) === 2 ) {
     108                $welcome->post_content = "<div class='content-area'>\n\n{$columns[0]}</div><div class='widget-area'>\n\n{$columns[1]}</div>";
     109        }
     110
     111        setup_postdata( $welcome );
     112
     113        // Disable Jetpack sharing buttons
     114        add_filter( 'sharing_show', '__return_false' );
    93115        ?>
    94116        <div class="make-welcome">
    95117                <div class="entry-meta">
    96                         <?php edit_post_link( __( 'Edit', 'wporg' ), '', '', $welcome->ID ); ?>
    97                         <button type="button" id="make-welcome-hide" class="toggle dashicons dashicons-no" data-hash="<?php echo $content_hash; ?>" data-cookie="<?php echo $cookie; ?>" title="<?php esc_attr_e( 'Hide this message', 'wporg' ); ?>"></button>
     118                        <?php edit_post_link( __( 'Edit', 'wporg' ), '', '', $welcome->ID, 'post-edit-link ' . $class ); ?>
     119                        <button type="button" id="make-welcome-toggle" data-hash="<?php echo $content_hash; ?>" data-cookie="<?php echo $cookie; ?>"><?php echo $label; ?></button>
    98120                </div>
    99                 <div class="entry-content clear">
     121                <div class="entry-content clear <?php echo $class; ?>"">
    100122                        <?php the_content(); ?>
    101123                </div>
    102124        </div>
    103125        <?php
    104                 remove_filter( 'sharing_show', '__return_false' );
    105                 wp_reset_postdata();
    106         endif;
     126        remove_filter( 'sharing_show', '__return_false' );
     127        wp_reset_postdata();
    107128}
    108129add_action( 'wporg_breathe_after_header', __NAMESPACE__ . '\welcome_box' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-breathe/style.css

    r6562 r6841  
    787787
    788788.make-welcome .entry-meta {
    789         margin: 15px;
     789        margin: 1em;
    790790        position: absolute;
    791791        right: 0;
    … …  
    812812.make-welcome .entry-meta [type="button"]:focus {
    813813        outline: thin dotted;
     814}
     815
     816.make-welcome .hidden {
     817        display: none;
    814818}
    815819
Note: See TracChangeset for help on using the changeset viewer.