Make WordPress Core


Ignore:
Timestamp:
03/22/2014 09:03:18 PM (11 years ago)
Author:
ocean90
Message:

Widget Customizer: Fix 'WidgetCustomizerPreview' is undefined error in IE8/9.

  • Move WidgetCustomizerPreview to wp.customize.WidgetCustomizerPreview
  • Move WidgetCustomizerPreview_exports to export_preview_data()
  • Use _wpWidgetCustomizerPreviewSettings to transfer settings to wp.customize.WidgetCustomizerPreview

see #27485.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r27652 r27653  
    697697    static function customize_preview_init() {
    698698        add_filter( 'sidebars_widgets', array( __CLASS__, 'preview_sidebars_widgets' ), 1 );
    699         add_action( 'wp_enqueue_scripts', array( __CLASS__, 'customize_preview_enqueue_deps' ) );
    700         add_action( 'wp_footer', array( __CLASS__, 'export_preview_data' ), 9999 );
     699        add_action( 'wp_enqueue_scripts', array( __CLASS__, 'customize_preview_enqueue' ) );
     700        add_action( 'wp_print_styles', array( __CLASS__, 'inject_preview_css' ), 1 );
     701        add_action( 'wp_footer', array( __CLASS__, 'export_preview_data' ), 20 );
    701702    }
    702703
     
    720721     * @action wp_enqueue_scripts
    721722     */
    722     static function customize_preview_enqueue_deps() {
     723    static function customize_preview_enqueue() {
    723724        wp_enqueue_script( 'customize-preview-widgets' );
    724 
    725         add_action( 'wp_print_styles', array( __CLASS__, 'inject_preview_css' ), 1 );
    726 
    727         // Why not wp_localize_script? Because we're not localizing, and it forces values into strings
    728         global $wp_scripts;
    729         $exports = array(
    730             'registered_sidebars' => array_values( $GLOBALS['wp_registered_sidebars'] ),
    731             'registered_widgets' => $GLOBALS['wp_registered_widgets'],
    732             'i18n' => array(
    733                 'widget_tooltip' => ( 'Shift-click to edit this widget.' ),
    734             ),
    735         );
    736         foreach ( $exports['registered_widgets'] as &$registered_widget ) {
    737             unset( $registered_widget['callback'] ); // may not be JSON-serializeable
    738         }
    739         $wp_scripts->add_data(
    740             'customize-preview-widgets',
    741             'data',
    742             sprintf( 'var WidgetCustomizerPreview_exports = %s;', json_encode( $exports ) )
    743         );
    744     }
     725        }
    745726
    746727    /**
     
    768749     */
    769750    static function export_preview_data() {
    770         wp_print_scripts( array( 'customize-preview-widgets' ) );
     751        // Prepare customizer settings to pass to Javascript.
     752        $settings = array(
     753            'renderedSidebars'   => array_fill_keys( array_unique( self::$rendered_sidebars ), true ),
     754            'renderedWidgets'    => array_fill_keys( array_keys( self::$rendered_widgets ), true ),
     755            'registeredSidebars' => array_values( $GLOBALS['wp_registered_sidebars'] ),
     756            'registeredWidgets'  => $GLOBALS['wp_registered_widgets'],
     757            'l10n'               => array(
     758                'widgetTooltip' => ( 'Shift-click to edit this widget.' ),
     759            ),
     760        );
     761        foreach ( $settings['registeredWidgets'] as &$registered_widget ) {
     762            unset( $registered_widget['callback'] ); // may not be JSON-serializeable
     763        }
     764
    771765        ?>
    772         <script>
    773         (function () {
    774             /*global WidgetCustomizerPreview */
    775             WidgetCustomizerPreview.rendered_sidebars = <?php echo json_encode( array_fill_keys( array_unique( self::$rendered_sidebars ), true ) ) ?>;
    776             WidgetCustomizerPreview.rendered_widgets = <?php echo json_encode( array_fill_keys( array_keys( self::$rendered_widgets ), true ) ); ?>;
    777         }());
     766        <script type="text/javascript">
     767            var _wpWidgetCustomizerPreviewSettings = <?php echo json_encode( $settings ); ?>;
    778768        </script>
    779769        <?php
Note: See TracChangeset for help on using the changeset viewer.