From fe824ee872dc1fb71095f55413aafcee3fe9955c Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 23 Feb 2016 17:15:23 +0000 Subject: [PATCH] Embeds: Make the click event handler work for dynamically added links. Props JamesDiGioia. Fixes #35630. git-svn-id: https://develop.svn.wordpress.org/trunk@36637 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/wp-embed-template.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/js/wp-embed-template.js b/src/wp-includes/js/wp-embed-template.js index ddcad26786..60ea47d387 100644 --- a/src/wp-includes/js/wp-embed-template.js +++ b/src/wp-includes/js/wp-embed-template.js @@ -26,7 +26,6 @@ share_dialog_close = document.querySelector( '.wp-embed-share-dialog-close' ), share_input = document.querySelectorAll( '.wp-embed-share-input' ), share_dialog_tabs = document.querySelectorAll( '.wp-embed-share-tab-button button' ), - links = document.getElementsByTagName( 'a' ), i; if ( share_input ) { @@ -154,13 +153,13 @@ /** * Send link target to the parent (embedding) site. */ - sendEmbedMessage( 'link', href ); - e.preventDefault(); + if ( href ) { + sendEmbedMessage( 'link', href ); + e.preventDefault(); + } } - for ( i = 0; i < links.length; i++ ) { - links[ i ].addEventListener( 'click', linkClickHandler ); - } + document.addEventListener( 'click', linkClickHandler ); } /**