Skip to content

Commit

Permalink
Add IE check for IE fix (#12234)
Browse files Browse the repository at this point in the history
* Add IE check

* typo
  • Loading branch information
ellatrix committed Nov 23, 2018
1 parent f4fc47e commit bd897f6
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions packages/editor/src/components/rich-text/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { diffAriaProps, pickAriaProps } from './aria';

const { getSelection } = window;
const { TEXT_NODE } = window.Node;
const { userAgent } = window.navigator;

/**
* Zero-width space character used by TinyMCE as a caret landing point for
Expand All @@ -34,23 +35,6 @@ const { TEXT_NODE } = window.Node;
*/
export const TINYMCE_ZWSP = '\uFEFF';

/**
* Determines whether we need a fix to provide `input` events for contenteditable.
*
* @param {Element} editorNode The root editor node.
*
* @return {boolean} A boolean indicating whether the fix is needed.
*/
function needsInternetExplorerInputFix( editorNode ) {
return (
// Rely on userAgent in the absence of a reasonable feature test for contenteditable `input` events.
/Trident/.test( window.navigator.userAgent ) &&
// IE11 dispatches input events for `<input>` and `<textarea>`.
! /input/i.test( editorNode.tagName ) &&
! /textarea/i.test( editorNode.tagName )
);
}

/**
* Applies a fix that provides `input` events for contenteditable in Internet Explorer.
*
Expand Down Expand Up @@ -113,6 +97,14 @@ function applyInternetExplorerInputFix( editorNode ) {
}

const IS_PLACEHOLDER_VISIBLE_ATTR_NAME = 'data-is-placeholder-visible';

/**
* Whether or not the user agent is Internet Explorer.
*
* @type {boolean}
*/
const IS_IE = userAgent.indexOf( 'Trident' ) >= 0;

export default class TinyMCE extends Component {
constructor() {
super();
Expand Down Expand Up @@ -247,6 +239,7 @@ export default class TinyMCE extends Component {
// In IE11, focus is lost to parent after initialising
// TinyMCE, so we have to set it back.
if (
IS_IE &&
document.activeElement !== this.editorNode &&
document.activeElement.contains( this.editorNode )
) {
Expand Down Expand Up @@ -275,7 +268,7 @@ export default class TinyMCE extends Component {
this.removeInternetExplorerInputFix = null;
}

if ( editorNode && needsInternetExplorerInputFix( editorNode ) ) {
if ( IS_IE ) {
this.removeInternetExplorerInputFix = applyInternetExplorerInputFix( editorNode );
}
}
Expand Down

0 comments on commit bd897f6

Please sign in to comment.