WordPress.org

Make WordPress Core

Changeset 20893


Ignore:
Timestamp:
05/25/2012 12:15:12 AM (7 years ago)
Author:
koopersmith
Message:

Theme Customizer: Add CORS checks to the initial check for customize support. Prevents flash of customize links on large pages. see #20582, #19910.

Add wp_customize_support_script(), to quickly alter the body class based on whether customize is supported.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-header.php

    r20845 r20893  
    9898<script type="text/javascript">
    9999    document.body.className = document.body.className.replace('no-js','js');
    100 <?php
    101 // If the customize loader is enqueued, then add the 'customize-support' class early.
    102 // This prevents a flash of unstyled content.
    103 if ( wp_script_is( 'customize-loader', 'queue' ) ) : ?>
    104     if ( window.postMessage )
    105         document.body.className = document.body.className.replace('no-customize-support','customize-support');
    106 <?php endif; ?>
    107100</script>
     101
     102<?php wp_customize_support_script(); ?>
    108103
    109104<div id="wpwrap">
  • trunk/wp-includes/theme.php

    r20890 r20893  
    16191619    return esc_url( admin_url( 'customize.php' ) . '?theme=' . $stylesheet );
    16201620}
     1621
     1622/**
     1623 * Prints a script to check whether or not the customizer is supported,
     1624 * and apply either the no-customize-support or customize-support class
     1625 * to the body.
     1626 *
     1627 * This function MUST be called inside the body tag.
     1628 *
     1629 * Ideally, call this function immediately after the body tag is opened.
     1630 * This prevents a flash of unstyled content.
     1631 *
     1632 * It is also recommended that you add the "no-customize-support" class
     1633 * to the body tag by default.
     1634 *
     1635 * @since 3.4.0
     1636 */
     1637function wp_customize_support_script() {
     1638    if ( ! wp_script_is( 'customize-loader', 'queue' ) )
     1639        return;
     1640
     1641    $admin_origin = parse_url( admin_url() );
     1642    $home_origin  = parse_url( home_url() );
     1643    $cross_domain = ( strtolower( $admin_origin[ 'host' ] ) != strtolower( $home_origin[ 'host' ] ) );
     1644
     1645    ?>
     1646    <script type="text/javascript">
     1647        (function() {
     1648            var request, b = document.body, c = 'className', cs = 'customize-support', rcs = new RegExp('(^|\\s+)(no-)?'+cs+'(\\s+|$)');
     1649
     1650<?php       if ( $cross_domain ): ?>
     1651            request = (function(){ var xhr = new XMLHttpRequest(); return ('withCredentials' in xhr); })();
     1652<?php       else: ?>
     1653            request = true;
     1654<?php       endif; ?>
     1655
     1656            b[c] = b[c].replace( rcs, '' );
     1657            b[c] += ( window.postMessage && request ? ' ' : ' no-' ) + cs;
     1658        }());
     1659    </script>
     1660    <?php
     1661}
Note: See TracChangeset for help on using the changeset viewer.