From 1a068f2a619719b2d216577300181744de45dc79 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 27 Jan 2017 04:24:58 +0000 Subject: [PATCH] TinyMCE: improve the previews for embedded WordPress posts: - Add option to force a sandbox iframe in wpview. - Use it to show the embedded post preview. - Remove the deprecated `wpembed` plugin.js Fixes #39513. git-svn-id: https://develop.svn.wordpress.org/trunk@40019 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 18 ++++++++-- src/wp-includes/class-wp-editor.php | 1 - src/wp-includes/js/mce-view.js | 35 +++++++++++++------ .../js/tinymce/plugins/wpembed/plugin.js | 17 --------- 4 files changed, 39 insertions(+), 32 deletions(-) delete mode 100644 src/wp-includes/js/tinymce/plugins/wpembed/plugin.js diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 1226a9e53e..20ef07e2ac 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3004,7 +3004,6 @@ function wp_ajax_parse_embed() { $parsed = $styles . $html . $scripts; } - if ( ! empty( $no_ssl_support ) || ( is_ssl() && ( preg_match( '%<(iframe|script|embed) [^>]*src="http://%', $parsed ) || preg_match( '%]*href="http://%', $parsed ) ) ) ) { // Admin is ssl and the embed is not. Iframes, scripts, and other "active content" will be blocked. @@ -3014,10 +3013,23 @@ function wp_ajax_parse_embed() { ) ); } - wp_send_json_success( array( + $return = array( 'body' => $parsed, 'attr' => $wp_embed->last_attr - ) ); + ); + + if ( strpos( $parsed, 'class="wp-embedded-content' ) ) { + if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { + $script_src = includes_url( 'js/wp-embed.js' ); + } else { + $script_src = includes_url( 'js/wp-embed.min.js' ); + } + + $return['head'] = ''; + $return['sandbox'] = true; + } + + wp_send_json_success( $return ); } /** diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index 1d2c75c113..83777cfd8c 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/wp-includes/class-wp-editor.php @@ -417,7 +417,6 @@ final class _WP_Editors { 'wpdialogs', 'wptextpattern', 'wpview', - 'wpembed', ); if ( ! self::$has_medialib ) { diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index 16d860d470..21b2c87b6a 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -468,7 +468,7 @@ * @param {Boolean} rendered Only set for (un)rendered nodes. Optional. */ setContent: function( content, callback, rendered ) { - if ( _.isObject( content ) && content.body.indexOf( '' + '' + '' + @@ -623,10 +626,22 @@ } function reload() { - $( node ).data( 'rendered', null ); + if ( ! editor.isHidden() ) { + $( node ).data( 'rendered', null ); - setTimeout( function() { - wp.mce.views.render(); + setTimeout( function() { + wp.mce.views.render(); + } ); + } + } + + function addObserver() { + observer = new MutationObserver( _.debounce( resize, 100 ) ); + + observer.observe( iframeDoc.body, { + attributes: true, + childList: true, + subtree: true } ); } @@ -635,13 +650,11 @@ MutationObserver = iframeWin.MutationObserver || iframeWin.WebKitMutationObserver || iframeWin.MozMutationObserver; if ( MutationObserver ) { - observer = new MutationObserver( _.debounce( resize, 100 ) ); - - observer.observe( iframeDoc.body, { - attributes: true, - childList: true, - subtree: true - } ); + if ( ! iframeDoc.body ) { + iframeDoc.addEventListener( 'DOMContentLoaded', addObserver, false ); + } else { + addObserver(); + } } else { for ( i = 1; i < 6; i++ ) { setTimeout( resize, i * 700 ); diff --git a/src/wp-includes/js/tinymce/plugins/wpembed/plugin.js b/src/wp-includes/js/tinymce/plugins/wpembed/plugin.js deleted file mode 100644 index b6efbc95bf..0000000000 --- a/src/wp-includes/js/tinymce/plugins/wpembed/plugin.js +++ /dev/null @@ -1,17 +0,0 @@ -(function ( tinymce ) { - 'use strict'; - - tinymce.PluginManager.add( 'wpembed', function ( editor, url ) { - editor.on( 'init', function () { - var scriptId = editor.dom.uniqueId(); - - var scriptElm = editor.dom.create( 'script', { - id: scriptId, - type: 'text/javascript', - src: url + '/../../../wp-embed.js' - } ); - - editor.getDoc().getElementsByTagName( 'head' )[ 0 ].appendChild( scriptElm ); - } ); - } ); -})( window.tinymce );