From dc1ab99136f06a550a12580832bca6cd726b0440 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Wed, 20 Nov 2019 17:13:21 +0200 Subject: [PATCH 1/7] Remove duplicated fireEcent, that prevents to duble initialization --- lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js b/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js index df691601eccb9..6cc53e3d40d92 100644 --- a/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js +++ b/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js @@ -293,7 +293,6 @@ define([ }; varienGlobalEvents.fireEvent('open_browser_callback', payload); - this.eventBus.fireEvent('open_browser_callback', payload); }.bind(this); } From d56adbb6e91bb014feafa6febfde65a53b7d3cf3 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Thu, 21 Nov 2019 09:23:14 +0200 Subject: [PATCH 2/7] Revert event add checks that method not fires two times at the time --- lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js b/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js index 6cc53e3d40d92..94e931f3349d7 100644 --- a/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js +++ b/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js @@ -293,6 +293,7 @@ define([ }; varienGlobalEvents.fireEvent('open_browser_callback', payload); + this.eventBus.fireEvent('open_browser_callback', payload); }.bind(this); } @@ -372,7 +373,7 @@ define([ /** * @param {Object} o */ - openFileBrowser: function (o) { + openFileBrowser: _.debounce(function (o) { var typeTitle = this.translate('Select Images'), storeId = this.config['store_id'] ? this.config['store_id'] : 0, frameDialog = jQuery('div.mce-container[role="dialog"]'), @@ -405,7 +406,7 @@ define([ } ); }); - }, + }, 250), /** * @param {String} string From a880a833582e76446ca12e23850805da0357299c Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Fri, 22 Nov 2019 14:38:47 +0200 Subject: [PATCH 3/7] remove duplicated events on wisiwyg initialization --- lib/internal/Magento/Framework/Data/Form/Element/Editor.php | 4 ---- lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php index b5f2017501c01..92dc2e6c97ecd 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php @@ -533,10 +533,6 @@ protected function getInlineJs($jsSetupObject, $forceLoad) $jsSetupObject . ')); varienGlobalEvents.attachEventHandler("formSubmit", editorFormValidationHandler); - varienGlobalEvents.clearEventHandlers("open_browser_callback"); - varienGlobalEvents.attachEventHandler("open_browser_callback", ' . - $jsSetupObject . - '.openFileBrowser); //]]> }); '; diff --git a/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js b/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js index 94e931f3349d7..df691601eccb9 100644 --- a/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js +++ b/lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js @@ -373,7 +373,7 @@ define([ /** * @param {Object} o */ - openFileBrowser: _.debounce(function (o) { + openFileBrowser: function (o) { var typeTitle = this.translate('Select Images'), storeId = this.config['store_id'] ? this.config['store_id'] : 0, frameDialog = jQuery('div.mce-container[role="dialog"]'), @@ -406,7 +406,7 @@ define([ } ); }); - }, 250), + }, /** * @param {String} string From 07fc246f5db339b9a79cc9ebe841df28eb1a239e Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Fri, 22 Nov 2019 15:03:06 +0200 Subject: [PATCH 4/7] Static test fix --- lib/internal/Magento/Framework/Data/Form/Element/Editor.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php index 92dc2e6c97ecd..0c9a3ee5b9495 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php @@ -309,9 +309,11 @@ protected function _getPluginButtonsHtml($visible = true) $configStyle = ''; if (isset($buttonOptions['style'])) { $configStyle = $buttonOptions['style']; - } + } + // phpcs:disable Magento2.Performance.ForeachArrayMerge $buttonOptions = array_merge($buttonOptions, ['style' => 'display:none;' . $configStyle]); - } + // phpcs:enable + } $buttonsHtml .= $this->_getButtonHtml($buttonOptions); } } From a6ba5850045eb2276fb91ce6b12bf0e12b90b383 Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Fri, 22 Nov 2019 15:24:42 +0200 Subject: [PATCH 5/7] Remove duplicated event --- .../Magento/Framework/Data/Form/Element/Editor.php | 8 ++++---- .../mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php index 0c9a3ee5b9495..5059fb38f29ca 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php @@ -309,11 +309,11 @@ protected function _getPluginButtonsHtml($visible = true) $configStyle = ''; if (isset($buttonOptions['style'])) { $configStyle = $buttonOptions['style']; - } + } // phpcs:disable Magento2.Performance.ForeachArrayMerge $buttonOptions = array_merge($buttonOptions, ['style' => 'display:none;' . $configStyle]); - // phpcs:enable - } + // phpcs:enable + } $buttonsHtml .= $this->_getButtonHtml($buttonOptions); } } @@ -411,7 +411,7 @@ protected function _getButtonHtml($data) protected function _wrapIntoContainer($html) { if (!$this->getConfig('use_container')) { - return '
' .$html . '
'; + return '
' . $html . '
'; } $html = '
Date: Fri, 22 Nov 2019 17:07:53 +0200 Subject: [PATCH 6/7] Fix for tinymce3 editor --- app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js b/app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js index bb3300baf988a..86602b2017c15 100644 --- a/app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js +++ b/app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js @@ -78,6 +78,8 @@ define([ } tinyMCE3.init(this.getSettings(mode)); + varienGlobalEvents.clearEventHandlers("open_browser_callback"); + varienGlobalEvents.attachEventHandler("open_browser_callback", tinyMceEditors.get(this.id).openFileBrowser); }, /** From 7b16d76207684bc5422058d323d5e35d36ac58bc Mon Sep 17 00:00:00 2001 From: Nazar Klovanych Date: Sun, 24 Nov 2019 01:13:15 +0200 Subject: [PATCH 7/7] Cover with js unit test, static test fix --- .../Tinymce3/view/base/web/tinymce3Adapter.js | 4 +- .../tests/lib/mage/tinymce4Adapter.test.js | 41 +++++++++++++++++++ .../Framework/Data/Form/Element/Editor.php | 4 +- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 dev/tests/js/jasmine/tests/lib/mage/tinymce4Adapter.test.js diff --git a/app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js b/app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js index 86602b2017c15..15bc5465e5d04 100644 --- a/app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js +++ b/app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js @@ -78,8 +78,8 @@ define([ } tinyMCE3.init(this.getSettings(mode)); - varienGlobalEvents.clearEventHandlers("open_browser_callback"); - varienGlobalEvents.attachEventHandler("open_browser_callback", tinyMceEditors.get(this.id).openFileBrowser); + varienGlobalEvents.clearEventHandlers('open_browser_callback'); + varienGlobalEvents.attachEventHandler('open_browser_callback', tinyMceEditors.get(this.id).openFileBrowser); }, /** diff --git a/dev/tests/js/jasmine/tests/lib/mage/tinymce4Adapter.test.js b/dev/tests/js/jasmine/tests/lib/mage/tinymce4Adapter.test.js new file mode 100644 index 0000000000000..7af1a19e4b4c1 --- /dev/null +++ b/dev/tests/js/jasmine/tests/lib/mage/tinymce4Adapter.test.js @@ -0,0 +1,41 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'wysiwygAdapter', + 'underscore' +], function (wysiwygAdapter, _) { + 'use strict'; + + var obj; + + beforeEach(function () { + + /** + * Dummy constructor to use for instantiation + * @constructor + */ + var Constr = function () {}; + + Constr.prototype = wysiwygAdapter; + + obj = new Constr(); + obj.eventBus = new window.varienEvents(); + obj.initialize(1, { + 'store_id': 0, + 'tinymce4': { + 'content_css': '' + }, + 'files_browser_window_url': 'url' + }); + obj.setup(); + }); + + describe('"openFileBrowser" method', function () { + it('Opens file browser to given instance', function () { + expect(_.size(obj.eventBus.arrEvents['open_browser_callback'])).toBe(1); + }); + }); +}); diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php index 5059fb38f29ca..08a5edd09bf35 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Editor.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Editor.php @@ -310,9 +310,7 @@ protected function _getPluginButtonsHtml($visible = true) if (isset($buttonOptions['style'])) { $configStyle = $buttonOptions['style']; } - // phpcs:disable Magento2.Performance.ForeachArrayMerge - $buttonOptions = array_merge($buttonOptions, ['style' => 'display:none;' . $configStyle]); - // phpcs:enable + $buttonOptions['style'] = 'display:none; ' . $configStyle; } $buttonsHtml .= $this->_getButtonHtml($buttonOptions); }