Make WordPress Core

Ticket #38063: 38063.2.patch

File 38063.2.patch, 14.3 KB (added by azaozz, 10 years ago)
  • src/wp-includes/class-wp-editor.php

     
    2626        private static $editor_buttons_css = true;
    2727        private static $drag_drop_upload = false;
    2828        private static $old_dfw_compat = false;
     29        private static $translation;
    2930
    3031        private function __construct() {}
    3132
     
    357358                                /** This filter is documented in wp-admin/includes/media.php */
    358359                                $no_captions = (bool) apply_filters( 'disable_captions', '' );
    359360                                $ext_plugins = '';
     361                                $tooltips = array();
    360362
     363                                foreach ( self::get_translation() as $name => $value ) {
     364                                        if ( is_array( $value ) ) {
     365                                                $tooltips[$name] = $value[1];
     366                                        }
     367                                }
     368
    361369                                if ( $set['teeny'] ) {
    362370
    363371                                        /**
     
    550558                                        'wpeditimage_disable_captions' => $no_captions,
    551559                                        'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),
    552560                                        'plugins' => implode( ',', $plugins ),
    553                                         'wp_lang_attr' => get_bloginfo( 'language' )
     561                                        'wp_lang_attr' => get_bloginfo( 'language' ),
     562                                        'wp_tooltips' => wp_json_encode( $tooltips ),
    554563                                );
    555564
    556565                                if ( ! empty( $mce_external_plugins ) ) {
     
    812821                ) );
    813822        }
    814823
    815         /**
    816          * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
    817          * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
    818          *
    819          * @static
    820          * @param string $mce_locale The locale used for the editor.
    821          * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
    822          * @return string Translation object, JSON encoded.
    823          */
    824         public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
    825 
    826                 $mce_translation = array(
     824        private static function get_translation() {
     825                if ( empty( self::$translation ) ) {
     826                        self::$translation = array(
    827827                        // Default TinyMCE strings
    828828                        'New document' => __( 'New document' ),
    829829                        'Formats' => _x( 'Formats', 'TinyMCE' ),
    830830
    831831                        'Headings' => _x( 'Headings', 'TinyMCE' ),
    832                         'Heading 1' => __( 'Heading 1' ),
    833                         'Heading 2' => __( 'Heading 2' ),
    834                         'Heading 3' => __( 'Heading 3' ),
    835                         'Heading 4' => __( 'Heading 4' ),
    836                         'Heading 5' => __( 'Heading 5' ),
    837                         'Heading 6' => __( 'Heading 6' ),
     832                        'Heading 1' => array( __( 'Heading 1' ), 'access1' ),
     833                        'Heading 2' => array( __( 'Heading 2' ), 'access2' ),
     834                        'Heading 3' => array( __( 'Heading 3' ), 'access3' ),
     835                        'Heading 4' => array( __( 'Heading 4' ), 'access4' ),
     836                        'Heading 5' => array( __( 'Heading 5' ), 'access5' ),
     837                        'Heading 6' => array( __( 'Heading 6' ), 'access6' ),
    838838
    839839                        /* translators: block tags */
    840840                        'Blocks' => _x( 'Blocks', 'TinyMCE' ),
    841                         'Paragraph' => __( 'Paragraph' ),
    842                         'Blockquote' => __( 'Blockquote' ),
     841                        'Paragraph' => array( __( 'Paragraph' ), 'access7' ),
     842                        'Blockquote' => array( __( 'Blockquote' ), 'accessQ' ),
    843843                        'Div' => _x( 'Div', 'HTML tag' ),
    844844                        'Pre' => _x( 'Pre', 'HTML tag' ),
    845845                        'Preformatted' => _x( 'Preformatted', 'HTML tag' ),
     
    846846                        'Address' => _x( 'Address', 'HTML tag' ),
    847847
    848848                        'Inline' => _x( 'Inline', 'HTML elements' ),
    849                         'Underline' => __( 'Underline' ),
    850                         'Strikethrough' => __( 'Strikethrough' ),
     849                        'Underline' => array( __( 'Underline' ), 'metaU' ),
     850                        'Strikethrough' => array( __( 'Strikethrough' ), 'accessD' ),
    851851                        'Subscript' => __( 'Subscript' ),
    852852                        'Superscript' => __( 'Superscript' ),
    853853                        'Clear formatting' => __( 'Clear formatting' ),
    854                         'Bold' => __( 'Bold' ),
    855                         'Italic' => __( 'Italic' ),
    856                         'Code' => __( 'Code' ),
     854                        'Bold' => array( __( 'Bold' ), 'metaB' ),
     855                        'Italic' => array( __( 'Italic' ), 'metaI' ),
     856                        'Code' => array( __( 'Code' ), 'accessX' ),
    857857                        'Source code' => __( 'Source code' ),
    858858                        'Font Family' => __( 'Font Family' ),
    859859                        'Font Sizes' => __( 'Font Sizes' ),
    860860
    861                         'Align center' => __( 'Align center' ),
    862                         'Align right' => __( 'Align right' ),
    863                         'Align left' => __( 'Align left' ),
    864                         'Justify' => __( 'Justify' ),
     861                        'Align center' => array( __( 'Align center' ), 'accessC' ),
     862                        'Align right' => array( __( 'Align right' ), 'accessR' ),
     863                        'Align left' => array( __( 'Align left' ), 'accessL' ),
     864                        'Justify' => array( __( 'Justify' ), 'accessJ' ),
    865865                        'Increase indent' => __( 'Increase indent' ),
    866866                        'Decrease indent' => __( 'Decrease indent' ),
    867867
    868                         'Cut' => __( 'Cut' ),
    869                         'Copy' => __( 'Copy' ),
    870                         'Paste' => __( 'Paste' ),
    871                         'Select all' => __( 'Select all' ),
    872                         'Undo' => __( 'Undo' ),
    873                         'Redo' => __( 'Redo' ),
     868                        'Cut' => array( __( 'Cut' ), 'metaX' ),
     869                        'Copy' => array( __( 'Copy' ), 'metaC' ),
     870                        'Paste' => array( __( 'Paste' ), 'metaV' ),
     871                        'Select all' => array( __( 'Select all' ), 'metaA' ),
     872                        'Undo' => array( __( 'Undo' ), 'metaZ' ),
     873                        'Redo' => array( __( 'Redo' ), 'metaY' ),
    874874
    875875                        'Ok' => __( 'OK' ),
    876876                        'Cancel' => __( 'Cancel' ),
     
    877877                        'Close' => __( 'Close' ),
    878878                        'Visual aids' => __( 'Visual aids' ),
    879879
    880                         'Bullet list' => __( 'Bulleted list' ),
    881                         'Numbered list' => __( 'Numbered list' ),
     880                        'Bullet list' => array( __( 'Bulleted list' ), 'accessU' ),
     881                        'Numbered list' => array( __( 'Numbered list' ), 'accessO' ),
    882882                        'Square' => _x( 'Square', 'list style' ),
    883883                        'Default' => _x( 'Default', 'list style' ),
    884884                        'Circle' => _x( 'Circle', 'list style' ),
     
    904904                        'Author' => __( 'Author' ),
    905905
    906906                        // Media, image plugins
    907                         'Insert/edit image' => __( 'Insert/edit image' ),
     907                        'Insert/edit image' => array( __( 'Insert/edit image' ), 'accessM' ),
    908908                        'General' => __( 'General' ),
    909909                        'Advanced' => __( 'Advanced' ),
    910910                        'Source' => __( 'Source' ),
     
    938938                        'Horizontal line' => __( 'Horizontal line' ),
    939939                        'Horizontal space' => __( 'Horizontal space' ),
    940940                        'Restore last draft' => __( 'Restore last draft' ),
    941                         'Insert/edit link' => __( 'Insert/edit link' ),
    942                         'Remove link' => __( 'Remove link' ),
     941                        'Insert/edit link' => array( __( 'Insert/edit link' ), 'metaK' ),
     942                        'Remove link' => array( __( 'Remove link' ), 'accessS' ),
    943943
    944944                        'Color' => __( 'Color' ),
    945945                        'Custom color' => __( 'Custom color' ),
     
    10431043                        'Format' => _x( 'Format', 'TinyMCE menu' ),
    10441044
    10451045                        // WordPress strings
    1046                         'Toolbar Toggle' => __( 'Toolbar Toggle' ),
    1047                         'Insert Read More tag' => __( 'Insert Read More tag' ),
    1048                         'Insert Page Break tag' => __( 'Insert Page Break tag' ),
     1046                        'Toolbar Toggle' => array( __( 'Toolbar Toggle' ), 'accessZ' ),
     1047                        'Insert Read More tag' => array( __( 'Insert Read More tag' ), 'accessT' ),
     1048                        'Insert Page Break tag' => array( __( 'Insert Page Break tag' ), 'accessP' ),
    10491049                        'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor (no ellipsis)
    1050                         'Distraction-free writing mode' => __( 'Distraction-free writing mode' ),
     1050                        'Distraction-free writing mode' => array( __( 'Distraction-free writing mode' ), 'accessW' ),
    10511051                        'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
    10521052                        'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
    10531053                        'Edit ' => __( 'Edit' ), // Tooltip for the 'edit' button in the image toolbar
     
    10561056                        'Link options'  => __( 'Link options' ), // Tooltip for the 'link options' button in the inline link dialog
    10571057
    10581058                        // Shortcuts help modal
    1059                         'Keyboard Shortcuts' => __( 'Keyboard Shortcuts' ),
     1059                        'Keyboard Shortcuts' => array( __( 'Keyboard Shortcuts' ), 'accessH' ),
    10601060                        'Default shortcuts,' => __( 'Default shortcuts,' ),
    10611061                        'Additional shortcuts,' => __( 'Additional shortcuts,' ),
    10621062                        'Focus shortcuts:' => __( 'Focus shortcuts:' ),
     
    10791079                                __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ),
    10801080                        'The next group of formatting shortcuts are applied as you type or when you insert them around plain text in the same paragraph. Press Escape or the Undo button to undo.' =>
    10811081                                __( 'The next group of formatting shortcuts are applied as you type or when you insert them around plain text in the same paragraph. Press Escape or the Undo button to undo.' ),
    1082                 );
     1082                        );
     1083                }
    10831084
    10841085                /**
    10851086                 * Link plugin (not included):
     
    10921093                 *      Url
    10931094                 */
    10941095
     1096                return self::$translation;
     1097        }
     1098
     1099        /**
     1100         * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
     1101         * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
     1102         *
     1103         * @static
     1104         * @param string $mce_locale The locale used for the editor.
     1105         * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
     1106         * @return string Translation object, JSON encoded.
     1107         */
     1108        public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
    10951109                if ( ! $mce_locale ) {
    10961110                        $mce_locale = self::$mce_locale;
    10971111                }
    10981112
     1113                $mce_translation = self::get_translation();
     1114               
     1115                foreach ( $mce_translation as $name => $value ) {
     1116                        if ( is_array( $value ) ) {
     1117                                $mce_translation[$name] = $value[0];
     1118                        }
     1119                }
     1120
    10991121                /**
    11001122                 * Filters translated strings prepared for TinyMCE.
    11011123                 *
  • src/wp-includes/css/editor.css

     
    588588.mce-menu .mce-menu-item-normal.mce-active,
    589589.mce-menu .mce-menu-item-preview.mce-active {
    590590        background: #0073aa; /* See color scheme. */
     591        color: #fff;
    591592}
    592593
    593594.mce-menu .mce-menu-item-preview.mce-active {
     
    650651        margin-left: -2px;
    651652}
    652653
     654/* Keyboard shortcuts position */
     655.mce-menu.mce-menu-align .mce-menu-item-normal {
     656        position: relative;
     657}
     658
     659.mce-menu.mce-menu-align .mce-menu-shortcut {
     660        bottom: 0.5em;
     661}
     662
    653663/* Buttons in modals */
    654664.mce-primary button,
    655665.mce-primary button i {
  • src/wp-includes/js/tinymce/plugins/wordpress/plugin.js

     
    231231                        meta = tinymce.Env.mac ? __( 'Cmd + letter:' ) : __( 'Ctrl + letter:' ),
    232232                        table1 = [],
    233233                        table2 = [],
     234                        row1 = {},
     235                        row2 = {},
     236                        i1 = 0,
     237                        i2 = 0,
     238                        tooltips = editor.settings.wp_tooltips,
    234239                        header, html, dialog, $wrap;
    235240
    236                 each( [
    237                         { c: 'Copy',      x: 'Cut'              },
    238                         { v: 'Paste',     a: 'Select all'       },
    239                         { z: 'Undo',      y: 'Redo'             },
    240                         { b: 'Bold',      i: 'Italic'           },
    241                         { u: 'Underline', k: 'Insert/edit link' }
    242                 ], function( row ) {
    243                         table1.push( tr( row ) );
    244                 } );
     241                if ( ! tooltips ) {
     242                        return;
     243                }
    245244
    246                 each( [
    247                         { 1: 'Heading 1',             2: 'Heading 2'                     },
    248                         { 3: 'Heading 3',             4: 'Heading 4'                     },
    249                         { 5: 'Heading 5',             6: 'Heading 6'                     },
    250                         { l: 'Align left',            c: 'Align center'                  },
    251                         { r: 'Align right',           j: 'Justify'                       },
    252                         { d: 'Strikethrough',         q: 'Blockquote'                    },
    253                         { u: 'Bullet list',           o: 'Numbered list'                 },
    254                         { a: 'Insert/edit link',      s: 'Remove link'                   },
    255                         { m: 'Insert/edit image',     t: 'Insert Read More tag'          },
    256                         { h: 'Keyboard Shortcuts',    x: 'Code'                          },
    257                         { p: 'Insert Page Break tag', w: 'Distraction-free writing mode' }
    258                 ], function( row ) {
    259                         table2.push( tr( row ) );
    260                 } );
    261 
    262                 function tr( row ) {
     245                function tr( row, columns ) {
    263246                        var out = '<tr>';
     247                        var i = 0;
    264248
     249                        columns = columns || 1;
     250
    265251                        each( row, function( text, key ) {
    266                                 if ( ! text ) {
    267                                         out += '<td></td><td></td>';
    268                                 } else {
    269                                         out += '<td><kbd>' + key + '</kbd></td><td>' + __( text ) + '</td>';
    270                                 }
     252                                out += '<td><kbd>' + key + '</kbd></td><td>' + __( text ) + '</td>';
     253                                i++;
    271254                        });
    272255
     256                        while ( i < columns ) {
     257                                out += '<td></td><td></td>';
     258                                i++;
     259                        }
     260
    273261                        return out + '</tr>';
    274262                }
    275263
     264                each ( tooltips, function( tooltip, name ) {
     265                        var letter;
     266
     267                        if ( tooltip.indexOf( 'meta' ) !== -1 ) {
     268                                i1++;
     269                                letter = tooltip.replace( 'meta', '' ).toLowerCase();
     270
     271                                if ( letter ) {
     272                                        row1[ letter ] = name;
     273
     274                                        if ( i1 % 2 === 0 ) {
     275                                                table1.push( tr( row1, 2 ) );
     276                                                row1 = {};
     277                                        }
     278                                }
     279                        } else if ( tooltip.indexOf( 'access' ) !== -1 ) {
     280                                i2++;
     281                                letter = tooltip.replace( 'access', '' ).toLowerCase();
     282
     283                                if ( letter ) {
     284                                        row2[ letter ] = name;
     285
     286                                        if ( i2 % 2 === 0 ) {
     287                                                table2.push( tr( row2, 2 ) );
     288                                                row2 = {};
     289                                        }
     290                                }
     291                        }
     292                } );
     293
     294                // Add remaining single entries.
     295                if ( i1 % 2 > 0 ) {
     296                        table1.push( tr( row1, 2 ) );
     297                }
     298
     299                if ( i2 % 2 > 0 ) {
     300                        table2.push( tr( row2, 2 ) );
     301                }
     302
    276303                header = [ __( 'Letter' ), __( 'Action' ), __( 'Letter' ), __( 'Action' ) ];
    277304                header = '<tr><th>' + header.join( '</th><th>' ) + '</th></tr>';
    278305
     
    521548                                });
    522549                        });
    523550                }
     551
     552                if ( editor.settings.wp_tooltips ) {
     553                        var tooltips = tinymce.extend( {}, editor.settings.wp_tooltips );
     554                        var access = 'Shift+Alt+';
     555                        var meta = 'Ctrl+';
     556
     557                        // For Mac: shift = \u2303, ctrl = \u21E7, cmd = \u2318, alt = \u2325
     558
     559                        if ( tinymce.Env.mac ) {
     560                                access = '\u2303\u2325 ';
     561                                meta = '\u2318 ';
     562                        }
     563
     564                        each( tooltips, function( value, name ) {
     565                                tooltips[ name ] = value.replace( 'access', access ).replace( 'meta', meta );
     566                        } );
     567
     568                        each( editor.theme.panel.find('button'), function( button ) {
     569                                if ( button && button.settings.tooltip && tooltips.hasOwnProperty( button.settings.tooltip ) ) {
     570                                        button.settings.tooltip += ' (' + tooltips[ button.settings.tooltip ] + ')';
     571                                }
     572                        } );
     573
     574                        // listbox for the "blocks" drop-down
     575                        each( editor.theme.panel.find('listbox'), function( listbox ) {
     576                                if ( listbox && listbox.settings.text === 'Paragraph' ) {
     577                                        each( listbox.settings.values, function( item ) {
     578                                                if ( item.text && tooltips.hasOwnProperty( item.text ) ) {
     579                                                        item.shortcut = '(' + tooltips[ item.text ] + ')';
     580                                                }
     581                                        } );
     582                                }
     583                        } );
     584                }
    524585        });
    525586
    526587        editor.on( 'SaveContent', function( event ) {