- 快速入门
- Explore advanced topics
- Accessibility
- Editor control identifiers
- Annotations
- Editor events
- tinymce-AddOnManager
- Boilerplate content CSS
- Handle asynchronous image uploads
- tinymce-Annotator
- tinymce-FocusEvent
- Configuring callbacks for Comments 2-0
- Keyboard shortcuts
- tinymce-CommandEvent
- tinymce-FocusManager
- tinymce-WindowManager
- Toolbar buttons
- PHP image upload handler
- tinymce-ContentEvent
- tinymce-Formatter
- tinymce-dom-DomQuery
- Create a plugin for TinyMCE
- Security
- tinymce-Editor
- tinymce-NotificationManager
- tinymce-dom-DOMUtils
- Create a skin for TinyMCE
- Usage with module loaders
- tinymce-EditorCommands
- tinymce-Plugin
- tinymce-dom-ScriptLoader
- Create custom notifications
- TinyMCE plugin Yeoman generator
- tinymce-EditorManager
- tinymce-ProgressStateEvent
- tinymce-dom-BookmarkManager
- Editor command identifiers
- tinymce-Formatter
- tinymce-EditorObservable
- tinymce-ResizeEvent
- tinymce-dom-ControlSelection
- tinymce
- tinymce-Env
- tinymce-Shortcuts
- tinymce-dom-DomQuery
- tinymce-Event
- tinymce-Theme
- tinymce-dom-DOMUtils
- tinymce-UndoManager
- tinymce-dom-EventUtils
- tinymce-dom-RangeUtils
- tinymce-dom-ScriptLoader
- tinymce-dom-Selection
- tinymce-html-Schema
- tinymce-dom-Serializer
- tinymce-html-Serializer
- tinymce-util-I18n
- tinymce-dom-TreeWalker
- tinymce-html-Styles
- tinymce-util-JSON
- Cloud deployment of plugins Only
- tinymce-editor-ui-registry
- tinymce-html-Writer
- tinymce-util-JSONRequest
- Version compatibility reference
- Image & file upload options
- tinymce-geom-Rect
- tinymce-util-LocalStorage
- Configuration options reference
- Integration and setup options
- tinymce-html-DomParser
- tinymce-util-Observable
- tinymce-util-Observable
- Advanced editing behaviors
- JWT authentication setup
- tinymce-html-Entities
- tinymce-util-URI
- tinymce-util-Tools
- Content appearance options
- Localization options
- tinymce-html-Node
- tinymce-util-Color
- tinymce-util-XHR
- Content filtering options
- Spelling options
- tinymce-html-SaxParser
- tinymce-util-Delay
- Cloud deployment guide
- Content formatting options
- URL handling options
- tinymce-util-EventDispatcher
- Cloud deployment of editor & plugins
- Contribute to documentation
- Examples & demos
- Specify editor & plugin versions
- Contribute to TinyMCE development
- Basic example
- User interface options
- Case Change
- Checklist plugin
- Classic editor example
- Comments 2-0 Demo
- Custom formats example
- Custom menu item
- HTML5 formats example
- Valid elements example
- Custom toolbar button
- Format Painter
- Live example
- Embed rich media
- Full featured example
- Premium features
- Configure Enhanced Media Embed Server
- Server-side component installation
- Custom toolbar menu button
- Image tools example
- Accessibility checking
- Integrate Enhanced Media Embed Server
- Configure server-side components
- Custom toolbar split button
- Inline editor example
- Advanced source code editing
- Format Painter
- Troubleshoot server-side components
- Tiny Drive
- Local upload
- Case Change
- Get TinyMCE bugs fixed
- Professional support
- Distraction-free editor example
- Page Embed plugin
- Checking links as-you-type
- Mentions
- System requirements
- Basic local file picker
- Permanent Pen plugin
- Check Spelling As-You-Type
- Self-hosted file management
- Commenting & collaboration
- URL conversion example
- Adding custom dictionaries
- Page Embed plugin
- Cloud-based file management
- Checklist plugin
- Paste from Word
- Introduction & getting started
- Permanent Pen Plugin
- Advanced installation choices
- Logo & attribution requirements
- Basic setup
- Customizing the editor UI
- TinyMCE distraction-free editing mode
- Filtering TinyMCE content
- Setup inline editing mode
- Rails integration
- Get Support & FAQ
- Work with plugins to extend TinyMCE
- React integration
- Advanced Code Editor plugin
- Localize TinyMCE
- Integrate with other projects
- TinyMCE for Swing integration
- Advanced List plugin
- Code plugin
- Use multiple TinyMCE instances in a single page
- Angular 2+ integration
- Vue integration
- Anchor plugin
- Code Sample plugin
- Check spelling in TinyMCE
- Angular 1 integration
- WordPress integration
- Autolink plugin
- Color Picker plugin
- System requirements
- Bootstrap integration
- Migrating from TinyMCE 4-x to TinyMCE 5-0-
- Autoresize plugin
- Comments 2-0
- Uploading images and files
- Dojo integration
- TinyMCE Mobile
- Autosave plugin
- TinyMCE classic editing mode
- jQuery integration
- BBCode plugin
- Context Menu plugin
- KnockoutJS integration
- Add plugins to TinyMCE
- Case Change
- Directionality plugin
- Accessibility Checker plugin
- Character Map plugin
- Drive plugin
- Checklist plugin
- Emoticons plugin
- Format Painter
- Full Page plugin
- Full Screen plugin
- Link Checker plugin
- Help plugin
- Lists plugin
- Paste plugin
- Horizontal Rule plugin
- Media plugin
- Permanent Pen Plugin
- Table plugin
- Image plugin
- Enhanced Media Embed plugin
- PowerPaste plugin
- Template plugin
- User interface components
- Image Tools plugin
- Mentions plugin
- Preview plugin
- Text Color plugin
- Autocompleter
- Import CSS plugin
- MoxieManager plugin
- Print plugin
- Text Pattern plugin
- Context forms
- Insert Date/Time plugin
- Nonbreaking Space plugin
- Quick Toolbar plugin
- Spell Checker Pro plugin
- Context menu
- Legacy Output plugin
- Noneditable plugin
- Save plugin
- Table of Contents plugin
- Context toolbar
- Link plugin
- Page Break plugin
- Search and Replace plugin
- Visual Blocks plugin
- Custom sidebar
- Page Embed plugin
- Spell Checker plugin
- Visual Characters plugin
- Dialog
- Tab Focus plugin
- Word Count plugin
- Dialog components
- Quick start
- Custom menu items
- Toolbar buttons
- Types of toolbar buttons
Editor events
Editor Events
The following example uses a function to bind a handler to the click event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('click', function (e) {
console.log('Element clicked:', e.target.nodeName);
});
}
});
Event | Native/Core/Plugin | Description |
---|---|---|
Click | native | Fires when the editor is clicked. |
DblClick | native | Fires when the editor is double-clicked. |
MouseDown | native | Fires when the mouse button is pressed down inside the editor. |
MouseUp | native | Fires when a mouse button is released inside the editor. |
MouseMove | native | Fires when the mouse is moved within the editor. |
MouseOver | native | Fires when a new element is being hovered within the editor. |
MouseOut | native | Fires when an element is no longer being hovered within the editor. |
MouseEnter | native | Fires when the mouse enters the editor. |
MouseLeave | native | Fires when the mouse leaves the editor. |
KeyDown | native | Fires when a key is pressed within the editor. |
KeyPress | native | Fires when a key is pressed within the editor. |
KeyUp | native | Fires when a key is released within the editor. |
ContextMenu | native | Fires when the context menu is invoked within the editor. |
Paste | native | Fires when a paste is done within the editor. |
Init | core | Fires when the editor is initialized. |
Focus | core | Fires when the editor is focused. |
Blur | core | Fires when the editor is blurred. |
BeforeSetContent | core | Fires before the content is set to the editor. |
SetContent | core | Fires after the content is set to the editor. |
GetContent | core | Fires after the content is extracted from the editor. |
PreProcess | core | Fires when the contents in the editor are being serialized. |
PostProcess | core | Fires when the contents in the editor are being serialized. |
NodeChange | core | Fires when selection inside the editor is changed. |
Undo | core | Fires when the contents have been reverted to a previous state. |
Redo | core | Fires to revert the effects of an Undo event. |
Change | core | Fires when undo level is added to the editor. |
Dirty | core | Fires when editor contents are being considered dirty. |
Remove | core | Fires when the editor is removed. |
ExecCommand | core | Fires after a command has been executed. |
PastePreProcess | paste | Fires when contents are pasted into the editor. |
PastePostProcess | paste | Fires when contents are pasted into the editor. |
Native means that it’s just a wrapped native browser event.
Core means that it’s a core specific event provided by the editor.
Init
The following example binds a function to the init
event. This event fires when the editor is first initialized.
tinymce.init({
selector: 'textarea',
setup: function (editor) {
editor.on('init', function (e) {
console.log('Editor was initialized.');
});
}
});
Focus
This event fires when the editor is focused.
The following example listens for a focus event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('focus', function (e) {
console.log('Editor got focus!');
});
}
});
Blur
This event fires when the editor is blurred but not when the focus is moved to the editor’s UI components.
The following example listens for blur events.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('blur', function (e) {
console.log('Editor was blurred!');
});
}
});
BeforeSetContent
This event fires before content is inserted into the editor.
Parameters
- content
String
- The HTML content inserted into the editor. - selection
Boolean
- True or False if the content was inserted at selection or replaced all content.
The following example alters the content before inserting into the editor.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('BeforeSetContent', function (e) {
e.content += 'My custom content!';
});
}
});
SetContent
This event fires after content is inserted into the editor.
Parameters
- content
String
- The HTML content inserted into the editor. - selection
Boolean
- True or False if the content was inserted at selection or replaced all content.
The following example uses the SetContent
event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('SetContent', function (e) {
console.log(e.content);
});
}
});
GetContent
This event fires when content is extracted from the editor.
Parameters
- content
String
- The HTML content extracted from the editor.
The following example uses the GetContent
event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('GetContent', function (e) {
e.content += 'My custom content!';
});
}
});
PreProcess
This event fires when the content inside the editor is serialized to an HTML string.
Parameters
- node
DOMElement
- A clone of the HTML element being serialized.
The following example uses the PreProcess
event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('PreProcess', function (e) {
console.log(e.node);
});
}
});
PostProcess
This event fires when the content inside the editor have been serialized to an HTML string.
Parameters
- content
String
- The HTML content extracted from the editor.
The following example uses the PostProcess
event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('PostProcess', function (e) {
e.content += 'My custom content!';
});
}
});
NodeChange
This event fires when the selection inside the editor is changed.
Parameters
- element
DOMElement
- HTML Element of selection. - parents
[DOMElement]
- Array with parents of the element.
The following example binds the NodeChange
event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('NodeChange', function (e) {
console.log('Node changed');
});
}
});
Undo
This event fires when a request to undo is made.
Parameters
- level
Object
- Undo level object containing content.
The following example binds the Undo
event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('Undo', function (e) {
console.log('User has pressed undo');
});
}
});
Redo
This event fires when a request to redo is made.
Parameters
- level
Object
- Undo level object containing content.
The following example binds the Redo
event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('Redo', function (e) {
console.log('User has pressed redo');
});
}
});
Change
This event fires when changes are made inside the editor that cause an undo level to be added.
The following example listens for editor changes using the Change
event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('Change', function (e) {
console.log('Editor contents was changed.');
});
}
});
Dirty
This event fires when the editor is considered dirty. This state is toggled by using: editor.setDirty(false)
.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('Dirty', function (e) {
console.log('Editor is dirty!');
});
}
});
Remove
This event fires when the editor is removed from a textarea/div.
The following example detects when the editor.remove()
event is called.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('Remove', function (e) {
console.log('The editor has been removed');
});
}
});
ExecCommand
This event fires when a command like Bold/Italic etc is made by the editor.
Parameters
- command
String
- The name of the command that was executed.
The following example detects the execution of the bold feature.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('ExecCommand', function (e) {
if (e.command === 'mceToggleFormat' && e.value === 'bold') {
console.log('Bold was executed')
}
});
}
});
PastePreProcess
This event fires when content from the clipboard is processed by the paste process.
Parameters
- content
String
- The HTML content pasted into the editor.
The following example detects the beginning of the paste event.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('PastePreProcess', function (e) {
e.content = e.content + ' foo';
console.log('The modified pasted content was: ', e.content);
});
}
});
PastePostProcess
This event fires when content from the clipboard is processed by the paste operation.
Parameters
- node
DOMElement
- Node element being pasted.
The following example logs the pasted node.
tinymce.init({
selector: 'textarea',
init_instance_callback: function (editor) {
editor.on('PastePostProcess', function (e) {
console.log(e.node);
});
}
});
Event | Description |
---|---|
AddEditor | Fires when a new editor instance is added. |
RemoveEditor | Fires when an editor instance is removed. |
AddEditor
This event fires when an editor instance is created and added to the EditorManager
collection.
Parameters
- editor
tinymce.Editor
- Editor instance being added.
The following example listens for editor instances being created.
tinymce.on('AddEditor', function (e) {
console.log('Added editor with id: ' + e.editor.id);
});
RemoveEditor
This event fires when editor instances are removed from the target textarea/div.
Parameters
- editor
tinymce.Editor
- Editor instance being removed.
The following example listens for editor instances being removed.
tinymce.on('RemoveEditor', function (e) {
console.log('Removed editor with id: ' + e.editor.id);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论