Skip to content

Commit

Permalink
ENGCOM-6329: Added 'clearEvent' to eventBus to prevent multiple attac…
Browse files Browse the repository at this point in the history
…h event on wysiwyg editor #25671
  • Loading branch information
VladimirZaets authored Nov 26, 2019
2 parents 83d9d7c + cdf6286 commit 2d36ee0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/code/Magento/Tinymce3/view/base/web/tinymce3Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

/**
Expand Down
41 changes: 41 additions & 0 deletions dev/tests/js/jasmine/tests/lib/mage/tinymce4Adapter.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
8 changes: 2 additions & 6 deletions lib/internal/Magento/Framework/Data/Form/Element/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ protected function _getPluginButtonsHtml($visible = true)
if (isset($buttonOptions['style'])) {
$configStyle = $buttonOptions['style'];
}
$buttonOptions = array_merge($buttonOptions, ['style' => 'display:none;' . $configStyle]);
$buttonOptions['style'] = 'display:none; ' . $configStyle;
}
$buttonsHtml .= $this->_getButtonHtml($buttonOptions);
}
Expand Down Expand Up @@ -409,7 +409,7 @@ protected function _getButtonHtml($data)
protected function _wrapIntoContainer($html)
{
if (!$this->getConfig('use_container')) {
return '<div class="admin__control-wysiwig">' .$html . '</div>';
return '<div class="admin__control-wysiwig">' . $html . '</div>';
}

$html = '<div id="editor' . $this->getHtmlId() . '"'
Expand Down Expand Up @@ -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);
//]]>
});
</script>';
Expand Down
1 change: 1 addition & 0 deletions lib/web/mage/adminhtml/wysiwyg/tiny_mce/tinymce4Adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ define([
tinyMCE4.init(settings);
this.getPluginButtons().hide();
varienGlobalEvents.clearEventHandlers('open_browser_callback');
this.eventBus.clearEventHandlers('open_browser_callback');
this.eventBus.attachEventHandler('open_browser_callback', tinyMceEditors.get(self.id).openFileBrowser);
}.bind(this));
},
Expand Down

0 comments on commit 2d36ee0

Please sign in to comment.