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. Built from https://develop.svn.wordpress.org/trunk@41344 git-svn-id: http://core.svn.wordpress.org/trunk@41177 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8cfe233137
commit
ffa304135e
|
@ -562,18 +562,42 @@ window.wp = window.wp || {};
|
||||||
// Add wrap and the Visual|Text tabs.
|
// Add wrap and the Visual|Text tabs.
|
||||||
if ( settings.tinymce && settings.quicktags ) {
|
if ( settings.tinymce && settings.quicktags ) {
|
||||||
var $textarea = $( '#' + id );
|
var $textarea = $( '#' + id );
|
||||||
|
|
||||||
var $wrap = $( '<div>' ).attr( {
|
var $wrap = $( '<div>' ).attr( {
|
||||||
'class': 'wp-core-ui wp-editor-wrap tmce-active',
|
'class': 'wp-core-ui wp-editor-wrap tmce-active',
|
||||||
id: 'wp-' + id + '-wrap'
|
id: 'wp-' + id + '-wrap'
|
||||||
} );
|
} );
|
||||||
|
|
||||||
var $editorContainer = $( '<div class="wp-editor-container">' );
|
var $editorContainer = $( '<div class="wp-editor-container">' );
|
||||||
|
|
||||||
var $button = $( '<button>' ).attr( {
|
var $button = $( '<button>' ).attr( {
|
||||||
type: 'button',
|
type: 'button',
|
||||||
'data-wp-editor-id': id
|
'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(
|
$wrap.append(
|
||||||
$( '<div class="wp-editor-tools">' )
|
$editorTools
|
||||||
.append( $( '<div class="wp-editor-tabs">' )
|
.append( $( '<div class="wp-editor-tabs">' )
|
||||||
.append( $button.clone().attr({
|
.append( $button.clone().attr({
|
||||||
id: id + '-tmce',
|
id: id + '-tmce',
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -230,7 +230,8 @@ wp.textWidgets = ( function( $ ) {
|
||||||
// The user has disabled TinyMCE.
|
// The user has disabled TinyMCE.
|
||||||
if ( typeof window.tinymce === 'undefined' ) {
|
if ( typeof window.tinymce === 'undefined' ) {
|
||||||
wp.editor.initialize( id, {
|
wp.editor.initialize( id, {
|
||||||
quicktags: true
|
quicktags: true,
|
||||||
|
mediaButtons: true
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -242,11 +243,23 @@ wp.textWidgets = ( function( $ ) {
|
||||||
wp.editor.remove( id );
|
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, {
|
wp.editor.initialize( id, {
|
||||||
tinymce: {
|
tinymce: {
|
||||||
wpautop: true
|
wpautop: true
|
||||||
},
|
},
|
||||||
quicktags: true
|
quicktags: true,
|
||||||
|
mediaButtons: true
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.9-alpha-41343';
|
$wp_version = '4.9-alpha-41344';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue