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',
- 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(/ /ig, '');
- _html = _html.replace(/ /ig, '');
- _html = _html.replace(/<p><\/p>/ig, '');
- _html = _html.replace(/<a/ig, '<a rel="nofollow"');
-
-
-
- _html = _html.replace(/<p[^>]*>/ig,'');
- _html = _html.replace(/<\/p>/ig,'<br />');
- _html = _html.replace(/<br \/><br \/>/ig,'<br />');
- _html = _html.replace(/[\n]/ig, '');
-
-
- 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,'');
-
-
- a.setData(_html);
- }
- }
- }
- };
- })();
写到这里,就完成啦,完成了CKEditor添加一键排版插件
但是,到这里再phpcms里面,还是不能直接用的,在别的系统里面是可以的。因为phpcms的编辑器控件是需要单独选择的,还需要修改phpcms文件
打开phpcms/libs/classes/form.class.php
搜索['Maximize'] 在它的后面加上 ['autoformat'],就可以了
这样phpcms编辑器添加一键排版控件就完成啦,大家有什么疑问,欢迎留言,本文是站长手写代码,转载请说明出处,本文来自程序员人生