WordPress.org

Make WordPress Core

Changeset 44684


Ignore:
Timestamp:
01/21/2019 11:02:39 PM (4 weeks ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/wp/customize/preview.js

    r44583 r44684  
    238238     */
    239239    api.addLinkPreviewing = function addLinkPreviewing() {
    240         var linkSelectors = 'a[href], area';
     240        var linkSelectors = 'a[href], area[href]';
    241241
    242242        // Inject links into initial document.
     
    337337    api.prepareLinkPreview = function prepareLinkPreview( element ) {
    338338        var queryParams, $element = $( element );
     339
     340        // Skip elements with no href attribute. Check first to avoid more expensive checks down the road
     341        if ( ! element.hasAttribute( 'href' ) ) {
     342            return;
     343        }
    339344
    340345        // Skip links in admin bar.
     
    777782
    778783            // Update UUIDs in links and forms.
    779             $( document.body ).find( 'a[href], area' ).each( function() {
     784            $( document.body ).find( 'a[href], area[href]' ).each( function() {
    780785                api.prepareLinkPreview( this );
    781786            } );
     
    811816            api.settings.changeset.autosaved = true; // Start deferring to any autosave once changeset is updated.
    812817
    813             $( document.body ).find( 'a[href], area' ).each( function() {
     818            $( document.body ).find( 'a[href], area[href]' ).each( function() {
    814819                api.prepareLinkPreview( this );
    815820            } );
Note: See TracChangeset for help on using the changeset viewer.