Make WordPress Core

Ticket #23225: class-wp-customize-manager.php.patch

File class-wp-customize-manager.php.patch, 1.7 KB (added by deltafactory, 12 years ago)

Customizer patch remaps A tags that start with # to behave as intended.

  • class-wp-customize-manager.php

     
    333333                add_action( 'wp_head', array( $this, 'customize_preview_base' ) );
    334334                add_action( 'wp_head', array( $this, 'customize_preview_html5' ) );
    335335                add_action( 'wp_footer', array( $this, 'customize_preview_settings' ), 20 );
     336                add_action( 'wp_footer', array( $this, 'customize_preview_base_hash_url_fix' ), 20 );
    336337                add_action( 'shutdown', array( $this, 'customize_preview_signature' ), 1000 );
    337338                add_filter( 'wp_die_handler', array( $this, 'remove_preview_signature' ) );
    338339
     
    349350         * @since 3.4.0
    350351         */
    351352        public function customize_preview_base() {
    352                 ?><base href="<?php echo home_url( '/' ); ?>" /><?php
     353                ?><base id="wp-customize-preview-base" href="<?php echo home_url( '/' ); ?>" /><?php
    353354        }
    354355
    355356        /**
     357         * Print script to allow hash URLs to work as expected
     358         *
     359         * @since 3.8
     360         */
     361        public function customize_preview_base_hash_url_fix() {
     362                ?><script>(function(){
     363                        var wp_base = document.getElementById( 'wp-customize-preview-base' ),
     364                                a_tags = document.getElementsByTagName( 'a' ),
     365                                i, j, a_tag, attr;
     366
     367                        if ( wp_base ) {
     368                                for ( i = 0; i < a_tags.length; i++ ) {
     369                                        a_tag = a_tags[i];
     370                                        for ( j = 0; j < a_tag.attributes.length; j++ ) {
     371                                                attr = a_tag.attributes[j];
     372                                                if ( attr.nodeName === 'href' && attr.nodeValue.charAt(0) === '#' ) {
     373                                                        attr.nodeValue = document.location.href + attr.nodeValue;
     374                                                }
     375                                        }
     376                                }
     377                        }
     378
     379                })();
     380                </script><?php
     381        }
     382
     383        /**
    356384         * Print a workaround to handle HTML5 tags in IE < 9
    357385         *
    358386         * @since 3.4.0