- Fix adding the keyboard shortcuts to all button tooltips in the classic editor and classic block.
- Fix translating the aria labels for all buttons.

Fixes #35710;
Built from https://develop.svn.wordpress.org/trunk@45066


git-svn-id: http://core.svn.wordpress.org/trunk@44875 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2019-03-29 00:49:51 +00:00
parent 5a481ea118
commit 7ab495bfed
5 changed files with 101 additions and 40 deletions

View File

@ -1151,7 +1151,6 @@ final class _WP_Editors {
// Link plugin
'Link' => __( 'Link' ),
'Insert link' => __( 'Insert link' ),
'Insert/edit link' => __( 'Insert/edit link' ),
'Target' => __( 'Target' ),
'New window' => __( 'New window' ),
'Text to display' => __( 'Text to display' ),

View File

@ -12,7 +12,8 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
__ = editor.editorManager.i18n.translate,
$ = window.jQuery,
wp = window.wp,
hasWpautop = ( wp && wp.editor && wp.editor.autop && editor.getParam( 'wpautop', true ) );
hasWpautop = ( wp && wp.editor && wp.editor.autop && editor.getParam( 'wpautop', true ) ),
wpTooltips = false;
if ( $ ) {
$( document ).triggerHandler( 'tinymce-editor-setup', [ editor ] );
@ -581,41 +582,6 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
}
});
}
if ( editor.settings.wp_shortcut_labels && editor.theme.panel ) {
var labels = {};
var access = 'Shift+Alt+';
var meta = 'Ctrl+';
// For Mac: ctrl = \u2303, cmd = \u2318, alt = \u2325
if ( tinymce.Env.mac ) {
access = '\u2303\u2325';
meta = '\u2318';
}
each( editor.settings.wp_shortcut_labels, function( value, name ) {
labels[ name ] = value.replace( 'access', access ).replace( 'meta', meta );
} );
each( editor.theme.panel.find('button'), function( button ) {
if ( button && button.settings.tooltip && labels.hasOwnProperty( button.settings.tooltip ) ) {
// Need to translate now. We are changing the string so it won't match and cannot be translated later.
button.settings.tooltip = editor.translate( button.settings.tooltip ) + ' (' + labels[ button.settings.tooltip ] + ')';
}
} );
// listbox for the "blocks" drop-down
each( editor.theme.panel.find('listbox'), function( listbox ) {
if ( listbox && listbox.settings.text === 'Paragraph' ) {
each( listbox.settings.values, function( item ) {
if ( item.text && labels.hasOwnProperty( item.text ) ) {
item.shortcut = '(' + labels[ item.text ] + ')';
}
} );
}
} );
}
});
editor.on( 'SaveContent', function( event ) {
@ -718,6 +684,95 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
}
});
editor.on( 'beforerenderui', function() {
if ( editor.theme.panel ) {
each( [ 'button', 'colorbutton', 'splitbutton' ], function( buttonType ) {
replaceButtonsTooltips( editor.theme.panel.find( buttonType ) );
} );
addShortcutsToListbox();
}
} );
function prepareTooltips() {
var access = 'Shift+Alt+';
var meta = 'Ctrl+';
wpTooltips = {};
// For MacOS: ctrl = \u2303, cmd = \u2318, alt = \u2325
if ( tinymce.Env.mac ) {
access = '\u2303\u2325';
meta = '\u2318';
}
// Some tooltips are translated, others are not...
if ( editor.settings.wp_shortcut_labels ) {
each( editor.settings.wp_shortcut_labels, function( value, tooltip ) {
var translated = editor.translate( tooltip );
value = value.replace( 'access', access ).replace( 'meta', meta );
wpTooltips[ tooltip ] = value;
// Add the translated so we can match all of them.
if ( tooltip !== translated ) {
wpTooltips[ translated ] = value;
}
} );
}
}
function getTooltip( tooltip ) {
var translated = editor.translate( tooltip );
var label;
if ( ! wpTooltips ) {
prepareTooltips();
}
if ( wpTooltips.hasOwnProperty( translated ) ) {
label = wpTooltips[ translated ];
} else if ( wpTooltips.hasOwnProperty( tooltip ) ) {
label = wpTooltips[ tooltip ];
}
return label ? translated + ' (' + label + ')' : translated;
}
function replaceButtonsTooltips( buttons ) {
if ( ! buttons ) {
return;
}
each( buttons, function( button ) {
var tooltip;
if ( button && button.settings.tooltip ) {
tooltip = getTooltip( button.settings.tooltip );
button.settings.tooltip = tooltip;
// Override the aria label wiht the translated tooltip + shortcut.
if ( button._aria && button._aria.label ) {
button._aria.label = tooltip;
}
}
} );
}
function addShortcutsToListbox() {
// listbox for the "blocks" drop-down
each( editor.theme.panel.find( 'listbox' ), function( listbox ) {
if ( listbox && listbox.settings.text === 'Paragraph' ) {
each( listbox.settings.values, function( item ) {
if ( item.text && wpTooltips.hasOwnProperty( item.text ) ) {
item.shortcut = '(' + wpTooltips[ item.text ] + ')';
}
} );
}
} );
}
/**
* Experimental: create a floating toolbar.
* This functionality will change in the next releases. Not recommended for use by plugins.
@ -752,6 +807,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
each( buttons, function( item ) {
var itemName;
var tooltip;
function bindSelectorChanged() {
var selection = editor.selection;
@ -842,6 +898,12 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
item.size = settings.toolbar_items_size;
}
tooltip = item.tooltip || item.title;
if ( tooltip ) {
item.tooltip = getTooltip( tooltip );
}
item = Factory.create( item );
buttonGroup.items.push( item );

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.2-beta1-45065';
$wp_version = '5.2-beta1-45066';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.