From 89a70eb8594ce7e94a607d70351b10a1d25c32ff Mon Sep 17 00:00:00 2001 From: Joe McGill Date: Thu, 3 Nov 2016 01:21:28 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@39102 git-svn-id: http://core.svn.wordpress.org/trunk@39044 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-content/themes/twentyfourteen/js/functions.js | 11 ++++++----- wp-includes/js/wp-custom-header.js | 13 +++++++++---- wp-includes/js/wp-custom-header.min.js | 2 +- wp-includes/version.php | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/wp-content/themes/twentyfourteen/js/functions.js b/wp-content/themes/twentyfourteen/js/functions.js index 7efc7cf6b5..2b83db0b3c 100644 --- a/wp-content/themes/twentyfourteen/js/functions.js +++ b/wp-content/themes/twentyfourteen/js/functions.js @@ -105,11 +105,6 @@ if ( body.is( '.header-image' ) ) { - // Recaculate the header height when a custom header loads. - $( 'body' ).on( 'wp-custom-header-video-loaded', function() { - mastheadOffset = $( '#site-header' ).height(); - } ); - _window.on( 'scroll.twentyfourteen', function() { if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) { body.addClass( 'masthead-fixed' ); @@ -118,6 +113,12 @@ } } ); + // Update masthead offset once a custom header video loads. + $( document ).on( 'wp-custom-header-video-loaded', function() { + mastheadOffset = $( '#site-header' ).height(); + } ); + + // Update masthead offset after a selective refresh. if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) { wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() { diff --git a/wp-includes/js/wp-custom-header.js b/wp-includes/js/wp-custom-header.js index 80ebd917dc..08e24882fa 100644 --- a/wp-includes/js/wp-custom-header.js +++ b/wp-includes/js/wp-custom-header.js @@ -1,4 +1,4 @@ -(function( window, $, settings ) { +(function( window, settings ) { if ( ! ( 'addEventListener' in window ) ) { // Fail gracefully in unsupported browsers. @@ -31,11 +31,16 @@ if ( handlers.hasOwnProperty( id ) && handler.test( settings ) ) { handler.callback( settings ); + + // Set up and dispatch custom event when the video is loaded. + if ( 'dispatchEvent' in window ) { + var videoLoaded = new Event( 'wp-custom-header-video-loaded' ); + document.dispatchEvent( videoLoaded ); + } + break; } } - - $( 'body' ).trigger( 'wp-custom-header-video-loaded' ); } } @@ -151,4 +156,4 @@ }); } -})( window, jQuery, window._wpCustomHeaderSettings || {} ); +})( window, window._wpCustomHeaderSettings || {} ); diff --git a/wp-includes/js/wp-custom-header.min.js b/wp-includes/js/wp-custom-header.min.js index 751f1aff77..ad0169270e 100644 --- a/wp-includes/js/wp-custom-header.min.js +++ b/wp-includes/js/wp-custom-header.min.js @@ -1 +1 @@ -!function(a,b,c){function d(){function d(){if(c.container=document.getElementById("wp-custom-header"),g()){for(var a in h){var d=h[a];if(h.hasOwnProperty(a)&&d.test(c)){d.callback(c);break}}b("body").trigger("wp-custom-header-video-loaded")}}function g(){return!(a.innerWidth