Make WordPress Core

Changeset 44247


Ignore:
Timestamp:
12/16/2018 11:55:58 PM (8 years ago)
Author:
SergeyBiryukov
Message:

Block Editor: Fix the TinyMCE wordpress plugin to handle hiding/showing of toolbars in the classic block. Change the classic block toolbar to use the (now fixed) wp_adv button.

Props azaozz.
Merges [43889] and [43890] to trunk.
Fixes #45264.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js

    r43336 r44247  
    2020
    2121        function toggleToolbars( state ) {
    22                 var iframe, initial, toolbars,
    23                         pixels = 0;
    24 
    25                 initial = ( state === 'hide' );
     22                var initial, toolbars,
     23                        pixels = 0,
     24                        classicBlockToolbar = tinymce.$( '.block-library-classic__toolbar' );
     25
     26                if ( state === 'hide' ) {
     27                        initial = true;
     28                } else if ( classicBlockToolbar.length && ! classicBlockToolbar.hasClass( 'has-advanced-toolbar' ) ) {
     29                        // Show the second, third, etc. toolbar rows in the Classic block instance.
     30                        classicBlockToolbar.addClass( 'has-advanced-toolbar' );
     31                        state = 'show';
     32                }
    2633
    2734                if ( editor.theme.panel ) {
     
    2936                }
    3037
    31                 if ( ! toolbars || toolbars.length < 2 || ( state === 'hide' && ! toolbars[1].visible() ) ) {
    32                         return;
    33                 }
    34 
    35                 if ( ! state && toolbars[1].visible() ) {
    36                         state = 'hide';
    37                 }
    38 
    39                 each( toolbars, function( toolbar, i ) {
    40                         if ( i > 0 ) {
    41                                 if ( state === 'hide' ) {
    42                                         toolbar.hide();
    43                                         pixels += 30;
    44                                 } else {
    45                                         toolbar.show();
    46                                         pixels -= 30;
    47                                 }
    48                         }
    49                 });
    50 
    51                 if ( pixels && ! initial ) {
    52                         // Resize iframe, not needed in iOS
    53                         if ( ! tinymce.Env.iOS ) {
    54                                 iframe = editor.getContentAreaContainer().firstChild;
    55                                 DOM.setStyle( iframe, 'height', iframe.clientHeight + pixels );
    56                         }
    57 
     38                if ( toolbars && toolbars.length > 1 ) {
     39                        if ( ! state && toolbars[1].visible() ) {
     40                                state = 'hide';
     41                        }
     42
     43                        each( toolbars, function( toolbar, i ) {
     44                                if ( i > 0 ) {
     45                                        if ( state === 'hide' ) {
     46                                                toolbar.hide();
     47                                                pixels += 30;
     48                                        } else {
     49                                                toolbar.show();
     50                                                pixels -= 30;
     51                                        }
     52                                }
     53                        });
     54                }
     55
     56                // Resize editor iframe, not needed for iOS and inline instances.
     57                if ( pixels && ! tinymce.Env.iOS && editor.iframeElement ) {
     58                        DOM.setStyle( editor.iframeElement, 'height', editor.iframeElement.clientHeight + pixels );
     59                }
     60
     61                if ( ! initial ) {
    5862                        if ( state === 'hide' ) {
    59                                 setUserSetting('hidetb', '0');
     63                                setUserSetting( 'hidetb', '0' );
    6064                                wpAdvButton && wpAdvButton.active( false );
    6165                        } else {
    62                                 setUserSetting('hidetb', '1');
     66                                setUserSetting( 'hidetb', '1' );
    6367                                wpAdvButton && wpAdvButton.active( true );
    6468                        }
     
    7478                onPostRender: function() {
    7579                        wpAdvButton = this;
    76                         wpAdvButton.active( getUserSetting( 'hidetb' ) === '1' ? true : false );
     80                        wpAdvButton.active( getUserSetting( 'hidetb' ) === '1' );
    7781                }
    7882        });
     
    8286                if ( editor.getParam( 'wordpress_adv_hidden', true ) && getUserSetting( 'hidetb', '0' ) === '0' ) {
    8387                        toggleToolbars( 'hide' );
     88                } else {
     89                        tinymce.$( '.block-library-classic__toolbar' ).addClass( 'has-advanced-toolbar' );
    8490                }
    8591        });
     
    427433        });
    428434
    429         // Menubar
    430435        // Insert->Add Media
    431436        if ( wp && wp.media && wp.media.editor ) {
     437                editor.addButton( 'wp_add_media', {
     438                        tooltip: 'Add Media',
     439                        icon: 'dashicon dashicons-admin-media',
     440                        cmd: 'WP_Medialib'
     441                } );
     442
    432443                editor.addMenuItem( 'add_media', {
    433444                        text: 'Add Media',
  • trunk/src/wp-includes/css/editor.css

    r43309 r44247  
    360360.mce-toolbar .mce-btn-group {
    361361        margin: 0;
     362}
     363
     364/* Classic block hide/show toolbars */
     365.block-library-classic__toolbar .mce-toolbar-grp .mce-toolbar:not(:first-child) {
     366        display: none;
     367}
     368
     369.block-library-classic__toolbar.has-advanced-toolbar .mce-toolbar-grp .mce-toolbar {
     370        display: block;
    362371}
    363372
  • trunk/src/wp-includes/script-loader.php

    r44239 r44247  
    518518                'spellchecker',
    519519                'wp_add_media',
    520                 'kitchensink',
     520                'wp_adv',
    521521        );
    522522
Note: See TracChangeset for help on using the changeset viewer.