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.
Built from https://develop.svn.wordpress.org/trunk@40019


git-svn-id: http://core.svn.wordpress.org/trunk@39956 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2017-01-27 04:25:44 +00:00
parent b6281dbd75
commit 69c29935d5
8 changed files with 41 additions and 35 deletions

View File

@ -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( '%<link [^>]*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'] = '<script src="' . $script_src . '"></script>';
$return['sandbox'] = true;
}
wp_send_json_success( $return );
}
/**

View File

@ -417,7 +417,6 @@ final class _WP_Editors {
'wpdialogs',
'wptextpattern',
'wpview',
'wpembed',
);
if ( ! self::$has_medialib ) {

View File

@ -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( '<script' ) !== -1 ) {
if ( _.isObject( content ) && ( content.sandbox || content.head || content.body.indexOf( '<script' ) !== -1 ) ) {
this.setIframes( content.head || '', content.body, callback, rendered );
} else if ( _.isString( content ) && content.indexOf( '<script' ) !== -1 ) {
this.setIframes( '', content, callback, rendered );
@ -584,6 +584,9 @@
'display: none;' +
'content: "";' +
'}' +
'iframe {' +
'max-width: 100%;' +
'}' +
'</style>' +
'</head>' +
'<body id="wpview-iframe-sandbox" class="' + bodyClasses + '">' +
@ -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 );

File diff suppressed because one or more lines are too long

View File

@ -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 );

View File

@ -1 +0,0 @@
!function(a){"use strict";a.PluginManager.add("wpembed",function(a,b){a.on("init",function(){var c=a.dom.uniqueId(),d=a.dom.create("script",{id:c,type:"text/javascript",src:b+"/../../../wp-embed.js"});a.getDoc().getElementsByTagName("head")[0].appendChild(d)})})}(window.tinymce);

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-alpha-39994';
$wp_version = '4.8-alpha-40019';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.