Text widget: add the Add Media button and enable the `wpview` plugin to show embedded media previews in the editor.

Props westonruter, azaozz.
See #40854.

git-svn-id: https://develop.svn.wordpress.org/trunk@41344 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2017-09-08 10:56:10 +00:00
parent da4dd8eb56
commit 085b1411bd
2 changed files with 40 additions and 3 deletions

View File

@ -562,18 +562,42 @@ window.wp = window.wp || {};
// Add wrap and the Visual|Text tabs.
if ( settings.tinymce && settings.quicktags ) {
var $textarea = $( '#' + id );
var $wrap = $( '<div>' ).attr( {
'class': 'wp-core-ui wp-editor-wrap tmce-active',
id: 'wp-' + id + '-wrap'
} );
var $editorContainer = $( '<div class="wp-editor-container">' );
var $button = $( '<button>' ).attr( {
type: 'button',
'data-wp-editor-id': id
} );
var $editorTools = $( '<div class="wp-editor-tools">' );
if ( settings.mediaButtons ) {
var buttonText = 'Add Media';
if ( window._wpMediaViewsL10n && window._wpMediaViewsL10n.addMedia ) {
buttonText = window._wpMediaViewsL10n.addMedia;
}
var $addMediaButton = $( '<button type="button" class="button insert-media add_media">' );
$addMediaButton.append( '<span class="wp-media-buttons-icon"></span>' );
$addMediaButton.append( document.createTextNode( ' ' + buttonText ) );
$addMediaButton.data( 'editor', id );
$editorTools.append(
$( '<div class="wp-media-buttons">' )
.append( $addMediaButton )
);
}
$wrap.append(
$( '<div class="wp-editor-tools">' )
$editorTools
.append( $( '<div class="wp-editor-tabs">' )
.append( $button.clone().attr({
id: id + '-tmce',

View File

@ -230,7 +230,8 @@ wp.textWidgets = ( function( $ ) {
// The user has disabled TinyMCE.
if ( typeof window.tinymce === 'undefined' ) {
wp.editor.initialize( id, {
quicktags: true
quicktags: true,
mediaButtons: true
});
return;
@ -242,11 +243,23 @@ wp.textWidgets = ( function( $ ) {
wp.editor.remove( id );
}
// Add or enable the `wpview` plugin.
$( document ).one( 'wp-before-tinymce-init.text-widget-init', function( event, init ) {
// If somebody has removed all plugins, they must have a good reason.
// Keep it that way.
if ( ! init.plugins ) {
return;
} else if ( ! /\bwpview\b/.test( init.plugins ) ) {
init.plugins += ',wpview';
}
} );
wp.editor.initialize( id, {
tinymce: {
wpautop: true
},
quicktags: true
quicktags: true,
mediaButtons: true
});
/**