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'
}
}
} ) ; 麻省理工學院