diff --git a/wp-includes/class-wp-editor.php b/wp-includes/class-wp-editor.php index 03eb8a39d9..c3cb7e7241 100644 --- a/wp-includes/class-wp-editor.php +++ b/wp-includes/class-wp-editor.php @@ -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' ), diff --git a/wp-includes/js/tinymce/plugins/wordpress/plugin.js b/wp-includes/js/tinymce/plugins/wordpress/plugin.js index 790fad6265..b93e936b09 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/plugin.js +++ b/wp-includes/js/tinymce/plugins/wordpress/plugin.js @@ -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 ); diff --git a/wp-includes/js/tinymce/plugins/wordpress/plugin.min.js b/wp-includes/js/tinymce/plugins/wordpress/plugin.min.js index f5ba84b3eb..f782007017 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/plugin.min.js +++ b/wp-includes/js/tinymce/plugins/wordpress/plugin.min.js @@ -1 +1 @@ -!function(a){(!a.ui.FloatPanel.zIndex||a.ui.FloatPanel.zIndex<100100)&&(a.ui.FloatPanel.zIndex=100100),a.PluginManager.add("wordpress",function(b){function c(c){var d,f,i,j=0,k=a.$(".block-library-classic__toolbar");"hide"===c?d=!0:k.length&&!k.hasClass("has-advanced-toolbar")&&(k.addClass("has-advanced-toolbar"),c="show"),b.theme.panel&&(f=b.theme.panel.find(".toolbar:not(.menubar)")),f&&f.length>1&&(!c&&f[1].visible()&&(c="hide"),h(f,function(a,b){b>0&&("hide"===c?(a.hide(),j+=34):(a.show(),j-=34))})),j&&!a.Env.iOS&&b.iframeElement&&b.iframeElement.clientHeight&&(i=b.iframeElement.clientHeight+j,i>50&&g.setStyle(b.iframeElement,"height",i)),d||("hide"===c?(setUserSetting("hidetb","0"),e&&e.active(!1)):(setUserSetting("hidetb","1"),e&&e.active(!0))),b.fire("wp-toolbar-toggle")}function d(){}var e,f,g=a.DOM,h=a.each,i=b.editorManager.i18n.translate,j=window.jQuery,k=window.wp,l=k&&k.editor&&k.editor.autop&&b.getParam("wpautop",!0);return j&&j(document).triggerHandler("tinymce-editor-setup",[b]),b.addButton("wp_adv",{tooltip:"Toolbar Toggle",cmd:"WP_Adv",onPostRender:function(){e=this,e.active("1"===getUserSetting("hidetb"))}}),b.on("PostRender",function(){b.getParam("wordpress_adv_hidden",!0)&&"0"===getUserSetting("hidetb","0")?c("hide"):a.$(".block-library-classic__toolbar").addClass("has-advanced-toolbar")}),b.addCommand("WP_Adv",function(){c()}),b.on("focus",function(){window.wpActiveEditor=b.id}),b.on("BeforeSetContent",function(b){var c;b.content&&(b.content.indexOf("/g,function(b,d){return''})),b.content.indexOf("")!==-1&&(c=i("Page break"),b.content=b.content.replace(//g,'')),b.load&&"raw"!==b.format&&(l?b.content=k.editor.autop(b.content):b.content=b.content.replace(/-->\s+"):a.indexOf('data-wp-more="nextpage"')!==-1?c="":a.indexOf("data-wp-preserve")!==-1&&(b=a.match(/ data-wp-preserve="([^"]+)"/))&&(c=decodeURIComponent(b[1])),c||a}))}),b.on("ResolveName",function(a){var c;"IMG"===a.target.nodeName&&(c=b.dom.getAttrib(a.target,"data-wp-more"))&&(a.name=c)}),b.addCommand("WP_More",function(c){var d,e,f,g="wp-more-tag",h=b.dom,j=b.selection.getNode(),k=b.getBody();return c=c||"more",g+=" mce-wp-"+c,f="more"===c?"Read more...":"Next page",f=i(f),e='',j===k||"P"===j.nodeName&&j.parentNode===k?void b.insertContent(e):(d=h.getParent(j,function(a){return!(!a.parentNode||a.parentNode!==k)},b.getBody()),void(d&&("P"===d.nodeName?d.appendChild(h.create("p",null,e).firstChild):h.insertAfter(h.create("p",null,e),d),b.nodeChanged())))}),b.addCommand("WP_Code",function(){b.formatter.toggle("code")}),b.addCommand("WP_Page",function(){b.execCommand("WP_More","nextpage")}),b.addCommand("WP_Help",function(){function c(a,b){var c="
"+i("To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.")+"
",e+="\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi,"<$1$2>").replace(/<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi,"$1>"))}),j&&j(document).triggerHandler("tinymce-editor-init",[b]),window.tinyMCEPreInit&&window.tinyMCEPreInit.dragDropUpload&&f.bind(e,"dragstart dragend dragover drop",function(a){j&&j(document).trigger(new j.Event(a))}),b.getParam("wp_paste_filters",!0)&&(b.on("PastePreProcess",function(b){b.content=b.content.replace(/
/gi,""),a.Env.webkit||(b.content=b.content.replace(/(<[^>]+) style="[^"]*"([^>]*>)/gi,"$1$2"),b.content=b.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi,"$1 style=$2"))}),b.on("PastePostProcess",function(c){b.$("p",c.node).each(function(a,b){f.isEmpty(b)&&f.remove(b)}),a.isIE&&b.$("a",c.node).find("font, u").each(function(a,b){f.remove(b,!0)})})),b.settings.wp_shortcut_labels&&b.theme.panel){var g={},i="Shift+Alt+",k="Ctrl+";a.Env.mac&&(i="\u2303\u2325",k="\u2318"),h(b.settings.wp_shortcut_labels,function(a,b){g[b]=a.replace("access",i).replace("meta",k)}),h(b.theme.panel.find("button"),function(a){a&&a.settings.tooltip&&g.hasOwnProperty(a.settings.tooltip)&&(a.settings.tooltip=b.translate(a.settings.tooltip)+" ("+g[a.settings.tooltip]+")")}),h(b.theme.panel.find("listbox"),function(a){a&&"Paragraph"===a.settings.text&&h(a.settings.values,function(a){a.text&&g.hasOwnProperty(a.text)&&(a.shortcut="("+g[a.text]+")")})})}}),b.on("SaveContent",function(a){return!b.inline&&b.isHidden()?void(a.content=a.element.value):(a.content=a.content.replace(/
(?:
|\u00a0|\uFEFF| )*<\/p>/g,"
"),void(l?a.content=k.editor.removep(a.content):a.content=a.content.replace(/-->\s*\n\n/g,function(b,d){return''})),b.content.indexOf("")!==-1&&(c=m("Page break"),b.content=b.content.replace(//g,'')),b.load&&"raw"!==b.format&&(p?b.content=o.editor.autop(b.content):b.content=b.content.replace(/-->\s+"):a.indexOf('data-wp-more="nextpage"')!==-1?c="":a.indexOf("data-wp-preserve")!==-1&&(b=a.match(/ data-wp-preserve="([^"]+)"/))&&(c=decodeURIComponent(b[1])),c||a}))}),b.on("ResolveName",function(a){var c;"IMG"===a.target.nodeName&&(c=b.dom.getAttrib(a.target,"data-wp-more"))&&(a.name=c)}),b.addCommand("WP_More",function(c){var d,e,f,g="wp-more-tag",h=b.dom,i=b.selection.getNode(),j=b.getBody();return c=c||"more",g+=" mce-wp-"+c,f="more"===c?"Read more...":"Next page",f=m(f),e='',i===j||"P"===i.nodeName&&i.parentNode===j?void b.insertContent(e):(d=h.getParent(i,function(a){return!(!a.parentNode||a.parentNode!==j)},b.getBody()),void(d&&("P"===d.nodeName?d.appendChild(h.create("p",null,e).firstChild):h.insertAfter(h.create("p",null,e),d),b.nodeChanged())))}),b.addCommand("WP_Code",function(){b.formatter.toggle("code")}),b.addCommand("WP_Page",function(){b.execCommand("WP_More","nextpage")}),b.addCommand("WP_Help",function(){function c(a,b){var c="
"+m("To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.")+"
",e+="\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi,"<$1$2>").replace(/<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi,"$1>"))}),n&&n(document).triggerHandler("tinymce-editor-init",[b]),window.tinyMCEPreInit&&window.tinyMCEPreInit.dragDropUpload&&f.bind(e,"dragstart dragend dragover drop",function(a){n&&n(document).trigger(new n.Event(a))}),b.getParam("wp_paste_filters",!0)&&(b.on("PastePreProcess",function(b){b.content=b.content.replace(/
/gi,""),a.Env.webkit||(b.content=b.content.replace(/(<[^>]+) style="[^"]*"([^>]*>)/gi,"$1$2"),b.content=b.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi,"$1 style=$2"))}),b.on("PastePostProcess",function(c){b.$("p",c.node).each(function(a,b){f.isEmpty(b)&&f.remove(b)}),a.isIE&&b.$("a",c.node).find("font, u").each(function(a,b){f.remove(b,!0)})}))}),b.on("SaveContent",function(a){return!b.inline&&b.isHidden()?void(a.content=a.element.value):(a.content=a.content.replace(/
(?:
|\u00a0|\uFEFF| )*<\/p>/g,"
"),void(p?a.content=o.editor.removep(a.content):a.content=a.content.replace(/-->\s*\n\n/g,function(b,d){return''})),b.content.indexOf("")!==-1&&(c=i("Page break"),b.content=b.content.replace(//g,'')),b.load&&"raw"!==b.format&&(l?b.content=k.editor.autop(b.content):b.content=b.content.replace(/-->\s+"):a.indexOf('data-wp-more="nextpage"')!==-1?c="":a.indexOf("data-wp-preserve")!==-1&&(b=a.match(/ data-wp-preserve="([^"]+)"/))&&(c=decodeURIComponent(b[1])),c||a}))}),b.on("ResolveName",function(a){var c;"IMG"===a.target.nodeName&&(c=b.dom.getAttrib(a.target,"data-wp-more"))&&(a.name=c)}),b.addCommand("WP_More",function(c){var d,e,f,g="wp-more-tag",h=b.dom,j=b.selection.getNode(),k=b.getBody();return c=c||"more",g+=" mce-wp-"+c,f="more"===c?"Read more...":"Next page",f=i(f),e='',j===k||"P"===j.nodeName&&j.parentNode===k?void b.insertContent(e):(d=h.getParent(j,function(a){return!(!a.parentNode||a.parentNode!==k)},b.getBody()),void(d&&("P"===d.nodeName?d.appendChild(h.create("p",null,e).firstChild):h.insertAfter(h.create("p",null,e),d),b.nodeChanged())))}),b.addCommand("WP_Code",function(){b.formatter.toggle("code")}),b.addCommand("WP_Page",function(){b.execCommand("WP_More","nextpage")}),b.addCommand("WP_Help",function(){function c(a,b){var c="
"+i("To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.")+"
",e+="\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi,"<$1$2>").replace(/<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi,"$1>"))}),j&&j(document).triggerHandler("tinymce-editor-init",[b]),window.tinyMCEPreInit&&window.tinyMCEPreInit.dragDropUpload&&f.bind(e,"dragstart dragend dragover drop",function(a){j&&j(document).trigger(new j.Event(a))}),b.getParam("wp_paste_filters",!0)&&(b.on("PastePreProcess",function(b){b.content=b.content.replace(/
/gi,""),a.Env.webkit||(b.content=b.content.replace(/(<[^>]+) style="[^"]*"([^>]*>)/gi,"$1$2"),b.content=b.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi,"$1 style=$2"))}),b.on("PastePostProcess",function(c){b.$("p",c.node).each(function(a,b){f.isEmpty(b)&&f.remove(b)}),a.isIE&&b.$("a",c.node).find("font, u").each(function(a,b){f.remove(b,!0)})})),b.settings.wp_shortcut_labels&&b.theme.panel){var g={},i="Shift+Alt+",k="Ctrl+";a.Env.mac&&(i="\u2303\u2325",k="\u2318"),h(b.settings.wp_shortcut_labels,function(a,b){g[b]=a.replace("access",i).replace("meta",k)}),h(b.theme.panel.find("button"),function(a){a&&a.settings.tooltip&&g.hasOwnProperty(a.settings.tooltip)&&(a.settings.tooltip=b.translate(a.settings.tooltip)+" ("+g[a.settings.tooltip]+")")}),h(b.theme.panel.find("listbox"),function(a){a&&"Paragraph"===a.settings.text&&h(a.settings.values,function(a){a.text&&g.hasOwnProperty(a.text)&&(a.shortcut="("+g[a.text]+")")})})}}),b.on("SaveContent",function(a){return!b.inline&&b.isHidden()?void(a.content=a.element.value):(a.content=a.content.replace(/
(?:
|\u00a0|\uFEFF| )*<\/p>/g,"
"),void(l?a.content=k.editor.removep(a.content):a.content=a.content.replace(/-->\s*\n\n/g,function(b,d){return''})),b.content.indexOf("")!==-1&&(c=m("Page break"),b.content=b.content.replace(//g,'')),b.load&&"raw"!==b.format&&(p?b.content=o.editor.autop(b.content):b.content=b.content.replace(/-->\s+"):a.indexOf('data-wp-more="nextpage"')!==-1?c="":a.indexOf("data-wp-preserve")!==-1&&(b=a.match(/ data-wp-preserve="([^"]+)"/))&&(c=decodeURIComponent(b[1])),c||a}))}),b.on("ResolveName",function(a){var c;"IMG"===a.target.nodeName&&(c=b.dom.getAttrib(a.target,"data-wp-more"))&&(a.name=c)}),b.addCommand("WP_More",function(c){var d,e,f,g="wp-more-tag",h=b.dom,i=b.selection.getNode(),j=b.getBody();return c=c||"more",g+=" mce-wp-"+c,f="more"===c?"Read more...":"Next page",f=m(f),e='',i===j||"P"===i.nodeName&&i.parentNode===j?void b.insertContent(e):(d=h.getParent(i,function(a){return!(!a.parentNode||a.parentNode!==j)},b.getBody()),void(d&&("P"===d.nodeName?d.appendChild(h.create("p",null,e).firstChild):h.insertAfter(h.create("p",null,e),d),b.nodeChanged())))}),b.addCommand("WP_Code",function(){b.formatter.toggle("code")}),b.addCommand("WP_Page",function(){b.execCommand("WP_More","nextpage")}),b.addCommand("WP_Help",function(){function c(a,b){var c="
"+m("To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.")+"
",e+="\s*<(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)( [^>]*)?>/gi,"<$1$2>").replace(/<\/(p|div|ul|ol|dl|table|blockquote|h[1-6]|fieldset|pre)>\s*<\/p>/gi,"$1>"))}),n&&n(document).triggerHandler("tinymce-editor-init",[b]),window.tinyMCEPreInit&&window.tinyMCEPreInit.dragDropUpload&&f.bind(e,"dragstart dragend dragover drop",function(a){n&&n(document).trigger(new n.Event(a))}),b.getParam("wp_paste_filters",!0)&&(b.on("PastePreProcess",function(b){b.content=b.content.replace(/
/gi,""),a.Env.webkit||(b.content=b.content.replace(/(<[^>]+) style="[^"]*"([^>]*>)/gi,"$1$2"),b.content=b.content.replace(/(<[^>]+) data-mce-style=([^>]+>)/gi,"$1 style=$2"))}),b.on("PastePostProcess",function(c){b.$("p",c.node).each(function(a,b){f.isEmpty(b)&&f.remove(b)}),a.isIE&&b.$("a",c.node).find("font, u").each(function(a,b){f.remove(b,!0)})}))}),b.on("SaveContent",function(a){return!b.inline&&b.isHidden()?void(a.content=a.element.value):(a.content=a.content.replace(/
(?:
|\u00a0|\uFEFF| )*<\/p>/g,"
"),void(p?a.content=o.editor.removep(a.content):a.content=a.content.replace(/-->\s*\n\n