| 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 | | } |
| | 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 | |