From ce9e48622abbb280d0eef871a6e304cfe9c83312 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Tue, 21 Feb 2017 06:55:18 +0000 Subject: [PATCH] Customize: Skip intercepting non-HTTP(S) links in customizer preview just as jump links are ignored. Ensures that links with `javascript:`, `mailto:` and other protocols work as expected in the customizer preview. Props westonruter. Merges [40064] to the 4.7 branch. Fixes #39797. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@40096 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/customize-preview.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/js/customize-preview.js b/src/wp-includes/js/customize-preview.js index f51c45ff98..d95f804bcd 100644 --- a/src/wp-includes/js/customize-preview.js +++ b/src/wp-includes/js/customize-preview.js @@ -145,10 +145,9 @@ return; } + // Allow internal jump links and JS links to behave normally without preventing default. isInternalJumpLink = ( '#' === link.attr( 'href' ).substr( 0, 1 ) ); - - // Allow internal jump links to behave normally without preventing default. - if ( isInternalJumpLink ) { + if ( isInternalJumpLink || ! /^https?:$/.test( link.prop( 'protocol' ) ) ) { return; } @@ -334,8 +333,8 @@ return; } - // Ignore links with href="#" or href="#id". - if ( '#' === $( element ).attr( 'href' ).substr( 0, 1 ) ) { + // Ignore links with href="#", href="#id", or non-HTTP protocols (e.g. javascript: and mailto:). + if ( '#' === $( element ).attr( 'href' ).substr( 0, 1 ) || ! /^https?:$/.test( element.protocol ) ) { return; }