Make WordPress Core

Changeset 20488


Ignore:
Timestamp:
04/16/2012 11:07:23 PM (14 years ago)
Author:
koopersmith
Message:

Theme Customizer: Integrate with browser history. Use window.history by default, with window.onhashchange as a fallback. fixes #20337, see #19910.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/customize-loader.dev.js

    r20476 r20488  
    77
    88        Loader = {
     9                supports: {
     10                        history:  !! ( window.history && history.pushState ),
     11                        hashchange: ('onhashchange' in window) && (document.documentMode === undefined || document.documentMode > 7)
     12                },
     13
    914                initialize: function() {
    10                         this.body      = $( document.body ).addClass('customize-support');
    11                         this.element   = $( '<div id="customize-container" class="wp-full-overlay" />' ).appendTo( this.body );
     15                        this.body    = $( document.body ).addClass('customize-support');
     16                        this.window  = $( window );
     17                        this.element = $( '<div id="customize-container" class="wp-full-overlay" />' ).appendTo( this.body );
    1218
    1319                        $('#wpbody').on( 'click', '.load-customize', function( event ) {
     
    1723                                Loader.open( $(this).attr('href') );
    1824                        });
     25
     26                        // Add navigation listeners.
     27                        if ( this.supports.history )
     28                                this.window.on( 'popstate', Loader.popstate );
     29
     30                        if ( this.supports.hashchange )
     31                                this.window.on( 'hashchange', Loader.hashchange );
     32                },
     33                popstate: function( e ) {
     34                        var state = e.originalEvent.state;
     35                        if ( state && state.customize )
     36                                Loader.open( state.customize );
     37                        else if ( Loader.active )
     38                                Loader.close();
     39                },
     40                hashchange: function( e ) {
     41                        var hash = window.location.toString().split('#')[1];
     42
     43                        if ( hash && 0 === hash.indexOf( 'customize=on' ) )
     44                                Loader.open( wpCustomizeLoaderL10n.url + '?' + hash );
     45
     46                        if ( ! hash )
     47                                Loader.close();
    1948                },
    2049                open: function( src ) {
     50                        if ( this.active )
     51                                return;
     52                        this.active = true;
     53
    2154                        this.iframe = $( '<iframe />', { src: src }).appendTo( this.element );
    2255
     
    3063
    3164                        this.messenger.bind( 'close', function() {
    32                                 Loader.close();
     65                                if ( Loader.supports.history )
     66                                        history.back();
     67                                else if ( Loader.supports.hashchange )
     68                                        window.location.hash = '';
     69                                else
     70                                        Loader.close();
    3371                        });
    3472
    3573                        this.element.fadeIn( 200, function() {
     74                                var hash = src.split('?')[1];
     75
    3676                                Loader.body.addClass( 'customize-active full-overlay-active' );
     77
     78                                // Ensure we don't call pushState if the user hit the forward button.
     79                                if ( Loader.supports.history && window.location.href !== src )
     80                                        history.pushState( { customize: src }, '', src );
     81                                else if ( Loader.supports.hashchange && hash )
     82                                        window.location.hash = hash;
    3783                        });
    3884                },
    3985                close: function() {
     86                        if ( ! this.active )
     87                                return;
     88                        this.active = false;
     89
    4090                        this.element.fadeOut( 200, function() {
    4191                                Loader.iframe.remove();
     
    4898
    4999        $( function() {
    50                 if ( !! window.postMessage )
     100                if ( window.postMessage )
    51101                        Loader.initialize();
    52102        });
  • trunk/wp-includes/theme.php

    r20477 r20488  
    15911591        wp_localize_script( 'customize-loader', 'wpCustomizeLoaderL10n', array(
    15921592                'back' => sprintf( __( '&larr; Return to %s' ), get_admin_page_title() ),
     1593                'url'  => admin_url( 'admin.php' ),
    15931594        ) );
    15941595}
Note: See TracChangeset for help on using the changeset viewer.