首页前端开发其他前端知识ckeditor插件开发简单实例

ckeditor插件开发简单实例

时间2024-02-10 12:06:03发布访客分类其他前端知识浏览558
导读:收集整理的这篇文章主要介绍了ckeditor插件开发简单实例,觉得挺不错的,现在分享给大家,也给大家做个参考。 CKedITor就是fcKeditor,在发布一个新版本的时候,把自己的名...
收集整理的这篇文章主要介绍了ckeditor插件开发简单实例,觉得挺不错的,现在分享给大家,也给大家做个参考。

CKedITor就是fcKeditor,在发布一个新版本的时候,把自己的名字都改了,不要"F"。

需求:我需要在编辑文本的时候,选择一段文字,点击自定义的按钮,就能够在这段文字后面增加一个图标,图标超链接去一个地址,以选中的文字作为参数。

做法:

1、在CKeditor的plugins文件夹下,创建新文件夹"addmap",这个名字可以自定义,这个名字是我项目中用的名字

2、在addmap文件夹下,放一张Gif图片"map.gif",用来作图标用的。

3、在addmap文件夹下,新建"plugin.js",编辑这个js文件,我们这里的代码是:

复制代码 代码如下:
(function() {
    //Section 1 : 按下自定义按钮时执行的代码
    VAR a = {
        exec: function(editor) {
        var data="";  
        var mySelection = editor.getSelection();
        if (CKEDITOR.env.ie) {
            mySelection.unlock(true);
            data = mySelection.getNative().createRange().text;
        } else {
            data = mySelection.getNative();
        }
        if(data!=null& & data!=''){
            editor.insertHtML(data+'a href="/map_index.html?ad='+data+'"> img border="0" height="24" src="/images/map_icon.gif" width="24" /> /a> ');
        }
        }
    } ,
    b = 'addmap';
    CKEDITOR.plugins.add(b, {
        init: function(editor) {
            editor.addCommand(b, a);
            editor.ui.addButton('addmap', {
                label: 'add map link',
                icon: this.path + 'map.gif',
                command: b
            } );
        }
    } );
} )();

4、回到CKeditor的根目录,编辑config.js

复制代码 代码如下:@H_360_57@
CKEDITOR.editorConfig = function( config )
{
// define changes to default configuration here. For example:
config.language = 'zh-cn';
//config.uiColor = '#AADC6E';
//字体.
config.font_names = '宋体; 楷体_GB2312; 新宋体; 黑体; 隶书; 幼圆; 微软雅黑; Arial; Comic Sans MS; Courier New; Tahoma; Times New roman; Verdana; ';
//工具按钮    
config.toolbar=
[
   ['Source','-','Preview'],
   ['Cut','Copy','Paste','PasteText','PasteFromWord','-','PRint','Link','Unlink','Anchor'],
   ['Undo','redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
   ['addmap']
];

config.extraPlugins = 'addmap';

5、测试

您可能感兴趣的文章:
  • CKEditor扩展插件:自动排版功能autoformat插件实现方法详解
  • FCKeditor 插件开发 示例(详细版本)
  • ckeditor自定义插件使用方法详解
  • CKEditor 附插入代码的插件
  • 添加FCKeditor插件需要注意的地方
  • fckeditor 插件实例 制作步骤
  • autogrow 让FCKeditor高度随内容增加的插件
  • CKEditor中加入syntaxhighlighter代码高亮插件
  • FCKeditor 和 SyntaxHighlighter 代码高亮插件的整合
  • ckeditor一键排版功能实现方法分析

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: ckeditor插件开发简单实例
本文地址: https://pptw.com/jishu/608337.html
UEditor 编辑器跨域上传解决方法 为SyntaxHighlighter添加新语言的方法

游客 回复需填写必要信息