KindEditor-编辑器配置参数属性

在《KindEditor-KindEditor简介》中提到了KindEditor编辑器的使用方法,下面是一段源码:

function editText(){
KindEditor.ready(function(K) {
editor1 = K.create('textarea[id="contentEdit"]', {
cssPath : getRootPath() +'/global/editor/plugins/code/prettify.css',
uploadJson : getRootPath() +'/uploadController?agentId='+agentId+'&nextDirName=agent&uploadType=image',
fileManagerJson : getRootPath() +'/fileManager?agentId='+agentId+'&nextDirName=agent&uploadType=image',
items:['source' , 'fullscreen', '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyfull', 'insertorderedlist','|', 'insertunorderedlist', 'indent', 'outdent',
       'clearhtml', 'quickformat', '|', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'lineheight', 'removeformat', '|', 'image', 'table', 'hr', 'baidumap'],
allowFileManager : true,
resizeType : 0,
urlType:"domain",
afterBlur: function(){this.sync();},
});
prettyPrint();
});
}


配置参数

1、id
TEXTAREA输入框的ID,必须设置。
数据类型:String

 

2、items
配置编辑器的工具栏,其中"-"表示换行,"|"表示分隔符。
数据类型:Array
默认值:

['source', '|', 'fullscreen', 'undo', 'redo', 'print', 'cut', 'copy', 'paste',
'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent','subscript',
'superscript', '|', 'selectall', '-',
'title', 'fontname', 'fontsize', '|', 'textcolor', 'bgcolor', 'bold',
'italic', 'underline', 'strikethrough', 'removeformat', '|', 'image',
'flash', 'media', 'advtable', 'hr', 'emoticons', 'link', 'unlink', '|', 'about']

        

3、width
编辑器的宽度,可以设置px或%,比TEXTAREA输入框样式表宽度优先度高。
数据类型:String
默认值:TEXTAREA输入框的宽度
注: 3.2版本开始支持。

 

4、height
编辑器的高度,只能设置px,比TEXTAREA输入框样式表高度优先度高。
数据类型:String
默认值:TEXTAREA输入框的高度
注: 3.2版本开始支持。


5、minWidth
数据类型:Int
指定编辑器最小宽度,单位为px。
默认值:200

 

6、minHeight
数据类型:Int
指定编辑器最小高度,单位为px。
默认值:100

 

7、filterMode
数据类型:Boolean
true时过滤HTML代码,false时允许输入任何代码。
默认值:false
注: 3.4以前版本的filterMode默认值为true。

 

8、htmlTags
指定要保留的HTML标记和属性。哈希数组的key为HTML标签名,value为HTML属性数组,"."开始的属性表示style属性。
数据类型:Object
默认值:

{
    font
 : ['color', 'size', 'face', '.background-color'],
    span
 : ['style'],
    div
 : ['class', 'align', 'style'],
    table
:['class', 'border', 'cellspacing', 'cellpadding', 'width', 'height','align', 'style'],
   
 'td,th':['class', 'align', 'valign', 'width', 'height',

             'colspan', 'rowspan', 'bgcolor', 'style'],
    a
 : ['class', 'href', 'target', 'name', 'style'],
    embed
 : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality',

              'style', 'align', 'allowscriptaccess', '/'],
    img
 : ['src', 'width', 'height', 'border', 'alt', 'title', 'align', 'style', '/'],
    hr
 : ['class', '/'],
    br
 : ['/'],
   
 'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : ['align', 'style'],
   
 'tbody,tr,strong,b,sub,sup,em,i,u,strike' : []
}     

注:filterMode为true时有效。3.4版本开始属性可设置style,保留所有inline样式。

 

9、resizeMode
2或1或0,2时可以拖动改变宽度和高度,1时只能改变高度,0时不能拖动。
数据类型:Int
默认值:2

 

10、skinType
风格类型,default或tinymce。
数据类型:String
默认值:default
注:3.4以前版本和3.4.1版本开始默认值为default,3.4版本的默认值为oxygen。

 

11、wyswygMode
可视化模式或代码模式
数据类型:Boolean
默认值:true

 

12、cssPath
指定编辑器iframe document的CSS,用于设置可视化区域的样式。
数据类型:String或Array
默认值:空
注:3.4.1版本开始可指定多个CSS文件。例如:cssPath : ['a.css', 'b.css']

 

13、skinsPath
指定编辑器的skins目录,skins目录存放风格的css文件和gif图片。
数据类型:String
默认值:KE.scriptPath + 'skins/'

 

14、pluginsPath
指定编辑器的plugins目录。
数据类型:String
默认值:KE.scriptPath + 'plugins/'

 

15、minChangeSize
undo/redo文字输入最小变化长度,当输入的文字变化小于这个长度时不会添加到undo堆栈里。
数据类型:Int
默认值:5

 

16、loadStyleMode
true时自动加载编辑器的CSS。
数据类型:Boolean
默认值:true
注: 3.4版本开始支持。

 

17、urlType
改变站内本地URL,可设置空、relative、absolute、domain。

空为不修改URL,relative为相对路径,absolute为绝对路径,domain为带域名的绝对路径。
数据类型:String
默认值:空
注: 3.4版本开始支持,3.4.1版本开始默认值为空。

 

18、newlineTag
设置回车换行标签,可设置p、br。
数据类型:String
默认值:br
注: 3.4版本开始支持。

 

19、afterCreate
设置编辑器创建后执行的回调函数。
数据类型:Function
默认值:无

 

20、afterDialogCreate
设置弹出浮动框创建后执行的回调函数。
数据类型:Function
默认值:无
注: 3.4.3版本开始支持。

 

21、allowUpload
true或false,true时显示上传图片标签。
数据类型:Boolean
默认值:true
注: 3.4版本开始支持。

 

22、allowFileManager
true或false,true时显示浏览服务器图片功能。
数据类型:Boolean
默认值:false
注: 3.4版本开始支持。

 

23、referMethod
设置referMethod后上传图片的POST参数里有referMethod。
数据类型:String
默认值:空
注: 3.4版本开始支持。

 

24、dialogAlignType
设置弹出框(dialog)的对齐类型,可设置page和空。

指定page时按当前页面居中,指定空时按编辑器居中。
数据类型:String
默认值:page
注: 3.4.1版本开始支持。

 

25、imageUploadJson
指定上传图片的服务器端程序。
数据类型:String
默认值:../../php/upload_json.php
注: 3.4.1版本开始支持。

 

26、fileManagerJson
指定浏览远程图片的服务器端程序。
数据类型:String
默认值:../../php/file_manager_json.php
注: 3.4.1版本开始支持。

 

27、autoSetDataMode
true或false。

true时自动将编辑器内容设置到原来的textarea,也就是每次输入内容就执行KE.util.setData函数。
数据类型:Boolean
默认值:true
注: 3.5版本开始支持。打开autoSetDataMode模式后会降低输入性能,理想的做法是关闭autoSetDataMode,提交数据前执行KE.util.setData。

 

28、afterSetData
自动执行KE.util.setData后执行的回调函数,autoSetDataMode为true时有效。
数据类型:Function
默认值:无
注: 3.5版本开始支持。

 

29、shadowMode
true或false,true时弹出层显示阴影。
数据类型:Boolean
默认值:true
注: 3.5版本开始支持。

 

30、allowPreviewEmoticons
true或false,true时鼠标放在表情上可以预览表情。
数据类型:Boolean
默认值:true
注: 3.5版本开始支持。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,我们需要在 Spring Boot 项目中引入 kindeditor 的相关依赖。可以通过在 Maven 或 Gradle 配置文件中添加以下依赖来实现: Maven: ```xml <dependency> <groupId>com.github.kindeditor</groupId> <artifactId>kindeditor</artifactId> <version>4.1.11</version> </dependency> ``` Gradle: ```groovy compile group: 'com.github.kindeditor', name: 'kindeditor', version: '4.1.11' ``` 接着,在 Spring Boot 项目中添加一个控制器,用于处理 kindeditor 的上传请求和获取文件列表请求。示例代码如下: ```java @RestController @RequestMapping("/kindeditor") public class KindEditorController { @Autowired private Environment env; /** * KindEditor上传文件接口 * @param file * @param request * @return */ @PostMapping("/upload") public Map<String, Object> upload(@RequestParam("imgFile") MultipartFile file, HttpServletRequest request) { Map<String, Object> result = new HashMap<>(); String url = ""; try { // 获取上传文件目录 String uploadDir = env.getProperty("kindeditor.upload-dir"); if (StringUtils.isBlank(uploadDir)) { uploadDir = request.getServletContext().getRealPath("/upload"); } File dir = new File(uploadDir); if (!dir.exists()) { dir.mkdirs(); } // 获取上传文件名 String fileName = file.getOriginalFilename(); // 生成新的文件名 String newFileName = UUID.randomUUID().toString() + "." + StringUtils.substringAfterLast(fileName, "."); // 保存文件 File dest = new File(dir, newFileName); file.transferTo(dest); // 返回文件访问URL url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/upload/" + newFileName; result.put("error", 0); result.put("url", url); } catch (Exception e) { result.put("error", 1); result.put("message", "文件上传失败"); } return result; } /** * KindEditor获取文件列表接口 * @param request * @return */ @GetMapping("/filemanager") public Map<String, Object> fileManager(HttpServletRequest request) { Map<String, Object> result = new HashMap<>(); try { // 获取上传文件目录 String uploadDir = env.getProperty("kindeditor.upload-dir"); if (StringUtils.isBlank(uploadDir)) { uploadDir = request.getServletContext().getRealPath("/upload"); } File dir = new File(uploadDir); if (!dir.exists()) { dir.mkdirs(); } // 遍历目录,获取文件列表 List<Map<String, Object>> fileList = new ArrayList<>(); File[] files = dir.listFiles(); if (files != null && files.length > 0) { for (File file : files) { Map<String, Object> fileInfo = new HashMap<>(); fileInfo.put("is_dir", file.isDirectory()); fileInfo.put("has_file", file.isFile()); fileInfo.put("filesize", file.length()); fileInfo.put("filename", file.getName()); fileInfo.put("datetime", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(file.lastModified()))); fileList.add(fileInfo); } } result.put("error", 0); result.put("file_list", fileList); } catch (Exception e) { result.put("error", 1); result.put("message", "文件列表获取失败"); } return result; } } ``` 其中,`upload` 方法用于处理 kindeditor 的上传请求,`filemanager` 方法用于获取文件列表请求。在 `upload` 方法中,我们通过 `MultipartFile` 接口获取上传的文件信息,然后将文件保存至指定目录,并返回文件访问 URL。在 `filemanager` 方法中,我们遍历指定目录下的所有文件,并将文件信息封装成列表返回。 最后,在前端页面中引入 kindeditor 的相关资源文件,并在页面中添加文本编辑器元素。示例代码如下: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>KindEditor富文本编辑器</title> <link rel="stylesheet" href="http://cdn.staticfile.org/kindeditor/4.1.11/themes/default/default.css" /> <script src="http://cdn.staticfile.org/kindeditor/4.1.11/kindeditor.js"></script> <script src="http://cdn.staticfile.org/kindeditor/4.1.11/lang/zh-CN.js"></script> </head> <body> <textarea id="editor"></textarea> <script> KindEditor.ready(function(K) { K.create('#editor', { uploadJson: '/kindeditor/upload', fileManagerJson: '/kindeditor/filemanager' }); }); </script> </body> </html> ``` 在以上代码中,我们引入了 kindeditor 的相关资源文件,并在页面中添加了一个 ID 为 `editor` 的 textarea 元素,然后通过 JavaScript 代码初始化了 kindeditor,并设置了上传文件和获取文件列表的 URL。 至此,我们就可以在 Spring Boot 项目中轻松实现 kindeditor 的富文本编辑器功能了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值