From c7e05dafbe2266d6a9705dc5b41ee06a01ea5151 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Thu, 19 Nov 2015 23:05:39 +0000 Subject: [PATCH] Embeds: Remove `&` characters from the inline embed JS. Older versions of WordPress will convert those `&` characters to `&`, which makes for some non-functional JS. If folks are running an older release, let's not make their lives more difficult than it already is. Props pento, peterwilsoncc. See #34698. git-svn-id: https://develop.svn.wordpress.org/trunk@35708 602fd350-edb4-49c9-b593-d223f7449a82 --- Gruntfile.js | 16 +++++++++++++++- src/wp-includes/js/wp-embed.js | 28 +++++++++++++++++++--------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 58f7e211b9..9e377a0565 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -435,9 +435,22 @@ module.exports = function(grunt) { '!wp-includes/js/masonry.min.js', '!wp-includes/js/swfobject.js', '!wp-includes/js/underscore.*', - '!wp-includes/js/zxcvbn.min.js' + '!wp-includes/js/zxcvbn.min.js', + '!wp-includes/js/wp-embed.js' // We have extra options for this, see uglify:embed ] }, + embed: { + options: { + compress: { + conditionals: false + } + }, + expand: true, + cwd: SOURCE_DIR, + dest: BUILD_DIR, + ext: '.min.js', + src: ['wp-includes/js/wp-embed.js'] + }, media: { expand: true, cwd: SOURCE_DIR, @@ -647,6 +660,7 @@ module.exports = function(grunt) { 'cssmin:rtl', 'cssmin:colors', 'uglify:core', + 'uglify:embed', 'uglify:jqueryui', 'concat:tinymce', 'compress:tinymce', diff --git a/src/wp-includes/js/wp-embed.js b/src/wp-includes/js/wp-embed.js index 8223102381..50471c714b 100644 --- a/src/wp-includes/js/wp-embed.js +++ b/src/wp-includes/js/wp-embed.js @@ -1,9 +1,15 @@ (function ( window, document ) { 'use strict'; - var supportedBrowser = ( document.querySelector && window.addEventListener ), + var supportedBrowser = false, loaded = false; + if ( document.querySelector ) { + if ( window.addEventListener ) { + supportedBrowser = true; + } + } + window.wp = window.wp || {}; if ( !! window.wp.receiveEmbedMessage ) { @@ -50,8 +56,10 @@ targetURL.href = data.value; /* Only continue if link hostname matches iframe's hostname. */ - if ( targetURL.host === sourceURL.host && document.activeElement === source ) { - window.top.location.href = data.value; + if ( targetURL.host === sourceURL.host ) { + if ( document.activeElement === source ) { + window.top.location.href = data.value; + } } } } @@ -77,15 +85,17 @@ source = iframes[ i ]; source.style.display = ''; - if ( !source.getAttribute( 'data-secret' ) ) { - /* Add secret to iframe */ - secret = Math.random().toString( 36 ).substr( 2, 10 ); - source.src += '#?secret=' + secret; - source.setAttribute( 'data-secret', secret ); + if ( source.getAttribute( 'data-secret' ) ) { + continue; } + /* Add secret to iframe */ + secret = Math.random().toString( 36 ).substr( 2, 10 ); + source.src += '#?secret=' + secret; + source.setAttribute( 'data-secret', secret ); + /* Remove security attribute from iframes in IE10 and IE11. */ - if ( ( isIE10 || isIE11 ) && !!source.getAttribute( 'security' ) ) { + if ( ( isIE10 || isIE11 ) ) { iframeClone = source.cloneNode( true ); iframeClone.removeAttribute( 'security' ); source.parentNode.replaceChild( iframeClone, source );