From 5e77c07a2e2afbfcf46d0ad2edfa39832e85ead5 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Mon, 21 Jan 2019 23:02:39 +0000 Subject: [PATCH] Customiser: Prevent JS errors when previewing pages with an `` tag. The customiser assumes that `` tags will have a `href` attribute, which isn't necessarily true. Now it checks instead of assuming. Props janthiel, adamsilverstein. Fixes #45053. git-svn-id: https://develop.svn.wordpress.org/trunk@44684 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/wp/customize/preview.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/js/_enqueues/wp/customize/preview.js b/src/js/_enqueues/wp/customize/preview.js index e8f7d041c0..9bbbf2a084 100644 --- a/src/js/_enqueues/wp/customize/preview.js +++ b/src/js/_enqueues/wp/customize/preview.js @@ -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() {