Make WordPress Core

Ticket #35710: 35710.1.diff

File 35710.1.diff, 5.5 KB (added by azaozz, 6 years ago)
  • src/js/_enqueues/vendor/tinymce/plugins/wordpress/plugin.js

     
    1212                __ = editor.editorManager.i18n.translate,
    1313                $ = window.jQuery,
    1414                wp = window.wp,
    15                 hasWpautop = ( wp && wp.editor && wp.editor.autop && editor.getParam( 'wpautop', true ) );
     15                hasWpautop = ( wp && wp.editor && wp.editor.autop && editor.getParam( 'wpautop', true ) ),
     16                wpTooltips = false;
    1617
    1718        if ( $ ) {
    1819                $( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] );
     
    581582                                }
    582583                        });
    583584                }
    584 
    585                 if ( editor.settings.wp_shortcut_labels && editor.theme.panel ) {
    586                         var labels = {};
    587                         var access = 'Shift+Alt+';
    588                         var meta = 'Ctrl+';
    589 
    590                         // For Mac: ctrl = \u2303, cmd = \u2318, alt = \u2325
    591 
    592                         if ( tinymce.Env.mac ) {
    593                                 access = '\u2303\u2325';
    594                                 meta = '\u2318';
    595                         }
    596 
    597                         each( editor.settings.wp_shortcut_labels, function( value, name ) {
    598                                 labels[ name ] = value.replace( 'access', access ).replace( 'meta', meta );
    599                         } );
    600 
    601                         each( editor.theme.panel.find('button'), function( button ) {
    602                                 if ( button && button.settings.tooltip && labels.hasOwnProperty( button.settings.tooltip ) ) {
    603                                         // Need to translate now. We are changing the string so it won't match and cannot be translated later.
    604                                         button.settings.tooltip = editor.translate( button.settings.tooltip ) + ' (' + labels[ button.settings.tooltip ] + ')';
    605                                 }
    606                         } );
    607 
    608                         // listbox for the "blocks" drop-down
    609                         each( editor.theme.panel.find('listbox'), function( listbox ) {
    610                                 if ( listbox && listbox.settings.text === 'Paragraph' ) {
    611                                         each( listbox.settings.values, function( item ) {
    612                                                 if ( item.text && labels.hasOwnProperty( item.text ) ) {
    613                                                         item.shortcut = '(' + labels[ item.text ] + ')';
    614                                                 }
    615                                         } );
    616                                 }
    617                         } );
    618                 }
    619585        });
    620586
    621587        editor.on( 'SaveContent', function( event ) {
     
    718684                }
    719685        });
    720686
     687        editor.on( 'beforerenderui', function() {
     688                if ( editor.theme.panel ) {
     689                        replaceButtonsTooltips( editor.theme.panel.find( 'button' ) );
     690                        addDropdownShortcuts();
     691                }
     692        } );
     693
     694        function prepareTooltips() {
     695                var access = 'Shift+Alt+';
     696                var meta = 'Ctrl+';
     697
     698                wpTooltips = {};
     699
     700                // For Mac: ctrl = \u2303, cmd = \u2318, alt = \u2325
     701                if ( tinymce.Env.mac ) {
     702                        access = '\u2303\u2325';
     703                        meta = '\u2318';
     704                }
     705
     706                // Some tooltips are translated, others are not...
     707                if ( editor.settings.wp_shortcut_labels ) {
     708                        each( editor.settings.wp_shortcut_labels, function( value, tooltip ) {
     709                                var translated = editor.translate( tooltip );
     710
     711                                value = value.replace( 'access', access ).replace( 'meta', meta );
     712                                wpTooltips[ tooltip ] = value;
     713
     714                                // Add the translated so we can match all of them.
     715                                if ( tooltip !== translated ) {
     716                                        wpTooltips[ translated ] = value;
     717                                }
     718                        } );
     719                }
     720        }
     721
     722        function getTooltip( tooltip ) {
     723                var translated = editor.translate( tooltip );
     724                var label;
     725
     726                if ( ! wpTooltips ) {
     727                        prepareTooltips();
     728                }
     729
     730                if ( wpTooltips.hasOwnProperty( translated ) ) {
     731                        label = wpTooltips[ translated ];
     732                } else if ( wpTooltips.hasOwnProperty( tooltip ) ) {
     733                        label = wpTooltips[ tooltip ];
     734                }
     735
     736                return label ? translated + ' (' + label + ')' : translated;
     737        }
     738
     739        function replaceButtonsTooltips( buttons ) {
     740
     741                if ( ! buttons ) {
     742                        return;
     743                }
     744
     745                each( buttons, function( button ) {
     746                        var tooltip;
     747
     748                        if ( button && button.settings.tooltip ) {
     749                                tooltip = getTooltip( button.settings.tooltip );
     750                                button.settings.tooltip = tooltip;
     751
     752                                // Override the aria label wiht the translated tooltip + shortcut.
     753                                if ( button._aria && button._aria.label ) {
     754                                        button._aria.label = tooltip;
     755                                }
     756                        }
     757                } );
     758        }
     759
     760        function addDropdownShortcuts() {
     761                // listbox for the "blocks" drop-down
     762                each( editor.theme.panel.find( 'listbox' ), function( listbox ) {
     763                        if ( listbox && listbox.settings.text === 'Paragraph' ) {
     764                                each( listbox.settings.values, function( item ) {
     765                                        if ( item.text && wpTooltips.hasOwnProperty( item.text ) ) {
     766                                                item.shortcut = '(' + wpTooltips[ item.text ] + ')';
     767                                        }
     768                                } );
     769                        }
     770                } );
     771        }
     772
    721773        /**
    722774         * Experimental: create a floating toolbar.
    723775         * This functionality will change in the next releases. Not recommended for use by plugins.
     
    752804
    753805                        each( buttons, function( item ) {
    754806                                var itemName;
     807                                var tooltip;
    755808
    756809                                function bindSelectorChanged() {
    757810                                        var selection = editor.selection;
     
    842895                                                                item.size = settings.toolbar_items_size;
    843896                                                        }
    844897
     898                                                        tooltip = item.tooltip || item.title;
     899
     900                                                        if ( tooltip ) {
     901                                                                item.tooltip = getTooltip( tooltip );
     902                                                        }
     903
    845904                                                        item = Factory.create( item );
    846905
    847906                                                        buttonGroup.items.push( item );
  • src/wp-includes/class-wp-editor.php

     
    11511151                                // Link plugin
    11521152                                'Link'                                 => __( 'Link' ),
    11531153                                'Insert link'                          => __( 'Insert link' ),
    1154                                 'Insert/edit link'                     => __( 'Insert/edit link' ),
    11551154                                'Target'                               => __( 'Target' ),
    11561155                                'New window'                           => __( 'New window' ),
    11571156                                'Text to display'                      => __( 'Text to display' ),