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. react书写规范小记

    1.对齐方式 //如果没有属性,在自闭和标签前添加一个空格: <Footer /> //如果可以放在一行,放在一行上即可: <Footer bar="bar" / ...

  2. DOS程序员手册(十五)

    837页 writeln('TRACING Current Buffer==='); holdup; bcbtrc(cvtbase^.curbfr); writeln; holdup ; writel ...

  3. [部署开发环境][1 vagrant] vagrant部署开发环境--安装vagrant

    # 安装教程 # 安装vagrant 教程 # 准备 - windows操作系统 - VirtualBox---Win, - vagrant_1.9.3.msi - 镜像文件https://atlas ...

  4. Linux 内核数据结构bitmap

    #include <stdio.h> #include <stdlib.h> #define MAX_PRIO 10000 #define BITS_PER_LONG 32 # ...

  5. [CF1045C]Hyperspace Highways

    题目大意:给一张$n$个点$m$条边的图,保证若有一个环,一定是完全子图,多次询问两个点之间的最短路径长度 题解:把完全子图缩成一个点,圆方树,方点权值设成$1$,圆点设成$0$即可. 卡点:数组开小 ...

  6. Spring Boot RabbitMQ 延迟消息实现完整版

    概述 曾经去网易面试的时候,面试官问了我一个问题,说 下完订单后,如果用户未支付,需要取消订单,可以怎么做 我当时的回答是,用定时任务扫描DB表即可.面试官不是很满意,提出: 用定时任务无法做到准实时 ...

  7. BZOJ2208 [Jsoi2010]连通数 【图的遍历】

    题目 输入格式 输入数据第一行是图顶点的数量,一个正整数N. 接下来N行,每行N个字符.第i行第j列的1表示顶点i到j有边,0则表示无边. 输出格式 输出一行一个整数,表示该图的连通数. 输入样例 3 ...

  8. 洛谷 P2375 [NOI2014]动物园 解题报告

    P2375 [NOI2014]动物园 题目描述 近日,园长发现动物园中好吃懒做的动物越来越多了.例如企鹅,只会卖萌向游客要吃的.为了整治动物园的不良风气,让动物们凭自己的真才实学向游客要吃的,园长决定 ...

  9. 中英文混截,一个中文相当于n个英文

    项目中遇到这么个需求,截取中英文字符串,一个中文相当于2个英文,全英文时截取12个英文字母,全中文时是6个中文汉字,中英文混合时是12个字节,在网上有找到这样的解决方案,但我没能静下心来研究懂,于是自 ...

  10. P2625 豪华游轮 (背包$dp$,数学)

    题目链接 Solution 贼有意思的一个题目. 可以发现阻止我们走的更远的就是那些需要反向走的路程. 然后发现当角度越接近 \(180^\circ\) ,对我们最终的答案则更优. 所以先是一个背包把 ...