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.

git-svn-id: https://develop.svn.wordpress.org/trunk@39102 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe McGill
2016-11-03 01:20:14 +00:00
parent c962a98980
commit 22bb12dd61
2 changed files with 15 additions and 9 deletions
+9 -4
View File
@@ -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 || {} );