layout | title | title_nav | description | keywords |
---|---|---|---|---|
default |
Migrating from TinyMCE 4 to TinyMCE 5. |
Migrating from TinyMCE 4 |
Guidance for migrating from TinyMCE 4 to TinyMCE 5. |
migration considerations premigration pre-migration |
Most configuration changes in TinyMCE 5 only affect complex use cases, such as customized user interface components. The process for setting up a basic TinyMCE 5 instance is the same as TinyMCE 4.
This chapter describes the migration process and workarounds for customers using TinyMCE 4. It describes the settings that require updating prior to migration; and workaround procedures for deprecated, deleted, and updated features.
Note: For support related to migration, please contact Tiny support. Open Source users: Please report issues on the TinyMCE GitHub Repository.
To migrate the core TinyMCE editor to TinyMCE 5, review the following sections:
- Cloud Delivery.
- Editor: Changes to Methods.
- Editor: Changes to Settings.
- Browser support: backward compatibility or quirks mode.
To use TinyMCE 5 from the {{site.cloudname}}, include this script in your HTML page. Replace 'no-api-key' with your API key.
<script src="{{ site.cdnurl }}" referrerpolicy="origin"></script>
For information on using the latest development and testing builds, see: Cloud deployment guide - Specify editor & plugin versions.
All TinyMCE 4 API methods for creating UI components have been removed. New methods have been added for TinyMCE 5. For information on creating and customizing UI components, see: User interface components.
TinyMCE 5 includes the following changes to editor-core settings:
Setting | Description |
---|---|
custom_colors |
custom_colors is true by default. Setting custom_colors: false removes the custom color picker in the color swatch. |
Setting | TinyMCE 4 | TinyMCE 5 |
---|---|---|
height |
Set the height of the editable area of the editor. Supported number values. |
Sets the overall height of the editor, including the menubar, toolbars, and statusbar. Supports numbers and strings. Assumes strings are a valid CSS value for height. |
width |
Supported number values. | Supports numbers and strings. Assumes strings are a valid CSS value for width. |
resize |
true by default. |
true by default if the autoresize plugin is not enabled.false by default if the autoresize plugin is enabled. |
-
The
file_browser_callback
option has been removed for TinyMCE 5. Thefile_browser_callback
option was used to add a file or image browser to TinyMCE. This option was deprecated in version 4.1.0 and replaced byfile_picker_callback
. -
insert_button_items
- theinsert_button_items
option was used to specify the toolbar items to display in theinsert
toolbar button menu. This toolbar button has been removed from TinyMCE 5. For a workaround, configure a custom toolbar button using the following configurations in thetinymce.init
:
tinymce.init({
...
toolbar: 'insert',
setup: function (editor) {
editor.ui.registry.addMenuButton('insert', {
icon: 'plus',
tooltip: 'Insert',
fetch: (callback) => callback('image link | inserttable')
});
}
});
file_picker_callback
provides a callback function, removing the requirement for an additional function to manually find and update the element or fire events. file_picker_callback
can also update other fields by passing a second argument to update other fields in the dialog. For information on using file_picker_callback
, see: Image & file upload options - file_picker_callback
.
The following example shows the difference between the removed file_browser_callback
setting and file_picker_callback
, assuming that browseFiles
is a function that opens an external file picker.
tinymce.init({
...
file_browser_callback_types: 'file image media',
file_browser_callback: function (fieldId, value, type, win) {
browseFiles(value, type, function (fileUrl) {
win.document.getElementById(fieldId).value = fileUrl;
});
}
});
tinymce.init({
...
file_picker_types: 'file image media',
file_picker_callback: function (callback, value, meta) {
browseFiles(value, meta.filetype, function (fileUrl) {
callback(fileUrl);
});
}
});
TinyMCE 5 does not support browsers running in Quirks or backward compatibility modes.
New platform detection functions were to the Env
API for {{site.productname}} 5.1, allowing for some older detection properties to be deprecated.
Deprecated Property | Alternative Property / Reason for Deprecation | Type | Original Description |
---|---|---|---|
opera |
Use browser.isOpera() instead. |
Boolean | Constant that is true if the browser is Opera. |
webKit |
Use browser.isSafari() or browser.isChrome() instead. |
Boolean | Constant that is true if the browser is WebKit (Safari/Chrome). |
ie |
Use browser.version.major and browser.isIE() or browser.isEdge() instead. |
Number | Constant that is greater than zero if the browser is IE. |
gecko |
Use browser.isFirefox() instead. |
Boolean | Constant that is true if the browser is Gecko. |
mac |
Use os.isOSX() or os.isiOS() instead. |
Boolean | Constant that is true if the operating system is Mac OS. |
iOS |
Use os.isiOS() instead. |
Boolean | Constant that is true if the operating system is iOS. |
android |
Use os.isAndroid() instead. |
Boolean | Constant that is true if the operating system is android. |
desktop |
Use deviceType.isDesktop() instead. |
Boolean | Constant that is true if the browser is running on a desktop device |
contentEditable |
All supported browsers now support content editable elements. | Boolean | Constant that is true if the browser supports editing. |
caretAfter |
All supported browsers now support placing carets after inline blocks. | Boolean | Returns true /false if the browser can or can't place the caret after a inline block like an image. |
range |
All supported browsers now support native DOM ranges. | Boolean | Constant that is true if the browser supports native DOM Ranges. IE 9+. |
ceFalse |
All supported browsers now support contentEditable=false regions. |
Boolean | Constant that is true if the browser supports contentEditable=false regions. |
Most themes provided with TinyMCE 4 have been removed from TinyMCE 5 and are now combined in a new responsive theme called Silver. The Silver
theme is enabled by default and contains a set of configurable UI components that can be used to replace the functionality of the TinyMCE 4 themes: Modern, Inline, and Inlite.
Removed Theme | Replaced by |
---|---|
Modern | Silver |
Modern inline | Silver Inline |
Inlite(Distraction-free Editor) | Silver (distraction-free configuration) |
Mobile | Silver (responsive to small screen touch devices) |
The Inlite theme has been removed from TinyMCE 5.
The Inlite theme features are provided by the Quick Toolbar (quickbars
) plugin for TinyMCE 5. The Inlite quicklink
functionality is now provided by Context Forms.
The following is an example of a TinyMCE 5 quickbars configuration:
{
theme: 'silver',
inline: true,
toolbar: false,
menubar: false,
plugins: [ 'quickbars' ]
}
This will provide a similar but improved distraction-free experience in TinyMCE 5.
The Modern theme has been removed from TinyMCE 5. The Modern theme's UI library tinymce.ui.*
has also been removed. This change may impact integrations depending upon the level of customization.
Removed event | Description |
---|---|
BeforeRenderUi | Fired before the UI was rendered. |
The {{site.productname}} 4 Mobile theme was deprecated in {{site.productname}} 5.1. The mobile-optimized editor is loaded on mobile devices. For information on the new mobile experience, see: {{site.productname}} mobile.
This section covers migrating UI components to TinyMCE 5
- Removed UI configuration settings
- Changed UI API method namespace
- Custom toolbar buttons
- Custom context toolbars
- Custom menu items
- Custom dialogs
- Custom URL dialogs
All inline style configurations have been removed in TinyMCE 5 in favor of modern CSS. This affects all TinyMCE 4 UI component configurations. Skins should be used for custom styling in TinyMCE 5.
Removed style settings:
flex
border
layout
- Use the TinyMCE 5 UI component settings to compose a custom layout.spacing
padding
align
pack
no-wrap
The API methods for registering UI components have moved. They are now part of tinymce.editor.ui.registry
.
The following methods have changed for TinyMCE 5:
The following new methods have been added for creating and using new components:
New method | Description |
---|---|
editor.ui.registry.addAutocompleter: (name, spec) |
Autocompleter |
editor.ui.registry.addContextForm: (name, spec) |
Context form |
editor.ui.registry.addContextMenu: (name, spec) |
Context menu |
editor.ui.registry.addMenuButton: (name, spec) |
Menu Button |
editor.ui.registry.addNestedMenuItem: (name, spec) |
Nested menu item |
editor.ui.registry.addSplitButton: (name, spec) |
Split Button |
editor.ui.registry.addToggleButton: (name, spec) |
Toggle Button |
editor.ui.registry.addToggleMenuItem: (name, spec) |
Toggle menu item |
editor.ui.registry.addIcon: (name, svgData) |
Registers an SVG as an icon |
editor.ui.registry.getAll: () |
Returns an array of everything in the UI registry |
The API methods for adding Custom toolbar buttons have changed for TinyMCE 5. The methods have been moved from editor.*
to editor.ui.registry.*
. The toolbar button type listbox
has been removed and a toogle button type has been added. The button types available in TinyMCE 5 are:
Listbox toolbar buttons are not supported in TinyMCE 5. The recommended replacement toolbar button type is the Split button.
The following methods for creating custom toolbar buttons have been moved for TinyMCE 5. For information on how to use the new methods, see: Toolbar buttons.
Old method | New method |
---|---|
editor.addButton() |
editor.ui.registry.addButton() |
editor.addMenuItem() |
editor.ui.registry.addMenuItem() |
New methods have been added for creating common types of toolbar buttons.
New method | Description |
---|---|
editor.ui.registry.addToggleButton() |
Adds a custom toolbar toggle button. |
editor.ui.registry.addSplitButton() |
Adds a custom toolbar split button. |
editor.ui.registry.addMenuButton() |
Adds a custom toolbar menu button. |
For information on how to use these methods, see: Types of toolbar buttons.
Old method | New method | Description |
---|---|---|
onclick |
onAction |
onclick is now onAction . onAction now has an API to provide helper functions to the user. For an example migration, see: Migrating onclick to onAction. |
cmd |
onAction |
cmd has been removed as a configuration option. Commands should be executed through onAction now. For an example migration, see: Migrating cmd to onAction. |
onpostrender |
onSetup |
onpostrender has been replaced with onSetup . For an example migration, see: Migrating onpostrender to onSetup. |
onclick
is now onAction
. The callback function given to onAction
takes a buttonApi
argument which is an object that contains helper functions.
For example:
editor.addButton('mybutton', {
text: "My Button",
onclick: () => alert("My Button clicked!")
});
editor.ui.registry.addButton('myButton', {
text: 'My Button',
onAction: (buttonApi) => alert('My Button clicked!')
});
Each type of toolbar button has a different set of API functions. For information using toolbar buttons, see: Types of toolbar buttons.
cmd: string
has been removed. Commands should be executed using onAction
instead.
For example:
editor.addButton('mybutton', {
text: "My Button",
cmd: 'mceSave'
});
editor.ui.registry.addButton('myButton', {
text: 'My Button',
onAction: (_) => editor.execCommand('mceSave')
});
onpostrender
has been replaced with onSetup
for menu and toolbar components.
There are 3 major changes:
onpostrender
was only processed when the editor was created,onSetup
runs every time a component is rendered. For example:onSetup
for a menu item is processed every time the menu rendered.onSetup
has an API containing helper functions. Each type of toolbar button has a different API.onSetup
can be configured to return a function, which will be automatically be called on the teardown of the component, such as when a menu item's menu is closed.- If a function should only be executed when the editor is first initialized, use the
editor.on('init', callback)
callback function.
- If a function should only be executed when the editor is first initialized, use the
Caution: If
onSetup
listens to any events usingeditor.on(eventName, callback)
, it should return aeditor.off(eventName, callback)
callback to unbind the event on tear down. Unless the event was'init'
,onSetup
returns(buttonApi) => ed.off(eventName, callback)
.
For example:
editor.addButton('currentdate', {
icon: 'insertdatetime',
tooltip: "Insert Current Date",
onclick: insertDate,
onpostrender: function monitorNodeChange() {
var btn = this;
editor.on('NodeChange', function(e) {
btn.disabled(e.element.nodeName.toLowerCase() == 'time');
});
}
});
In this example, the button's API contains isDisabled: () => boolean
and setDisabled: (state: boolean) => void
.
editor.ui.registry.addButton('customDateButton', {
icon: 'insert-time',
tooltip: 'Insert Current Date',
disabled: true,
onAction: (_) => editor.insertContent(toTimeHtml(new Date())),
onSetup: (buttonApi) => {
const editorEventCallback = (eventApi) => buttonApi.setDisabled(eventApi.element.nodeName.toLowerCase() === 'time');
editor.on('NodeChange', editorEventCallback);
return (buttonApi) => editor.off('NodeChange', editorEventCallback);
}
});
Note: The callback function given to
onSetup
takes abuttonApi
argument which is an object that contains helper functions.
The Context Toolbar accepts toolbar buttons to the editor using the addButton
, addToggleButton
, addSplitButton
, or addMenuButton
functions.
The API method for creating custom context toolbars in TinyMCE 5 has changed from editor.addContextToolbar()
to editor.ui.registry.addContextToolbar()
.
For information on Context Toolbars, see: Context toolbar.
The following configuration options have changed in the custom menu items for TinyMCE 5:
addMenuItem
has a new configuration.- A new method,
addNestedMenuItem
has been added to the options. TheaddNestedMenuItem
is a method for creating menu items that have a sub-menu with one or more menu items. - A new method,
addToggleMenuItem
has been added to the options. TheaddToggleMenuItem
is a method for creating toggle menu items similar to the toggle toolbar button. - The concept of
context
has been removed from menu item configurations. Themenu
setting provides this functionality for TinyMCE 5.
To add a custom item to a menu, use the menu
setting. All items in a menu need to be declared in order to appear.
For example:
tinymce.init({
selector: '#editor',
plugins: 'help',
menu: {
help: { title: 'Help', items: 'help | myCustomMenuItem' }
},
menubar: 'file edit help',
setup: (editor) => {
editor.ui.registry.addMenuItem('myCustomMenuItem', {
text: 'My Custom Menu Item',
onAction: () => alert('Menu item clicked')
});
}
});
More information
- For information on using the
menu
setting, see: User interface options - menu. - For an example of the default menu items, see: User interface options - Example: The TinyMCE Default Menu Items.
- For a list of the available menu controls provided by TinyMCE and the Tiny Premium Plugins, see: Editor control identifiers - Menu controls.
New method | Description |
---|---|
editor.ui.registry.addNestedMenuItem() |
Adds a menu item that opens a sub-menu. |
editor.ui.registry.addToggleMenuItem() |
Adds a custom toggle menu item. |
Old method | New method | Description |
---|---|---|
editor.addMenuItem: (name, spec) |
editor.ui.registry.addMenuItem() |
Adds a custom basic menu item. |
The following examples show custom menu item configurations in TinyMCE 4 and TinyMCE 5:
editor.addMenuItem('example', {
text: 'My menu item',
context: 'tools',
onclick: () => editor.insertContent('Hello world!!');
});
editor.ui.registry.addMenuItem('example', {
text: 'My menu item',
onAction: () => editor.insertContent('Hello world!!');
});
For information on how to use these methods, see: Custom menu items.
Dialogs are still opened using the editor.windowManager.open(config)
api, however a number of configuration options have changed.
Removed setting | Description |
---|---|
height |
The dialog component now uses CSS3 and a predefined small , medium , and large template to specify the dimensions. |
width |
The dialog component now uses CSS3 and a predefined small , medium , and large template to specify the dimensions. |
bodyType |
bodyType has been merged into the body setting. |
onpostrender |
onpostrender has been removed for the dialog configuration. The dialog configuration now includes an initialData setting for providing the initial state and an API to fetch or update the data. Refer to this section for more information on how to configure initialData . |
url |
URL dialogs now have their own API. For more information, see Custom URL dialogs . |
New setting | Description |
---|---|
initialData |
An object containing the initial value for the dialog components. |
onCancel |
A callback that is called when the dialog is cancelled without submitting any changes. |
onTabChange |
A callback that is called when switching tabs in a TabPanel. |
Old setting | New setting | Description |
---|---|---|
onchange |
onChange |
onChange now takes a callback function which is passed an API helper function and data. |
Note: The
onchange
callback function provided within individual components has been removed. A singleonChange
callback function provides the same functionality for all components in TinyMCE 5.
const config = {
title: 'Insert Link',
body: [
{
name: 'text',
type: 'textbox',
size: 40,
label: 'Text to display',
onchange () {
data.text = this.value();
}
}
]
};
const config = {
title: 'Insert Link',
body: {
type: 'panel',
items: [
{
name: 'text',
type: 'input',
label: 'Text to display'
}
]
},
onChange (api, changeData) {
if (changeData.name === 'text') {
// Do something with the text to display changes
}
}
};
For information about the new dialog configuration, see the Dialog and Dialog components documentation.
A redesign of the dialog API resulted in the following changes:
API | Type | Description |
---|---|---|
tinymce.WindowManager.getParams() |
Method | Returned the params of the last window open call. This was used in iframe based dialog to get params passed from the tinymce plugin. |
tinymce.WindowManager.getWindows() |
Method | Returned the currently opened window objects. |
tinymce.WindowManager.setParams() |
Method | Set the params of the last opened window. |
tinymce.WindowManager.windows |
Property | Returned an array of opened dialogs. |
Method | Description | Change |
---|---|---|
tinymce.WindowManager.alert() |
Creates an alert dialog. | A window object is no-longer returned. |
tinymce.WindowManager.confirm() |
Creates a "confirm" dialog. | A window object is no-longer returned. |
tinymce.WindowManager.close() |
Closes the top most window. | Only closes dialogs created with open() . |
For information on the new Dialog API, see: UI components - Dialog instance API.
The URL dialogs have moved from the editor.windowManager.open()
API to the editor.windowManager.openUrl()
API. This provides clear separation of the two different types of dialogs in TinyMCE.
Old setting | New setting | Description |
---|---|---|
file |
url |
The file setting has been removed in TinyMCE 5 and replaced with url . |
New setting | Description |
---|---|
onCancel |
A callback that is called when the dialog is cancelled without submitting any changes. |
onMessage |
A callback that is called when the dialog receives a message via the browser window.postMessage API. |
editor.windowManager.open({
title: 'URL Dialog Demo',
url: 'http://mysite.com/external-page.html'
});
editor.windowManager.openUrl({
title: 'URL Dialog Demo',
url: 'http://mysite.com/external-page.html'
});
For information about the new URL dialog configuration, see: URL dialog.
The following section covers the changed and removed plugin features for TinyMCE 5.
The height
and width
settings have been removed from plugin dialogs. The dialog component now uses CSS3 and a predefined small
, medium
, and large
template to specify the dimensions.
The following plugins from TinyMCE 4 do not require height or width options in TinyMCE 5:
TinyMCE 4 | TinyMCE 5 |
---|---|
autoresize_min_height |
min_height |
autoresize_max_height |
max_height |
textcolor_cols |
color_cols |
textcolor_map |
color_map |
These features have either changed or have been deleted in TinyMCE 5.
Plugin name | Description |
---|---|
ContextMenu | New API. See the docs. |
ColorPicker | Moved to the core. See the docs. |
TextColor | The textcolor plugin was removed and this setting is has been replaced by text_color in TinyMCE 5. |
The Context menus are part of the core and enabled by default in TinyMCE 5. TinyMCE 5 supports adding registered menu items and allows plugins to register "sections" of the context menu. These sections show or hide depending on the cursor position when the context menu is opened.
For information on using context menus and the default context menu configuration, see: UI components - Context menu.
New method | Description |
---|---|
editor.ui.registry.addContextMenu() |
Adds a custom context menu. |
For information on Context Menus, see UI components - Context menu.
spellchecker_callback
has been updated to remove a legacy format for the success
callback, which accepted a mapping object of misspelled words to suggestions. For example:
spellchecker_callback: function(method, text, success, failure) {
var words = text.match(this.getWordCharPattern());
if (method == "spellcheck") {
var suggestions = {};
for (var i = 0; i < words.length; i++) {
suggestions[words[i]] = ["First", "Second"];
}
success(suggestions);
}
}
The success
callback now requires the mapping object to be wrapped in an object with the words
key, such as:
spellchecker_callback: function(method, text, success, failure) {
var words = text.match(this.getWordCharPattern());
if (method == "spellcheck") {
var suggestions = {};
for (var i = 0; i < words.length; i++) {
suggestions[words[i]] = ["First", "Second"];
}
success({ words: suggestions });
}
}
For information on the spellchecker_callback
setting, see: Spell Checker plugin - spellchecker_callback
Changes between TinyMCE 4 and TinyMCE 5:
-
The text field for Styles have been removed from the advanced tab of the dialogs. This simplifies the dialogs for users and gives the editor a stricter control over the table styles, which ensures that the styles are valid.
-
When opening a properties dialog with a single table, row, or cell selected, the dialog will autofill with the relevant existing values. When multiple rows or cells are selected:
- If the selected rows or cells have the same values, TinyMCE 5 automatically fills the dialog values.
- If the fields have no existing value or have different values, the dialog fields are left empty.
-
The
Border
input field in the table properties dialog is now calledBorder width
.