Make WordPress Core

Changeset 39102


Ignore:
Timestamp:
11/03/2016 01:20:14 AM (10 years ago)
Author:
joemcgill
Message:

Themes: Remove jQuery dependency from wp-custom-header.js.

In [38985], we used jQuery to trigger a custom event once a video
handler has completed so themes, like Twenty Fourteen, can execute
their own adjustments after the header video has loaded.

This replaces the jQuery trigger() method with a native event and
updates Twenty Fourteen accordingly.

Props adamsilverstein, joemcgill.
Fixes #38550.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyfourteen/js/functions.js

    r38985 r39102  
    106106                        if ( body.is( '.header-image' ) ) {
    107107
    108                                 // Recaculate the header height when a custom header loads.
    109                                 $( 'body' ).on( 'wp-custom-header-video-loaded', function() {
    110                                         mastheadOffset = $( '#site-header' ).height();
    111                                 } );
    112 
    113108                                _window.on( 'scroll.twentyfourteen', function() {
    114109                                        if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) {
    … …  
    118113                                        }
    119114                                } );
     115
     116                                // Update masthead offset once a custom header video loads.
     117                                $( document ).on( 'wp-custom-header-video-loaded', function() {
     118                                        mastheadOffset = $( '#site-header' ).height();
     119                                } );
     120
    120121
    121122                                // Update masthead offset after a selective refresh.
  • trunk/src/wp-includes/js/wp-custom-header.js

    r39050 r39102  
    1 (function( window, $, settings ) {
     1(function( window, settings ) {
    22
    33        if ( ! ( 'addEventListener' in window ) ) {
    … …  
    3232                                        if ( handlers.hasOwnProperty( id ) && handler.test( settings ) ) {
    3333                                                handler.callback( settings );
     34
     35                                                // Set up and dispatch custom event when the video is loaded.
     36                                                if ( 'dispatchEvent' in window ) {
     37                                                        var videoLoaded = new Event( 'wp-custom-header-video-loaded' );
     38                                                        document.dispatchEvent( videoLoaded );
     39                                                }
     40
    3441                                                break;
    3542                                        }
    3643                                }
    37 
    38                                 $( 'body' ).trigger( 'wp-custom-header-video-loaded' );
    3944                        }
    4045                }
    … …  
    152157        }
    153158
    154 })( window, jQuery, window._wpCustomHeaderSettings || {} );
     159})( window, window._wpCustomHeaderSettings || {} );
Note: See TracChangeset for help on using the changeset viewer.