Make WordPress Core

Changeset 41344


Ignore:
Timestamp:
09/08/2017 10:56:10 AM (9 years ago)
Author:
azaozz
Message:

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.

Location:
trunk/src/wp-admin/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/editor.js

    r41151 r41344  
    563563                if ( settings.tinymce && settings.quicktags ) {
    564564                        var $textarea = $( '#' + id );
     565
    565566                        var $wrap = $( '<div>' ).attr( {
    566567                                        'class': 'wp-core-ui wp-editor-wrap tmce-active',
    567568                                        id: 'wp-' + id + '-wrap'
    568569                                } );
     570
    569571                        var $editorContainer = $( '<div class="wp-editor-container">' );
     572
    570573                        var $button = $( '<button>' ).attr( {
    571574                                        type: 'button',
     
    573576                                } );
    574577
     578                        var $editorTools = $( '<div class="wp-editor-tools">' );
     579
     580                        if ( settings.mediaButtons ) {
     581                                var buttonText = 'Add Media';
     582
     583                                if ( window._wpMediaViewsL10n && window._wpMediaViewsL10n.addMedia ) {
     584                                        buttonText = window._wpMediaViewsL10n.addMedia;
     585                                }
     586
     587                                var $addMediaButton = $( '<button type="button" class="button insert-media add_media">' );
     588
     589                                $addMediaButton.append( '<span class="wp-media-buttons-icon"></span>' );
     590                                $addMediaButton.append( document.createTextNode( ' ' + buttonText ) );
     591                                $addMediaButton.data( 'editor', id );
     592
     593                                $editorTools.append(
     594                                        $( '<div class="wp-media-buttons">' )
     595                                                .append( $addMediaButton )
     596                                );
     597                        }
     598
    575599                        $wrap.append(
    576                                 $( '<div class="wp-editor-tools">' )
     600                                $editorTools
    577601                                        .append( $( '<div class="wp-editor-tabs">' )
    578602                                                .append( $button.clone().attr({
  • trunk/src/wp-admin/js/widgets/text-widgets.js

    r41260 r41344  
    231231                                if ( typeof window.tinymce === 'undefined' ) {
    232232                                        wp.editor.initialize( id, {
    233                                                 quicktags: true
     233                                                quicktags: true,
     234                                                mediaButtons: true
    234235                                        });
    235236
     
    243244                                }
    244245
     246                                // Add or enable the `wpview` plugin.
     247                                $( document ).one( 'wp-before-tinymce-init.text-widget-init', function( event, init ) {
     248                                        // If somebody has removed all plugins, they must have a good reason.
     249                                        // Keep it that way.
     250                                        if ( ! init.plugins ) {
     251                                                return;
     252                                        } else if ( ! /\bwpview\b/.test( init.plugins ) ) {
     253                                                init.plugins += ',wpview';
     254                                        }
     255                                } );
     256
    245257                                wp.editor.initialize( id, {
    246258                                        tinymce: {
    247259                                                wpautop: true
    248260                                        },
    249                                         quicktags: true
     261                                        quicktags: true,
     262                                        mediaButtons: true
    250263                                });
    251264
Note: See TracChangeset for help on using the changeset viewer.