Analysis of how to use ckeditor custom plug-in

赶牛上岸
Release: 2018-03-06 13:50:35
Original
2484 people have browsed it

CKEditor is the famous FCKeditor. Another product of the company is CKFinder (an Ajax file manager). ckeditor is a powerful rich text editing tool. This article mainly introduces in detail how to use the ckeditor custom plug-in. It has certain reference value. Interested friends can refer to it

ckeditor is a very powerful rich text editing tool that provides us with most functions to meet our daily development needs. However, due to special circumstances, the ckeditor plug-in may need to be modified. ckeditor provides us with an interface that makes it easy to extend plug-ins.

Due to the needs of the project, it is necessary to rewrite the image upload function of ckeditor. The following is part of the code for the customized image upload function:

1. In ckeditor/plugins/ Create a new editorupload directory under the directory to store custom plug-ins; create a new directory images under this directory to store custom pictures, and put the plug-in image image.png in the images directory.

2. Create a new plugin.js in the editorupload directory:

(function () { var a = { exec: function (editor) { //调用jsp中的函数弹出上传框, var url = '../view/fileupload/upload.jsp'; openDialog({ //openDialog打开一个新窗口 title: '插入图片', url: url, height: 600, width: 900, callback:function(){ } }); } }, b = 'editorupload'; CKEDITOR.plugins.add('editorupload', { init: function (editor) { editor.addCommand(b, a); editor.ui.addButton('editorupload', { label: '添加图片', //鼠标悬停在插件上时显示的名字 icon: 'plugins/editorupload/images/image.png', //自定义图标的路径 command: b }); } }); })();
Copy after login

In the above code, a new upload.jsp page is created Used to upload pictures, use openDialog to pop up a new window, and set the height and width of the pop-up box.
CKEDITOR.plugins.add adds the customized editorupload to ckeditor.

The following is part of the upload.jsp page code:


  • 1、《PC首页轮播图片》长宽为666×250显示效果最好;《APP首页轮播图片》长宽为422×262显示效果最好;
  • 3、图片提交才会在首页生效;

Copy after login

The js of the upload.jps page part Code:

//提交照片 photoTaskDetail.submit = function () { var pictures = window.picManager._getPictures(); if (pictures.length < 1) { alert('请至少上传1张图片'); return false; } for (var i in pictures) { var imgPath = ""; var element = window.parent.CKEDITOR.dom.element.createFromHtml(imgPath); window.parent.CKEDITOR.instances.editorContent.insertElement(element); } parent.closeDialog(false); }
Copy after login

In the above code, you can upload multiple photos and put the photos into ckeditor respectively.
Configure ckeditor's config.js:

config.extraPlugins += (config.extraPlugins ? ',editorupload' : 'editorupload'); CKEDITOR.editorConfig = function( config ) { config.font_names= '宋体/宋体;黑体/黑体;仿宋/仿宋_GB2312;楷体/楷体_GB2312;隶书/隶书;幼圆/幼圆;微软雅黑/微软雅黑;'+ config.font_names; config.language = 'zh-cn'; config.extraPlugins += (config.extraPlugins ? ',lineheight' : 'lineheight'); config.extraPlugins += (config.extraPlugins ? ',editorupload' : 'editorupload'); CKEDITOR.config.lineheight_sizes = CKEDITOR.config.lineheight_sizes + '30px'; config.height = 650; config.toolbarCanCollapse = true; config.uiColor = '#90B8E9'; config.toolbar = 'Full'; config.toolbar_Full = [ { name: 'document', items: [ 'Source','-','Save','NewPage','DocProps','Preview','Print','-','Templates' ] }, { name: 'clipboard', items: [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] }, { name: 'links', items:['Link','Unlink']}, { name: 'insert', items:['HorizontalRule','Table','Image'] }, '/', { name: 'basicstyles', items: [ 'Bold','Underline','Strike','Subscript','Superscript','-','RemoveFormat'] }, { name: 'paragraph', items: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] }, { name: 'styles',items: ['lineheight','Format','Font','FontSize']}, { name: 'colors',items: ['TextColor', 'BGColor']}, { name: 'tools', items : [ 'Maximize','editorupload'] } ];
Copy after login

Add the editorupload plug-in to ckeditor.
The following are some screenshots of the implementation:

## Implementation summary:In the custom plug-in During the process, the image insertion function of the original plug-in must be turned on. The uploaded images will not be put into ckeditor, and the image addresses will be automatically filtered out. This may be caused by a bug in the ckeditor version. Guidance with solutions is welcome.

The above is the entire content of this article. I hope it will be helpful to everyone's study. I also hope that everyone will support the php Chinese website.

Related recommendations:

django teaches you how to easily use the rich text editor CKEditor

django teaches you How to master the rich text editor CKEditor

Integrate the CKeditor rich text editor into Python's Flask framework

The above is the detailed content of Analysis of how to use ckeditor custom plug-in. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!