Skip to content

Commit

Permalink
fix: check if function is available
Browse files Browse the repository at this point in the history
  • Loading branch information
fortunatomaldonado committed Oct 19, 2023
1 parent e54b4cd commit 9d3ac83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
15 changes: 9 additions & 6 deletions src/components/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ class UI extends React.Component {
// debounce it, when the handler is being invoked, the target might be no more part
// of the editor's UI - onActionPerformed causes re-render.

this._mousedownListener = event => {
this._mousedownListener = (event) => {
this._setUIHidden(event.target);
};

this._keyDownListener = CKEDITOR.tools.debounce(
_event => {
(_event) => {
this._setUIHidden(document.activeElement);
},
this.props.eventsDelay,
Expand Down Expand Up @@ -201,7 +201,7 @@ class UI extends React.Component {
} else {
const toolbarNames = Array.prototype.slice
.call(toolbarsNodeList)
.map(toolbar => {
.map((toolbar) => {
return toolbar.getAttribute('aria-label');
});

Expand Down Expand Up @@ -229,7 +229,10 @@ class UI extends React.Component {
}

if (this._keyDownListener) {
this._keyDownListener.detach();
if (this._keyDownListener.detach) {
this._keyDownListener.detach();
}

document.removeEventListener('keydown', this._keyDownListener);
}
}
Expand All @@ -248,11 +251,11 @@ class UI extends React.Component {
return null;
}

let toolbars = Object.keys(this.props.toolbars).map(toolbar => {
let toolbars = Object.keys(this.props.toolbars).map((toolbar) => {
return AlloyEditor.Toolbars[toolbar] || window[toolbar];
});

toolbars = this.filterExclusive(toolbars).map(toolbar => {
toolbars = this.filterExclusive(toolbars).map((toolbar) => {
const props = this.mergeExclusiveProps(
{
config: this.props.toolbars[toolbar.key],
Expand Down
16 changes: 9 additions & 7 deletions src/core/uicore.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if (!CKEDITOR.plugins.get('ae_uicore')) {
? editor.config.uicore.timeout
: 50;

const handleUI = CKEDITOR.tools.debounce(event => {
const handleUI = CKEDITOR.tools.debounce((event) => {
ariaState = [];

if (
Expand All @@ -95,11 +95,11 @@ if (!CKEDITOR.plugins.get('ae_uicore')) {
}
}, uiTasksTimeout);

const handleAria = CKEDITOR.tools.debounce(_event => {
const handleAria = CKEDITOR.tools.debounce((_event) => {
ariaElement.innerHTML = ariaState.join('. ');
}, uiTasksTimeout);

const handleMouseLeave = CKEDITOR.tools.debounce(event => {
const handleMouseLeave = CKEDITOR.tools.debounce((event) => {
const aeUINodes = document.querySelectorAll('.ae-ui');

let found;
Expand All @@ -116,7 +116,7 @@ if (!CKEDITOR.plugins.get('ae_uicore')) {
}
}, uiTasksTimeout);

editor.on('ariaUpdate', event => {
editor.on('ariaUpdate', (event) => {
// handleAria is debounced function, so if it is being called multiple times, it will
// be canceled until some time passes.
// For that reason here we explicitly append the current message to the list of messages
Expand All @@ -134,7 +134,7 @@ if (!CKEDITOR.plugins.get('ae_uicore')) {
const focusHandler = editable.attachListener(
editable,
'focus',
event => {
(event) => {
focusHandler.removeListener();

editable.attachListener(editable, 'keyup', handleUI);
Expand All @@ -150,10 +150,12 @@ if (!CKEDITOR.plugins.get('ae_uicore')) {
);
});

editor.on('destroy', _event => {
editor.on('destroy', (_event) => {
ariaElement.parentNode.removeChild(ariaElement);

handleUI.detach();
if (handleUI.detach) {
handleUI.detach();
}
});
},

Expand Down

0 comments on commit 9d3ac83

Please sign in to comment.