Customiser: Prevent JS errors when previewing pages with an <area> tag.

The customiser assumes that `<area>` tags will have a `href` attribute, which isn't necessarily true. Now it checks instead of assuming.

Props janthiel, adamsilverstein.
Fixes #45053.


Built from https://develop.svn.wordpress.org/trunk@44684


git-svn-id: http://core.svn.wordpress.org/trunk@44515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2019-01-21 23:03:50 +00:00
parent 64877e74e8
commit faf1528d8f
3 changed files with 10 additions and 5 deletions

View File

@ -237,7 +237,7 @@
* @returns {void}
*/
api.addLinkPreviewing = function addLinkPreviewing() {
var linkSelectors = 'a[href], area';
var linkSelectors = 'a[href], area[href]';
// Inject links into initial document.
$( document.body ).find( linkSelectors ).each( function() {
@ -337,6 +337,11 @@
api.prepareLinkPreview = function prepareLinkPreview( element ) {
var queryParams, $element = $( element );
// Skip elements with no href attribute. Check first to avoid more expensive checks down the road
if ( ! element.hasAttribute( 'href' ) ) {
return;
}
// Skip links in admin bar.
if ( $element.closest( '#wpadminbar' ).length ) {
return;
@ -776,7 +781,7 @@
api.settings.changeset.uuid = uuid;
// Update UUIDs in links and forms.
$( document.body ).find( 'a[href], area' ).each( function() {
$( document.body ).find( 'a[href], area[href]' ).each( function() {
api.prepareLinkPreview( this );
} );
$( document.body ).find( 'form' ).each( function() {
@ -810,7 +815,7 @@
api.settings.changeset.autosaved = true; // Start deferring to any autosave once changeset is updated.
$( document.body ).find( 'a[href], area' ).each( function() {
$( document.body ).find( 'a[href], area[href]' ).each( function() {
api.prepareLinkPreview( this );
} );
$( document.body ).find( 'form' ).each( function() {

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.1-beta1-44683';
$wp_version = '5.1-beta1-44684';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.