CKEditor添加一键排版插件实例
大家都知道phpcms也是ckeditor编辑器,那么如果增加这个一键排版这个牛逼功能呢
增加好了后,效果图是这样的

废话不多说,直接说步骤
第一步:config.js中statics\js\ckeditor\config.js中注册autoformat控件

config.extraPlugins = 'capture,videoforpc,flashplayer,autoformat'; 

第二步,在statics\js\ckeditor\plugins 新建文件夹autoformat

第三步,statics\js\ckeditor\plugins\autoformat新建文件plugin.js
写入如下内容

 (function() {
CKEDITOR.plugins.add('autoformat', {
requires: ['styles', 'button'],
init: function(a) {
a.addCommand('autoformat', CKEDITOR.plugins.autoformat.commands.autoformat);
a.ui.addButton('autoformat', {
label: "清除格式,一键排版",
command: 'autoformat',
//这个autoformat.gif是你的插件图标,放在同目录下
icon: this.path + "autoformat.gif"
});
}
});
CKEDITOR.plugins.autoformat = {
commands: {
autoformat: {
exec: function(a) {
var _html = a.getData();
//清除样式代码
_html = _html.replace(/<div/ig, '<p');
_html = _html.replace(/<\/div>/ig, '</p>');
_html = _html.replace(/<strong[^>]*>/ig, '');
_html = _html.replace(/<\/strong>/ig, '');
_html = _html.replace(/<em[^>]*>/ig, '');
_html = _html.replace(/<\/em>/ig, '');
_html = _html.replace(/<u[^>]*>/ig, '');
_html = _html.replace(/<\/u>/, '');
_html = _html.replace(/<li[^>]*>/ig, '');
_html = _html.replace(/<\/li>/ig, '');
_html = _html.replace(/<span[^>]*>/ig, '');
_html = _html.replace(/<\/span>/ig, '');
_html = _html.replace(/&nbsp;/ig, '');
_html = _html.replace(/ /ig, '');
_html = _html.replace(/<p><\/p>/ig, '');
_html = _html.replace(/<a/ig, '<a rel="nofollow"'); //将p标签替换成<br />
_html = _html.replace(/<p[^>]*>/ig, '');
_html = _html.replace(/<\/p>/ig, '<br />');
_html = _html.replace(/<br \/><br \/>/ig, '<br />');
_html = _html.replace(/[\n]/ig, ''); //按<br />分组,将换行<br>全部替换成p标签
bb = _html.split("<br />");
aa = '';
for (var i = 0; i < bb.length; i++) {
aa = aa + '<p>' + bb[i] + '</p>';
} //首行缩进
_html = aa.replace(/<p[^>]*>/ig, '<p>  ');
_html = _html.replace(/<p>  <\/p>/ig, '');
_html = _html.replace(/<p><\/p>/ig, ''); //在这里执行你将_html中的空行替换掉的操作
a.setData(_html);
}
}
}
};
})();

写到这里,就完成啦,完成了CKEditor添加一键排版插件

但是,到这里再phpcms里面,还是不能直接用的,在别的系统里面是可以的。因为phpcms的编辑器控件是需要单独选择的,还需要修改phpcms文件
 
打开phpcms/libs/classes/form.class.php
搜索['Maximize'] 在它的后面加上 ['autoformat'],就可以了。

转自:http://www.wfuyu.com/biji/25066.html

原文是程序员人生。

phpcms编辑器添加一键排版控件的更多相关文章

  1. Add an Item to the Navigation Control 将项目添加到导航控件

    In this lesson, you will learn how to add an item to the navigation control. For this purpose, the N ...

  2. 百度地图API示例之添加定位相关控件

    代码 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" cont ...

  3. C#构架之基础学习----动态添加窗体和 控件

    仿照窗体应用程序编写: 任务一:生成一个Form类的窗体对象frm using System.Windows.Forms;         //using指令使用Form对象创建所需的命名空间 //如 ...

  4. 在WPF中添加Windows Form控件(包括 ocx控件)

      首先,需要向项目中的reference添加两个dll,一个是.NET库中的System.Windows.Forms,另外一个是WindowsFormsIntegration,它的位置一般是在C:\ ...

  5. Unity编辑器 - 鼠标悬停在控件上时改变鼠标样式

    Unity编辑器 - 鼠标悬停在控件上时改变鼠标样式 摘自Unity文档 EditorGUIUtility.AddCursorRect public static void AddCursorRect ...

  6. Unity编辑器 - 使用GL绘制控件

    Unity编辑器 - 使用GL绘制控件 控件较为复杂时,可能造成界面卡顿,在EditorGUI中也可以灵活使用GL绘制来提升性能. 以绘制线段为例: using UnityEngine; using ...

  7. Unity编辑器 - DragAndDrop拖拽控件

    Unity编辑器 - DragAndDrop拖拽控件 Unity编辑器的拖拽(DragAndDrop)在网上能找到的资料少,自己稍微研究了一下,写了个相对完整的案例,效果如下 代码: object d ...

  8. IOS 当一个控件被添加到父控件中会调用(didMoveToSuperview)

    /** * 当一个控件被添加到父控件中就会调用 */ - (void)didMoveToSuperview { if (self.group.opened) { self.nameView.image ...

  9. QT5:第二章 布局排版控件

    一.简介 在QT组件面板中有Layouts和Spacers两个组件面板 注意:布局排版控件不显示 1.Layouts(布局) Vertical Layout:垂直方向布局,组件自动在垂直方向上分布 H ...

随机推荐

  1. Mac 小技巧

    本文的大部分技巧来自于池建强老师的<MacTalk.人生元编程>,感谢他的辛苦付出,本文多系整理而已. 终端输入说英语 说英语时我们当然希望有标准发音.在Mac中不需要字典,直接在终端里输 ...

  2. CSS系列(6) CSS通配符详解

    通配符使用星号*表示,意思是“所有的”. 平时使用电脑,比如要搜索C盘里所有的网页,可以使用 *.html来搜索,.html是网页的后缀名,*代表了所有网页的名称: 也就是使用 * 加后缀名,就可以在 ...

  3. 【情人节礼物】纯js脚本打造精美3D玫瑰

    情人节就要来临了,这是用代码做出的玫瑰花,这才是程序员送给女友的最好情人节礼物...(提示:在不同浏览器下观看效果.速度会有很大的不同) 代码如下: <!doctype html> < ...

  4. 通过slf4j/log4j的MDC/NDC 实现日志追踪

    在分布式系统或者较为复杂的系统中,我们希望可以看到一个客户请求的处理过程所涉及到的所有子系统\模块的处理日志. 由于slf4j/log4j基本是日志记录的标准组件,所以slf4j/log4j成为了我的 ...

  5. jekens介绍及服务搭建

    https://blog.csdn.net/achuo/article/details/51086599 https://blog.csdn.net/qq_37372007/article/detai ...

  6. springboot配多数据源

    多数据源配置 https://blog.csdn.net/neosmith/article/details/61202084 https://www.cnblogs.com/zhangboyu/p/7 ...

  7. Python学习5,三级菜单实例

    _author_ = "Happyboy" data = { '北京':{ "昌平":{ "沙河":["Happyboy" ...

  8. Python全栈工程师(元组、字典)

     ParisGabriel     感谢 大家的支持  你们的阅读评价就是我最好的更新动力  我会坚持吧排版做的越来越好        每天坚持 一天一篇 点个订阅吧  灰常感谢    当个死粉也阔以 ...

  9. shell之正则表达式

    正则表达式(regular expression ,REGEXP): 元字符: .:匹配任意单个字符 []:匹配指定范围内的任意单个字符 [^]:匹配指定范围外的任意字符 字符集合:使用[字符集合] ...

  10. 201621123033 《Java程序设计》第1周学习总结

    1. 本周学习总结 · jdk.jre.jvm的含义及相关概念(具体见下文回答) · 会使用记事本及简单编辑器编写Java程序,理解javac和java命令的含义(具体见下文回答) · java与C语 ...