diff --git a/assets/js/src/newsletter_editor/tinymce/mailpoet_shortcodes.js b/assets/js/src/newsletter_editor/tinymce/mailpoet_shortcodes.js index ebaedcbd81..3284268596 100644 --- a/assets/js/src/newsletter_editor/tinymce/mailpoet_shortcodes.js +++ b/assets/js/src/newsletter_editor/tinymce/mailpoet_shortcodes.js @@ -8,50 +8,54 @@ * its placeholder into editor text. */ +import MailPoet from 'mailpoet'; function tinyMceAdd(editor) { - var appendLabelAndClose = function appendLabelAndCLose(shortcode) { - editor.insertContent(shortcode); - editor.windowManager.close(); - }; - var generateOnClickFunc = function generateOnClickFunc(shortcode) { - return function appendAndClose() { - appendLabelAndClose(shortcode); - }; - }; + editor.ui.registry.addIcon('mailpoet', ''); - editor.addButton('mailpoet_shortcodes', { - icon: 'mailpoet_shortcodes', - onclick: function onClick() { + editor.ui.registry.addButton('mailpoet_shortcodes', { + icon: 'mailpoet', + onAction: function onActionButton() { var shortcodes = []; var configShortcodes = editor.settings.mailpoet_shortcodes; var i; Object.keys(configShortcodes).forEach(function configShortcodesLoop(segment) { + var section; if (Object.prototype.hasOwnProperty.call(configShortcodes, segment)) { - shortcodes.push({ - type: 'label', - text: segment, - }); + section = { + name: segment, + title: segment, + items: [], + }; for (i = 0; i < configShortcodes[segment].length; i += 1) { - shortcodes.push({ + section.items.push({ type: 'button', text: configShortcodes[segment][i].text, - onClick: generateOnClickFunc(configShortcodes[segment][i].shortcode), + name: configShortcodes[segment][i].shortcode, }); } + shortcodes.push(section); } }); // Open window editor.windowManager.open({ - height: parseInt(editor.getParam('plugin_mailpoet_shortcodes_height', 400), 10), - width: parseInt(editor.getParam('plugin_mailpoet_shortcodes_width', 450), 10), - autoScroll: true, title: editor.settings.mailpoet_shortcodes_window_title, - body: shortcodes, - buttons: [], + body: { + type: 'tabpanel', + tabs: shortcodes, + }, + buttons: [{ + type: 'cancel', + text: MailPoet.I18n.t('close'), + primary: true, + }], + onAction: function onActionDialog(dialog, button) { + editor.insertContent(button.name); + editor.windowManager.close(); + }, }); }, }); diff --git a/views/newsletter/editor.html b/views/newsletter/editor.html index bbaaeea051..416ab78a50 100644 --- a/views/newsletter/editor.html +++ b/views/newsletter/editor.html @@ -304,6 +304,7 @@ |replaceLinkTags('https://kb.mailpoet.com/article/146-my-newsletters-are-not-being-received', {'target' : '_blank', 'data-beacon-article': '580846f09033604df5166ed1'}) |escape('js') %> <%= localize({ + 'close': __('Close'), 'failedToFetchAvailablePosts': __('Failed to fetch available posts'), 'failedToFetchRenderedPosts': __('Failed to fetch rendered posts'), 'shortcodesWindowTitle': __('Select a shortcode'),