ThinkPHP整合各大主流在線編輯器的方法
今天一個(gè)客戶要求在編輯器里增加可以拖動(dòng)圖片的方法,研究了很久,發(fā)現(xiàn)這幾種編輯器只有在ie下才可以拖動(dòng)圖片大小,包括網(wǎng)易用的編輯器,QQ空間的編輯器,先提前聲明一下。下面進(jìn)入重點(diǎn)
1.百度編輯器ueditor
先新建項(xiàng)目,生成以后在目錄下新建一個(gè)plugins文件夾
然后下載ueditor,地址:http://ueditor.baidu.com/website/download.html,注意編碼。下載以后解壓將整合文件夾放到plugins里,并且改名為ueditor
將項(xiàng)目名/Lib/Action/IndexAction.clas.php添加
- class IndexAction extends Action {
- function index(){
- $this->display();
- }
- }
然后在對(duì)應(yīng)的模版里添加,在<head></head>中間添加
- <script type="text/javascript" src="/edit/plugins/ueditor/ueditor.config.js"></script>
- <script type="text/javascript" src="/edit/plugins/ueditor/ueditor.all.js"></script>
在需要的地方添加
- <textarea id="myEditor" name="content" style="width:700px;height:300px;">
- </textarea>
- <script type="text/javascript">
- UE.getEditor('myEditor')
- </script>
- toolbars:[
- ['fullscreen', 'source', '|', 'undo', 'redo', '|',
- 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
- 'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
- 'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
- 'directionalityltr', 'directionalityrtl', 'indent', '|',
- 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
- 'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
- 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe','insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
- 'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
- 'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', '|',
- 'print', 'preview', 'searchreplace', 'help']
- ]
看需要?jiǎng)h除即可。
最近百度網(wǎng)盤有個(gè)活動(dòng),如果有興趣的朋友可以參加一下,還有個(gè)人收集的一些書(shū)籍
http://pan.baidu.com/share/link?shareid=3950160737&uk=3826886292
2.kindeditor
下載地址:http://www.kindsoft.net/down.php
解壓改名放到plugins下,
在模版里添加
- <script charset="utf-8" src="/edit/plugins/kindeditor/kindeditor.js"></script>
- <script charset="utf-8" src="/edit/plugins/kindeditor/lang/ko.js"></script>
- <script>
- KindEditor.ready(function(K) {
- window.editor = K.create('#editor_id');
- });
- <textarea id="myEditor" name="content" style="width:700px;height:300px;">
- </textarea>
顯示的樣式,自然就是51cto博客編輯器的樣子了。
3.xheditor ,號(hào)稱最干凈整潔的在線編輯器
下載地址:http://xheditor.com/download
復(fù)制到plugins下改名
在需要的模版中添加
- <script type="text/javascript" src="/edit/plugins/xheditor/jquery/jquery-1.4.4.min.js"></script>
- <script type="text/javascript" src="/edit/plugins/xheditor/xheditor-1.1.14-zh-cn.js"></script>
- <textarea name="content" class="xheditor"></textarea>
即可,剩下的就是和后端的處理了。
一般我就比較喜歡使用這三種編輯器,而且各有特點(diǎn),現(xiàn)在不喜歡fckeditor了,外觀不美觀,而且上傳之類的,容易出問(wèn)題,包括有上傳漏洞。就不說(shuō)了。有興趣的朋友可以加群:252799167一起學(xué)習(xí)進(jìn)