wp/wp-includes/js/customize-preview.js
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
--- a/wp/wp-includes/js/customize-preview.js	Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-includes/js/customize-preview.js	Mon Oct 14 18:28:13 2019 +0200
@@ -1,5 +1,7 @@
 /*
  * Script run inside a Customizer preview frame.
+ *
+ * @output wp-includes/js/customize-preview.js
  */
 (function( exports, $ ){
 	var api = wp.customize,
@@ -235,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() {
@@ -335,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;
@@ -377,11 +384,6 @@
 			queryParams.customize_messenger_channel = api.settings.channel;
 		}
 		element.search = $.param( queryParams );
-
-		// Prevent links from breaking out of preview iframe.
-		if ( api.settings.channel ) {
-			element.target = '_self';
-		}
 	};
 
 	/**
@@ -779,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() {
@@ -813,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() {