Make WordPress Core

Changeset 30306


Ignore:
Timestamp:
11/11/2014 10:28:38 PM (10 years ago)
Author:
ocean90
Message:

Customizer: When navigating around the site within the Customizer preview, update the document title.

props westonruter.
fixes #28542.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/customize.php

    r30164 r30306  
    7777$is_ios = wp_is_mobile() && preg_match( '/iPad|iPod|iPhone/', $_SERVER['HTTP_USER_AGENT'] );
    7878
    79 if ( $is_ios )
     79if ( $is_ios ) {
    8080    $body_class .= ' ios';
    81 
    82 if ( is_rtl() )
    83     $body_class .=  ' rtl';
     81}
     82
     83if ( is_rtl() ) {
     84    $body_class .= ' rtl';
     85}
    8486$body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
    8587
    86 $admin_title = sprintf( __( '%1$s — WordPress' ), strip_tags( sprintf( __( 'Customize %s' ), $wp_customize->theme()->display('Name') ) ) );
     88if ( $wp_customize->is_theme_active() ) {
     89    $document_title_tmpl = _x( 'Customize: %s', 'Placeholder is the document title from the preview' );
     90} else {
     91    $document_title_tmpl = _x( 'Live Preview: %s', 'Placeholder is the document title from the preview' );
     92}
     93$document_title_tmpl = html_entity_decode( $document_title_tmpl, ENT_QUOTES, 'UTF-8' ); // because exported to JS and assigned to document.title
     94$admin_title = sprintf( $document_title_tmpl, __( 'Loading…' ) );
     95
    8796?><title><?php echo $admin_title; ?></title>
    8897
     
    254263        ),
    255264        'autofocus' => array(),
     265        'documentTitleTmpl' => $document_title_tmpl,
    256266    );
    257267
  • trunk/src/wp-admin/js/customize-controls.js

    r30214 r30306  
    15011501
    15021502    /**
     1503     * Set the document title of the customizer
     1504     *
     1505     * @param {string} documentTitle
     1506     */
     1507    api.setDocumentTitle = function ( documentTitle ) {
     1508        var tmpl, title;
     1509        tmpl = api.settings.documentTitleTmpl;
     1510        title = tmpl.replace( '%s', documentTitle );
     1511        document.title = title;
     1512        if ( window !== window.parent ) {
     1513            window.parent.document.title = document.title;
     1514        }
     1515    };
     1516
     1517    /**
    15031518     * @constructor
    15041519     * @augments wp.customize.Messenger
     
    16181633            // Update the URL when the iframe sends a URL message.
    16191634            this.bind( 'url', this.previewUrl );
     1635
     1636            // Update the document title when the preview changes
     1637            this.bind( 'documentTitle', function ( title ) {
     1638                api.setDocumentTitle( title );
     1639            } );
    16201640        },
    16211641
  • trunk/src/wp-includes/js/customize-loader.js

    r29903 r30306  
    7979            }
    8080
    81             if ( ! hash && ! $.support.history ){
     81            if ( ! hash && ! $.support.history ) {
    8282                Loader.close();
    8383            }
     
    105105                return window.location = src;
    106106            }
     107
     108            // Store the document title prior to opening the Live Preview
     109            this.originalDocumentTitle = document.title;
    107110
    108111            this.active = true;
     
    135138                    Loader.close();
    136139                }
    137             } );
     140            });
    138141
    139142            // Prompt AYS dialog when navigating away
     
    159162
    160163        pushState: function ( src ) {
    161             var hash;
     164            var hash = src.split( '?' )[1];
    162165
    163166            // Ensure we don't call pushState if the user hit the forward button.
     
    165168                history.pushState( { customize: src }, '', src );
    166169            } else if ( ! $.support.history && $.support.hashchange && hash ) {
    167                 hash = src.split( '?' )[1];
    168170                window.location.hash = 'wp_customize=on&' + hash;
    169171            }
     172
     173            this.trigger( 'open' );
    170174        },
    171175
     
    195199
    196200            this.trigger( 'close' );
     201
     202            // Restore document title prior to opening the Live Preview
     203            if ( this.originalDocumentTitle ) {
     204                document.title = this.originalDocumentTitle;
     205            }
    197206
    198207            // Return focus to link that was originally clicked.
  • trunk/src/wp-includes/js/customize-preview.js

    r30102 r30306  
    102102        });
    103103
    104         preview.bind( 'active', function() {
    105             if ( api.settings.nonce )
    106                 preview.send( 'nonce', api.settings.nonce );
    107         });
     104        preview.bind( 'active', function() {
     105            if ( api.settings.nonce ) {
     106                preview.send( 'nonce', api.settings.nonce );
     107            }
     108
     109            preview.send( 'documentTitle', document.title );
     110        });
    108111
    109112        preview.send( 'ready', {
Note: See TracChangeset for help on using the changeset viewer.