phpcms編輯器添加一鍵排版控件
來源:程序員人生 發布時間:2015-11-17 23:16:57 閱讀次數:10274次
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編輯器添加一鍵排版控件就完成啦,大家有什么疑問,歡迎留言,本文是站長手寫代碼,轉載請說明出處,本文來自程序員人生
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈