# SunEditor
Vanilla javascript based WYSIWYG web editor, with no dependencies.
SunEditor supports IE11 and all modern browsers with no dependencies and polyfill.
Coded based on ES5 in supported by IE11.
#### Demo : suneditor.com
[](https://github.com/JiHong88/SunEditor/blob/master/LICENSE.txt)
[](https://github.com/JiHong88/SunEditor/releases)
[](https://www.npmjs.com/package/suneditor)
[](https://github.com/JiHong88/SunEditor/releases/latest)
[](https://www.jsdelivr.com/package/npm/suneditor)
[](https://www.npmjs.com/package/suneditor)

> The Suneditor is a lightweight, flexible, customizable WYSIWYG text editor for your web applications.
> - Pasting from Microsoft Word and Excel.
> - Custom table selection, merge and split.
> - Media embed, images upload.
> - Can use CodeMirror, KaTeX.
> - And.. many other features :)

## Table of contents
- [Browser Support](#browser-support)
- [Install](#install)
- [Getting Started](#getting-started)
- [When inserting custom tags in the editor](#when-inserting-custom-tags-in-the-editor)
- [Use import statement](#use-import-statement)
- [Load only what you want](#1-load-only-what-you-want)
- [Load all plugins](#2-load-all-plugins)
- [Plugins can be used directly in the button list](#3-plugins-can-be-used-directly-in-the-button-list)
- [Init function](#init-function)
- [Use CodeMirror](#use-codemirror)
- [Use KaTeX (math plugin)](#use-katex-math-plugin)
- [Options](#options)
- [Functions](#functions)
- [Plugins list](#plugins-list)
- [Examples](#examples)
- [Options template](#options-template)
- [Custom plugins](#custom-plugins)
- [Document](#document)
- [Other libraries using SunEditor](#other-libraries-using-sunEditor)
- [suneditor-react](#lib-suneditor-react)
- [angular-suneditor](#lib-angular-suneditor)
- [Using SunEditor with Livewire & Alpine.JS](#lib-livewire-alpine)
- [Plugin for Pluxml](#lib-pluxml)
- [AEM-SunEditor](#lib-aem-suneditor)
- [License](#license)
#### Browser Support
|
Chrome |
Firefox |
Opera |
Safari |
Edge |
Internet Explorer |
|:---:|:---:|:---:|:---:|:---:|:---:|
| Yes | Yes | Yes | Yes | Yes | 11+ |
## Install
#### Npm
``` sh
$ npm install suneditor --save
```
#### Bower
``` sh
$ bower install suneditor --save
```
#### CDN
``` html
```
[jsdelivr/suneditor](https://www.jsdelivr.com/package/npm/suneditor)
## Getting Started
### 1. Target Element
```html
```
### 2. Create
```javascript
/**
* ID : 'suneditor_sample'
* ClassName : 'sun-eidtor'
*/
// ID or DOM object
const editor = SUNEDITOR.create((document.getElementById('sample') || 'sample'),{
// All of the plugins are loaded in the "window.SUNEDITOR" object in dist/suneditor.min.js file
// Insert options
// Language global object (default: en)
lang: SUNEDITOR_LANG['ko']
});
```
### 3. Contents display
```java
When you display a document created by suneditor
You need to include "src/assets/css/suneditor-contents.css" or "dist/css/suneditor.min.css" file.
Then add "sun-editor-editable" to the class name of the Tag element that displays the content.
If you are using RTL mode, you also need to add "se-rtl".
In "suneditor-contents.css", you can define the style of all the tags created in suneditor.
```
## When inserting custom tags in the editor
```text
- Empty tags without meaning or tags that do not fit the editor's format are modified or deleted.
Tags with the class name "se-component" or "__se__tag" of the top-level tag will not be deleted.
"se-component" is the component type of the editor.
Class name for wrapper tags such as images and videos.
```
## Use import statement
### 1. Load only what you want
```javascript
import 'suneditor/dist/css/suneditor.min.css'
// import 'suneditor/assets/css/suneditor.css'
// import 'suneditor/assets/css/suneditor-contents.css'
import suneditor from 'suneditor'
// How to import plugins
import image from 'suneditor/src/plugins/dialog/link'
import list from 'suneditor/src/plugins/submenu/list'
import {font, video} from 'suneditor/src/plugins'
// How to import language files (default: en)
import lang from 'suneditor/src/lang'
import {ko} from 'suneditor/src/lang'
import de from 'suneditor/src/lang/de'
suneditor.create('sample', {
plugins: [font, video, image, list],
buttonList: [
['font', 'video', 'image', 'list']
],
lang: lang.ko
});
```
### 2. Load all plugins
```javascript
import 'suneditor/dist/css/suneditor.min.css'
import suneditor from 'suneditor'
import plugins from 'suneditor/src/plugins'
suneditor.create('sample', {
plugins: plugins,
buttonList: [
['undo', 'redo'],
['font', 'fontSize', 'formatBlock'],
['paragraphStyle', 'blockquote'],
['bold', 'underline', 'italic', 'strike', 'subscript', 'superscript'],
['fontColor', 'hiliteColor', 'textStyle'],
['removeFormat'],
'/', // Line break
['outdent', 'indent'],
['align', 'horizontalRule', 'list', 'lineHeight'],
['table', 'link', 'image', 'video', 'audio' /** ,'math' */], // You must add the 'katex' library at options to use the 'math' plugin.
/** ['imageGallery'] */ // You must add the "imageGalleryUrl".
['fullScreen', 'showBlocks', 'codeView'],
['preview', 'print'],
['save', 'template'],
/** ['dir', 'dir_ltr', 'dir_rtl'] */ // "dir": Toggle text direction, "dir_ltr": Right to Left, "dir_rtl": Left to Right
]
})
// You can also load what you want
suneditor.create('sample', {
plugins: [plugins.font],
// Plugins can be used directly in the button list
buttonList: [
['font', plugins.image]
]
})
```
### 3. Plugins can be used directly in the button list
```javascript
import 'suneditor/dist/css/suneditor.min.css'
import suneditor from 'suneditor'
import {align, font, fontSize, fontColor, hiliteColor,
horizontalRule, image, template} from 'suneditor/src/plugins'
suneditor.create('sample', {
buttonList: [
['undo', 'redo', 'removeFormat'],
[align, font, fontSize, fontColor, hiliteColor],
[horizontalRule, image, template]
],
})
```
## Init function
```text
The init function can be used by predefining options and calling the create function on the returned object.
The value of the option argument put in the "create" function call takes precedence
```
```javascript
import 'suneditor/dist/css/suneditor.min.css'
import suneditor from 'suneditor'
import plugins from 'suneditor/src/plugins'
// all plugins
const initEditor = suneditor.init({
plugins: plugins,
height: 200,
buttonList: [
[
'undo', 'redo',
'font', 'fontSize', 'formatBlock',
'paragraphStyle', 'blockquote',
'bold', 'underline', 'italic', 'strike', 'subscript', 'superscript',
'fontColor', 'hiliteColor', 'textStyle',
'removeFormat',
'outdent', 'indent',
'align', 'horizontalRule', 'list', 'lineHeight',
'table', 'link', 'image', 'video', 'audio', /** 'math', */ // You must add the 'katex' library at options to use the 'math' plugin.
/** 'imageGallery', */ // You must add the "imageGalleryUrl".
'fullScreen', 'showBlocks', 'codeView',
'preview', 'print', 'save', 'template',
/** 'dir', 'dir_ltr', 'dir_rtl' */ // "dir": Toggle text direction, "dir_ltr": Right to Left, "dir_rtl": Left to Right
]
]
});
initEditor.create('sample_1', {
// The value of the option argument put in the "create" function call takes precedence
});
initEditor.create('sample_2', {
// The value of the option argument put in the "create" function call takes precedence
height: 'auto',
buttonList: [
['bold', 'underline', 'italic'],
['removeFormat'],
['preview', 'print']
]
});
```
## Use CodeMirror
```html
```
```javascript
import 'suneditor/dist/css/suneditor.min.css'
import suneditor from 'suneditor'
// Import codeMirror
import CodeMirror from 'codemirror'
import 'codemirror/mode/htmlmixed/htmlmixed'
import 'codemirror/lib/codemirror.css'
suneditor.create('sample', {
codeMirror: CodeMirror // window.CodeMirror,
// Set options
// codeMirror: {
// src: CodeMirror,
// options: {...}
// }
buttonList: [
['codeView']
],
height: 400
});
```
## Use KaTeX (math plugin)
```html
```
```javascript
import 'suneditor/dist/css/suneditor.min.css'
import suneditor from 'suneditor'
// Import katex
import katex from 'katex'
import 'katex/dist/katex.min.css'
suneditor.create('sample', {
katex: katex // window.katex,
// Set options
// katex: {
// src: katex,
// options: {...}
// }
buttonList: [
['math']
]
});
```
## Options
```java
plugins: [
/** command */
blockquote,
/** Submenu */
align,
font,
fontColor,
fontSize,
formatBlock,
hiliteColor,
horizontalRule,
lineHeight,
list,
paragraphStyle,
table,
template,
textStyle,
/** Dialog */
image,
link,
video,
audio,
math, // You must add the 'katex' library at options to use the 'math' plugin.
/** File browser */
// You must add the "imageGalleryUrl".
// A button is added to the image modal.
// You can also use image gallery by adding it directly to the button list. (You must add "image" plugin.)
imageGallery
]
: Plugins array. default: null {Array}
// * Custom options and default options are all treated the same.
// * When using a custom plugin and a default plugin together, register as follows.
// * {custom_plugin, ...plugins}
// Values
strictMode : Option to disable clean mode, which checks the styles, classes, etc. of the editor content. default : false {Boolean}
strictHTMLValidation : Enforces strict HTML validation based on the editor`s policy. Applies to methods like setContents to ensure content compliance when enabled. default: false {Boolean}
lang : language object. default : en {Object}
defaultTag : Specifies default tag name of the editor. default: 'p' {String}
textTags : You can change the tag of the default text button. default: { bold: 'STRONG', underline: 'U', italic: 'EM', strike: 'DEL' }
ex) {
bold: 'b',
strike: 's'
}
value : Initial value(html string) of the edit area.
If not, the value of the "target textarea". default: null {String}
allowedClassNames : Specifies the allowed class name, It can be specified in the form of a regular expression.
Appended before the "default" value. (`${option}|${defaultValue}`) default: '^se-|__se__|katex';
historyStackDelayTime : When recording the history stack, this is the delay time(miliseconds) since the last input. default: 400 {Number}
frameAttrbutes : Specifies the properties of the editing area DIV. default: {} {Object}
ex) {
"spellcheck": false
}
// Whitelist, Blacklist -----------------------------------------------------------------------------------------
// (You can use regular expression syntax.)
// _defaultTagsWhitelist : 'br|p|div|pre|blockquote|h1|h2|h3|h4|h5|h6|ol|ul|li|hr|figure|figcaption|img|iframe|audio|video|table|thead|tbody|tr|th|td|a|b|strong|var|i|em|u|ins|s|span|strike|del|sub|sup|code|svg|path|details|summary'
addTagsWhitelist : Add tags to the default tags whitelist of editor. default: '' {String}
ex) 'mark|canvas|label|select|option|input|//' // "//" This means HTML comments.
ex) '*' // This means all tags are allowed. (Not available on "blacklist")
tagsBlacklist : Blacklist of the editor default tags. default: null {String}
ex) 'h1|h2'
// _editorTagsWhitelist : _defaultTagsWhitelist + addTagsWhitelist - tagsBlacklist
pasteTagsWhitelist : Whitelist of tags when pasting. default: _editorTagsWhitelist {String}
ex) 'p|h1|h2|h3'
ex) '*' // This means all tags are allowed. (Not available on "blacklist")
pasteTagsBlacklist : Blacklist of tags when pasting. default: null {String}
ex) 'h1|h2'
attributesWhitelist : Add attributes whitelist of tags that should be kept undeleted from the editor. default: null {Object}
// -- Fixed whitelist --
// Native attributes: 'contenteditable|colspan|rowspan|target|href|download|rel|src|alt|class|type|controls'
// Editor attributes: 'data-format|data-size|data-file-size|data-file-name|data-origin|data-align|data-image-link|data-rotate|data-proportion|data-percentage|origin-size|data-exp|data-font-size'
ex) {
'all': 'style|data-.+', // Apply to all tags
'input': 'checked|name' // Apply to input tag
'???': '*' // "*" === all attributes
}
attributesBlacklist : Add attribute blacklist of tags that should be deleted in editor. default: null {Object}
ex) {
'all': 'id', // Apply to all tags
'input': 'style' // Apply to input tag
'???': '*' // "*" === all attributes
}
// Layout-------------------------------------------------------------------------------------------------------
mode : The mode of the editor ('classic', 'inline', 'balloon', 'balloon-always'). default: 'classic' {String}
rtl : If true, the editor is set to RTL(Right To Left) mode. default: false {Boolean}
lineAttrReset : Deletes other attributes except for the property set at the time of line break.
If there is no value, no all attribute is deleted. default: '' {String}
ex) 'class|style': Attributes other than "class" and "style" are deleted at line break.
'*': All attributes are deleted at line break.
toolbarWidth : The width of the toolbar. Applies only when the editor mode is
'inline' or 'balloon' mode. default: 'auto' {Number|String}
toolbarContainer: A custom HTML selector placing the toolbar inside.
The class name of the element must be 'sun-editor'.
Element or querySelector argument. default: null {Element|String}
ex) document.querySelector('#id') || '#id'
stickyToolbar : Top offset value of "sticky toolbar".
Set to 0, '0px', '50px'...
If set to -1 or false or null to turn off. default: 0 {Number|String|Boolean}
hideToolbar : The toolbar is rendered hidden. default: false {Boolean}
fullScreenOffset: Top offset value of "full Screen".
Set to 0, '0px', '50px'... default: 0 {Number|String}
iframe : Content will be placed in an iframe and isolated from the rest of the page. default: false {Boolean}
fullPage : Allows the usage of HTML, HEAD, BODY tags and DOCTYPE declaration. default: false {Boolean}
iframeAttributes : Attributes of the iframe. default: null {Object}
ex) {'scrolling': 'no'}
iframeCSSFileName : Name or Array of the CSS file to apply inside the iframe.
You can also use regular expressions.
Applied by searching by filename in the link tag of document,
or put the URL value (".css" can be omitted). default: 'suneditor' {Array|String}
ex) '.+' or ['suneditor', 'http://suneditor.com/sample/css/sample.css', '.+\\.min\\.css']
previewTemplate : A template of the "preview".
The {{contents}} part in the HTML string is replaced with the contents of the editor. default: null {String}
ex) "
HTML source1
' }, { name: 'Template-2', html: 'HTML source2
' } ] // ETC------------------------------------------------------------------------------------------------------------ __allowedScriptTag : Allows script tags. default: false {Boolean} placeholder : The placeholder text. default: null {String} mediaAutoSelect : Activate the media[image, video, audio] selection status immediately after inserting the media tag. default: true {Boolean} icons : You can redefine icons. default: null {Object} ex) { bold: '', table: ' Use the attributes of "defaultIcons". * (more_text, more_paragraph, more_plus, more_horizontal, more_vertical) * text.xxx -> Use the text. * xxx -> HTML */ [ ['undo', 'redo'], [':t-More Text-default.more_text', 'bold', 'underline', 'italic'], [':p-More Paragraph-default.more_paragraph', 'font', 'formatBlock', 'align', 'list'], [':r-More Rich-default.more_plus', 'table', 'link', 'image', 'video'], [':v-View-text.View', 'fullScreen', 'codeView', 'print'], ['-right', ':o-More Others-', 'save', 'template'], // Used with alignment ] ----------------- ex) Responsive setting: ------------------------------------------------------------------------- // You can specify the arrangement of buttons according to the screen size in advance. // Responsive settings start with a percent sign.("%"). // %510(Number based on "px") [ // Default ['undo', 'redo'], ['font', 'fontSize', 'formatBlock'], ['paragraphStyle', 'blockquote'], ['bold', 'underline', 'italic', 'strike', 'subscript', 'superscript'], ['fontColor', 'hiliteColor', 'textStyle'], ['removeFormat'], ['outdent', 'indent'], ['align', 'horizontalRule', 'list', 'lineHeight'], ['table', 'link', 'image', 'video', 'audio', 'math'], ['imageGallery'], ['fullScreen', 'showBlocks', 'codeView'], ['preview', 'print'], ['save', 'template'], ['-left', '#fix', 'dir_ltr', 'dir_rtl'], // (min-width:992px) ['%992', [ ['undo', 'redo'], [':p-More Paragraph-default.more_paragraph', 'font', 'fontSize', 'formatBlock', 'paragraphStyle', 'blockquote'], ['bold', 'underline', 'italic', 'strike'], [':t-More Text-default.more_text', 'subscript', 'superscript', 'fontColor', 'hiliteColor', 'textStyle'], ['removeFormat'], ['outdent', 'indent'], ['align', 'horizontalRule', 'list', 'lineHeight'], ['-right', 'dir'], ['-right', ':i-More Misc-default.more_vertical', 'fullScreen', 'showBlocks', 'codeView', 'preview', 'print', 'save', 'template'], ['-right', ':r-More Rich-default.more_plus', 'table', 'link', 'image', 'video', 'audio', 'math', 'imageGallery'] ]], // (min-width:768px) ['%768', [ ['undo', 'redo'], [':p-More Paragraph-default.more_paragraph', 'font', 'fontSize', 'formatBlock', 'paragraphStyle', 'blockquote'], [':t-More Text-default.more_text', 'bold', 'underline', 'italic', 'strike', 'subscript', 'superscript', 'fontColor', 'hiliteColor', 'textStyle', 'removeFormat'], [':e-More Line-default.more_horizontal', 'outdent', 'indent', 'align', 'horizontalRule', 'list', 'lineHeight'], [':r-More Rich-default.more_plus', 'table', 'link', 'image', 'video', 'audio', 'math', 'imageGallery'], ['-right', 'dir'], ['-right', ':i-More Misc-default.more_vertical', 'fullScreen', 'showBlocks', 'codeView', 'preview', 'print', 'save', 'template'] ]] ] ``` ## Functions ```javascript import suneditor from 'suneditor' const editor = suneditor.create('example'); editor.core; // core object (The core object contains "util" and "functions".) editor.util; // util object // Reset the buttons on the toolbar. (Editor is not reloaded) // You cannot set a new plugin for the button. editor.setToolbarButtons([ [':moreText-More Text-default.more_horizontal', 'bold', 'underline', 'strike', 'subscript', 'superscript'], ['undo', 'redo'] ]); // Add or reset option property. (Editor is reloaded) editor.setOptions({ minHeight: '300px', buttonList: [ ['fontColor', 'hiliteColor'] ], colorList: [ ['#ccc', '#dedede', 'OrangeRed', 'Orange', 'RoyalBlue', 'SaddleBrown'] ] }); // Set "options.defaultStyle" style. // Define the style of the edit area // It can also be defined with the "setOptions" method, but the "setDefaultStyle" method does not render the editor again. editor.setDefaultStyle('font-family: cursive; font-size: 10px;'); // Open a notice area editor.noticeOpen('test notice'); // Close a notice area editor.noticeClose(); // Copies the contents of the suneditor into a [textarea] // * not working during enabled codeView mode editor.save(); // Gets the suneditor's context object. Contains settings, plugins, and cached element objects editor.getContext(); // Gets the contents of the suneditor // * not working during enabled codeView mode // onlyContents {Boolean}: Return only the contents of the body without headers when the "fullPage" option is true editor.getContents(onlyContents: Boolean); // Gets the current contents with containing parent div(div.sun-editor-editable). //
', true, true);
// Change the contents of the suneditor
editor.setContents('set contents');
// Get the editor's number of characters or binary data size.
// You can use the "charCounterType" option format.
// If argument is no value, the currently set "charCounterType" option is used.
editor.getCharCount((null || 'char' || 'byte' || 'byte-html'));
// Add content to the suneditor
editor.appendContents('append contents');
// Switch to or off "ReadOnly" mode.
editor.readOnly(true || false)
// Disable the suneditor
editor.disable();
// Enable the suneditor
editor.enable();
// Hide the suneditor
editor.hide();
// Show the suneditor
editor.show();
// Destroy the suneditor
editor.destroy();
// Toolbar methods
// Disable the toolbar
editor.toolbar.disable();
// Enable the toolbar
editor.toolbar.enable();
// Hide the toolbar
editor.toolbar.hide();
// Show the toolbar
editor.toolbar.show();
// Event functions -------------------------------------------------------------------------------------
// It can be redefined by receiving event object as parameter.
// It is not called in exceptional cases and is called after the default event function has before finished.
// e: event object, core: Core object
editor.onScroll = function (e, core) { console.log('onScroll', e) }
editor.onMouseDown = function (e, core) { console.log('onMouseDown', e) }
editor.onClick = function (e, core) { console.log('onClick', e) }
editor.onInput = function (e, core) { console.log('onInput', e) }
editor.onKeyDown = function (e, core) { console.log('onKeyDown', e) }
editor.onKeyUp = function (e, core) { console.log('onKeyUp', e) }
editor.onFocus = function (e, core) { console.log('onFocus', e) }
editor.onBlur = function (e, core) { console.log('onBlur', e) }
// onchange event
// contents: core.getContents(), Core object
editor.onChange = function (contents, core) { console.log('onChange', contents) }
// onload event
// When reloaded with the "setOptions" method, the value of the "reload" argument is true.
editor.onload = function (core, reload) {
console.log('onload-core', core)
console.log('onload-reload', reload)
}
// Clipboard event.
// Called before the editor's default event action.
// If it returns false, it stops without executing the rest of the action.
/**
* paste event
* e: Event object
* cleanData: HTML string modified for editor format
* maxCharCount: maxChartCount option (true if max character is exceeded)
* core: Core object
*/
editor.onPaste = function (e, cleanData, maxCharCount, core) { console.log('onPaste', e) }
/**
* paste event on math plugin
* e: Event object
* core: Core object
*/
editor.onPasteMath = function (e, core) { console.log('onPasteMath', e) }
// Copy event.
// Called before the editor's default event action.
// If it returns false, it stops without executing the rest of the action.
/**
* copy event
* e: Event object
* clipboardData: event.clipboardData
* core: Core object
*/
editor.onCopy = function (e, clipboardData, core) { console.log('onCopy', e) }
// Cut event.
// Called before the editor's default event action.
// If it returns false, it stops without executing the rest of the action.
/**
* cut event
* e: Event object
* clipboardData: event.clipboardData
* core: Core object
*/
editor.onCut = function (e, clipboardData, core) { console.log('onCut', e) }
// Drop event.
// Called before the editor's default event action.
// If it returns false, it stops without executing the rest of the action.
/**
* e: Event object
* cleanData: HTML string modified for editor format
* maxCharCount: maxChartCount option (true if max character is exceeded)
* core: Core object
*/
editor.onDrop = function (e, cleanData, maxCharCount, core) { console.log('onDrop', e) }
// Save event
// Called just after the save was executed.
/**
* contents Editor content
* core: Core object
*/
editor.onSave = function (contents, core) {console.log(contents) };
// Called before the image is uploaded
// If true is returned, the internal upload process runs normally.
// If false is returned, no image upload is performed.
// If new fileList are returned, replaced the previous fileList
// If undefined is returned, it waits until "uploadHandler" is executed.
/**
* files: Files array
* info: {
* - linkValue: Link url value
* - linkNewWindow: Open in new window Check Value
* - inputWidth: Value of width input
* - inputHeight: Value of height input
* - align: Align Check Value
* - isUpdate: Update image if true, create image if false
* - element: If isUpdate is true, the currently selected image.
* }
* core: Core object,
* uploadHandler: If undefined is returned, it waits until "uploadHandler" is executed.
* "uploadHandler" is an upload function with "core" and "info" bound. (plugin.upload.bind(core, info))
* [upload files] : uploadHandler(files or [new File(...),])
* [error] : uploadHandler("Error message")
* [Just finish] : uploadHandler()
* [directly register] : uploadHandler(response) // Same format as "imageUploadUrl" response
* ex) {
* // "errorMessage": "insert error message",
* "result": [ { "url": "...", "name": "...", "size": "999" }, ]
* }
* return {Boolean|Array|undefined}
*/
editor.onImageUploadBefore: function (files, info, core, uploadHandler) {
return Boolean || return (new FileList) || return undefined;
}
// Called before the video is uploaded
// If true is returned, the internal upload process runs normally.
// If false is returned, no video(iframe, video) upload is performed.
// If new fileList are returned, replaced the previous fileList
// If undefined is returned, it waits until "uploadHandler" is executed.
/**
* files: Files array
* info: {
* - inputWidth: Value of width input
* - inputHeight: Value of height input
* - align: Align Check Value
* - isUpdate: Update video if true, create video if false
* - element: If isUpdate is true, the currently selected video.
* }
* core: Core object,
* uploadHandler: If undefined is returned, it waits until "uploadHandler" is executed.
* "uploadHandler" is an upload function with "core" and "info" bound. (plugin.upload.bind(core, info))
* [upload files] : uploadHandler(files or [new File(...),])
* [error] : uploadHandler("Error message")
* [Just finish] : uploadHandler()
* [directly register] : uploadHandler(response) // Same format as "videoUploadUrl" response
* ex) {
* // "errorMessage": "insert error message",
* "result": [ { "url": "...", "name": "...", "size": "999" }, ]
* }
* return {Boolean|Array|undefined}
*/
editor.onVideoUploadBefore: function (files, info, core, uploadHandler) {
return Boolean || return (new FileList) || return undefined;
}
// Called before the audio is uploaded
// If true is returned, the internal upload process runs normally.
// If false is returned, no audio upload is performed.
// If new fileList are returned, replaced the previous fileList
// If undefined is returned, it waits until "uploadHandler" is executed.
/**
* files: Files array
* info: {
* - isUpdate: Update audio if true, create audio if false
* - currentaudio: If isUpdate is true, the currently selected audio.
* }
* core: Core object,
* uploadHandler: If undefined is returned, it waits until "uploadHandler" is executed.
* "uploadHandler" is an upload function with "core" and "info" bound. (plugin.upload.bind(core, info))
* [upload files] : uploadHandler(files or [new File(...),])
* [error] : uploadHandler("Error message")
* [Just finish] : uploadHandler()
* [directly register] : uploadHandler(response) // Same format as "audioUploadUrl" response
* ex) {
* // "errorMessage": "insert error message",
* "result": [ { "url": "...", "name": "...", "size": "999" }, ]
* }
* return {Boolean|Array|undefined}
*/
editor.onAudioUploadBefore: function (files, info, core, uploadHandler) {
return Boolean || return (new FileList) || return undefined;
}
// Called when the image is uploaded, updated, deleted.
/**
* targetElement: Target element
* index: Uploaded index (key value)
* state: Upload status ('create', 'update', 'delete')
* info: {
* - index: data index
* - name: file name
* - size: file size
* - select: select function
* - delete: delete function
* - element: Target element
* - src: src attribute of tag
* }
* remainingFilesCount: Count of remaining files to upload (0 when added as a url)
* core: Core object
*/
editor.onImageUpload = function (targetElement, index, state, info, remainingFilesCount, core) {
console.log(`targetElement:${targetElement}, index:${index}, state('create', 'update', 'delete'):${state}`)
console.log(`info:${info}, remainingFilesCount:${remainingFilesCount}`)
}
// Called when the video(iframe, video) is is uploaded, updated, deleted
// -- arguments is same "onImageUpload" --
editor.onVideoUpload = function (targetElement, index, state, info, remainingFilesCount, core) {
console.log(`targetElement:${targetElement}, index:${index}, state('create', 'update', 'delete'):${state}`)
console.log(`info:${info}, remainingFilesCount:${remainingFilesCount}`)
}
// Called when the audio is is uploaded, updated, deleted
// -- arguments is same "onImageUpload" --
editor.onAudioUpload = function (targetElement, index, state, info, remainingFilesCount, core) {
console.log(`targetElement:${targetElement}, index:${index}, state('create', 'update', 'delete'):${state}`)
console.log(`info:${info}, remainingFilesCount:${remainingFilesCount}`)
}
// Called when the image is upload failed.
// If you return false, the default notices are not called.
/**
* errorMessage: Error message
* result: Response Object
* core: Core object
* return {Boolean}
*/
editor.onImageUploadError = function (errorMessage, result, core) {
alert(errorMessage)
return Boolean
}
// Called when the video(iframe, video) upload failed
// -- arguments is same "onImageUploadError" --
editor.onVideoUploadError = function (errorMessage, result, core) {
alert(errorMessage)
return Boolean
}
// Called when the audio upload failed
// -- arguments is same "onImageUploadError" --
editor.onAudioUploadError = function (errorMessage, result, core) {
alert(errorMessage)
return Boolean
}
// Called when the editor is resized using the bottom bar
// height, prevHeight are number
editor.onResizeEditor = function (height, prevHeight, core, resizeObserverEntry) {
console.log(`height: ${height}, prevHeight: ${prevHeight}`, resizeObserverEntry)
// "resizeObserverEntry" is not provided in IE Browser.
}
// Called after the "setToolbarButtons" invocation
// Can be used to tweak buttons properties (useful for custom buttons)
/**
* buttonList: buttonList array
* core: Core object
*/
editor.onSetToolbarButtons = function (buttonList, core) {
console.log(`buttonList: ${buttonList}`)
}
// It replaces the default callback function of the image upload
/**
* xmlHttp: xmlHttpRequest object
* info: Input information
* - linkValue: Link url value
* - linkNewWindow: Open in new window Check Value
* - inputWidth: Value of width input
* - inputHeight: Value of height input
* - align: Align Check Value
* - isUpdate: Update image if true, create image if false
* - element: If isUpdate is true, the currently selected image.
* core: Core object
*/
editor.imageUploadHandler = function (xmlHttp, info, core) {
// Editor code
const response = JSON.parse(xmlHttp.responseText);
if (response.errorMessage) {
this.plugins.image.error.call(this, response.errorMessage, response);
} else {
this.plugins.image.register.call(this, info, response);
}
}
/**
* @description It replaces the default callback function of the video upload
* xmlHttp: xmlHttpRequest object
* info: Input information
* - inputWidth: Value of width input
* - inputHeight: Value of height input
* - align: Align Check Value
* - isUpdate: Update video if true, create video if false
* - element: If isUpdate is true, the currently selected video.
* core: Core object
*/
editor.videoUploadHandler = function (xmlHttp, info, core) {
// Editor code
const response = JSON.parse(xmlHttp.responseText);
if (response.errorMessage) {
this.plugins.video.error.call(this, response.errorMessage, response);
} else {
this.plugins.video.register.call(this, info, response);
}
}
/**
* @description It replaces the default callback function of the audio upload
* xmlHttp xmlHttpRequest object
* info Input information
* - isUpdate: Update audio if true, create audio if false
* - element: If isUpdate is true, the currently selected audio.
* core Core object
*/
editor.audioUploadHandler = function (xmlHttp, info, core) {
// Editor code
const response = JSON.parse(xmlHttp.responseText);
if (response.errorMessage) {
this.plugins.audio.error.call(this, response.errorMessage, response);
} else {
this.plugins.audio.register.call(this, info, response);
}
}
// An event when toggling between code view and wysiwyg view.
/**
* isCodeView: Whether the current code view mode
* core: Core object
*/
editor.toggleCodeView = function (isCodeView, core) {
console.log('isCodeView', isCodeView);
}
// An event when toggling full screen.
/**
* isFullScreen: Whether the current full screen mode
* core: Core object
*/
editor.toggleFullScreen = function (isFullScreen, core) {
console.log('isFullScreen', isFullScreen);
}
// Called just before the inline toolbar is positioned and displayed on the screen.
/**
* toolbar: Toolbar Element
* context: The editor's context object (editor.getContext()|core.context)
* core Core object
*/
editor.showInline = function (toolbar, context, core) {
console.log('toolbar', toolbar);
console.log('context', context);
}
// Called just after the controller is positioned and displayed on the screen.
// controller - editing elements displayed on the screen [image resizing, table editor, link editor..]]
/**
* name: The name of the plugin that called the controller
* controllers: Array of Controller elements
* core: Core object
*/
editor.showController = function (name, controllers, core) {
console.log('plugin name', name);
console.log('controller elements', controllers);
}
```
## Plugins list
> The plugin and the button have the same name.
| Name | Type |
|---|---|
| blockquote | command |
| image | dialog |
| link | |
| video | |
| audio | |
| math | |
| align | submenu |
| font | |
| fontColor | |
| fontSize | |
| formatBlock | |
| hiliteColor | |
| horizontalRule | |
| lineHeight | |
| list | |
| paragraphStyle | |
| table | |
| template | |
| textStyle | |
| imageGallery | fileBrowser |