jodit
4.2.5
下载最新版本或通过NPM:
npm install jodit您将获得以下文件:
/esm :编辑器的ESM版本(与WebPack之类的工具兼容)/es5 , /es2015 , /es2018 , /es2021 :UMD捆绑文件(未缩小)/es5 , /es2015 , /es2018 , /es2021带有.min.js扩展:UMD捆绑和缩小文件types/index.d.ts :此文件指定编辑器的API。它是版本的,而其他所有内容都被视为私有,并且每个版本都可能会改变。包括以下两个文件:
< link type =" text/css " rel =" stylesheet " href =" es2015/jodit.min.css " />
< script type =" text/javascript " src =" es2015/jodit.min.js " > </ script >ES2021版本(仅适用于现代浏览器):
< link type =" text/css " rel =" stylesheet " href =" es2021/jodit.min.css " />
< script type =" text/javascript " src =" es2021/jodit.min.js " > </ script > < script type =" importmap " >
{
"imports" : {
"autobind-decorator" : "https://unpkg.com/[email protected]/lib/esm/index.js"
}
}
</ script >
< link rel =" stylesheet " href =" ./node_modules/jodit/es2021/jodit.min.css " />
< script type =" module " >
import { Jodit } from './node_modules/jodit/esm/index.js' ;
Jodit . make ( '#editor' , {
width : 600 ,
height : 400
} ) ;
</ script >ESM模块自动仅包含基本的插件和英语。您可以根据需要手动包含其他插件和语言。
< script type =" importmap " >
{
"imports" : {
"autobind-decorator" : "https://unpkg.com/[email protected]/lib/esm/index.js"
}
}
</ script >
< link rel =" stylesheet " href =" ./node_modules/jodit/es2021/jodit.min.css " />
< script type =" module " >
import { Jodit } from './node_modules/jodit/esm/index.js' ;
import './node_modules/jodit/esm/plugins/add-new-line/add-new-line.js' ;
import './node_modules/jodit/esm/plugins/fullsize/fullsize.js' ;
import de from './node_modules/jodit/esm/langs/de.js' ;
Jodit . langs . de = de ;
Jodit . make ( '#editor' , {
width : 600 ,
height : 400 ,
language : 'de'
} ) ;
</ script > < link
rel =" stylesheet "
href =" https://cdnjs.cloudflare.com/ajax/libs/jodit/4.0.1/es2021/jodit.min.css "
/>
< script src =" https://cdnjs.cloudflare.com/ajax/libs/jodit/4.0.1/es2021/jodit.min.js " > </ script > < link
rel =" stylesheet "
href =" https://unpkg.com/[email protected]/es2021/jodit.min.css "
/>
< script src =" https://unpkg.com/[email protected]/es2021/jodit.min.js " > </ script >在您的HTML中添加textarea元素:
< textarea id =" editor " name =" editor " > </ textarea >在Textarea上初始化Jodit:
const editor = Jodit . make ( '#editor' ) ;
editor . value = '<p>start</p>' ; Jodit . plugins . yourplugin = function ( editor ) {
editor . events . on ( 'afterInit' , function ( ) {
editor . s . insertHTMl ( 'Text' ) ;
} ) ;
} ; const editor = Jodit . make ( '.someselector' , {
extraButtons : [
{
name : 'insertDate' ,
iconURL : 'https://xdsoft.net/jodit/logo.png' ,
exec : function ( editor ) {
editor . s . insertHTML ( new Date ( ) . toDateString ( ) ) ;
editor . synchronizeValues ( ) ; // For history saving
}
}
]
} ) ;或者
const editor = Jodit . make ( '.someselector' , {
buttons : [ 'bold' , 'insertDate' ] ,
controls : {
insertDate : {
name : 'insertDate' ,
iconURL : 'https://xdsoft.net/jodit/logo.png' ,
exec : function ( editor ) {
editor . s . insertHTML ( new Date ( ) . toDateString ( ) ) ;
}
}
}
} ) ;用插件按钮
Jodit . plugins . add ( 'insertText' , function ( editor ) {
editor . events . on ( 'someEvent' , function ( text ) {
editor . s . insertHTMl ( 'Hello ' + text ) ;
} ) ;
} ) ;
// or
Jodit . plugins . add ( 'textLength' , {
init ( editor ) {
const div = editor . create . div ( 'jodit_div' ) ;
editor . container . appendChild ( div ) ;
editor . events . on ( 'change.textLength' , ( ) => {
div . innerText = editor . value . length ;
} ) ;
} ,
destruct ( editor ) {
editor . events . off ( 'change.textLength' ) ;
}
} ) ;
// or use class
Jodit . plugins . add (
'textLength' ,
class textLength {
init ( editor ) {
const div = editor . create . div ( 'jodit_div' ) ;
editor . container . appendChild ( div ) ;
editor . events . on ( 'change.textLength' , ( ) => {
div . innerText = editor . value . length ;
} ) ;
}
destruct ( editor ) {
editor . events . off ( 'change.textLength' ) ;
}
}
) ;
const editor = Jodit . make ( '.someselector' , {
buttons : [ 'bold' , 'insertText' ] ,
controls : {
insertText : {
iconURL : 'https://xdsoft.net/jodit/logo.png' ,
exec : function ( editor ) {
editor . events . fire ( 'someEvent' , 'world!!!' ) ;
}
}
}
} ) ; 要测试FileBrowser和Uploader模块,需要安装PHP连接器
composer create-project --no-dev jodit/connector运行测试PHP服务器
php -S localhost:8181 -t ./并设置Jodit的选项:
const editor = Jodit . make ( '#editor' , {
uploader : {
url : 'http://localhost:8181/index-test.php?action=fileUpload'
} ,
filebrowser : {
ajax : {
url : 'http://localhost:8181/index-test.php'
}
}
} ) ; 麻省理工学院