ThinkPHP整合各大主流在线编辑器的方法

简介:

   今天一个客户要求在编辑器里增加可以拖动图片的方法,研究了很久,发现这几种编辑器只有在ie下才可以拖动图片大小,包括网易用的编辑器,QQ空间的编辑器,先提前声明一下。下面进入重点

   1.百度编辑器ueditor

   先新建项目,生成以后在目录下新建一个plugins文件夹

171046287.jpg

   然后下载ueditor,地址:http://ueditor.baidu.com/website/download.html,注意编码。下载以后解压将整合文件夹放到plugins里,并且改名为ueditor

   将项目名/Lib/Action/IndexAction.clas.php添加

1
2
3
4
5
class  IndexAction  extends  Action {
     function  index(){
         $ this ->display();
     }
}


然后在对应的模版里添加,在<head></head>中间添加

1
2
< script  type = "text/javascript"  src = "/edit/plugins/ueditor/ueditor.config.js" ></ script >
< script  type = "text/javascript"  src = "/edit/plugins/ueditor/ueditor.all.js" ></ script >


在需要的地方添加

1
2
3
4
5
< textarea  id = "myEditor"  name = "content"  style = "width:700px;height:300px;" >
</ textarea >
< script  type = "text/javascript" >
     UE.getEditor('myEditor')
</ script >


这是textera的方式,也可以用div,p都可以,官方推荐的是

1
2
3
< script  type = "text/plain"  id = "myEditor" >
     //从数据库中取出文章内容打印到此处
</ script >


1
2
3
4
5
6
7
8
9
10
11
12
13
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' ]
         ]


看需要删除即可。

最近百度网盘有个活动,如果有兴趣的朋友可以参加一下,还有个人收集的一些书籍

http://pan.baidu.com/share/link?shareid=3950160737&uk=3826886292

2.kindeditor

下载地址:http://www.kindsoft.net/down.php

解压改名放到plugins下,

在模版里添加

1
2
3
4
5
6
< 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');
         });
1
2
< textarea  id = "myEditor"  name = "content"  style = "width:700px;height:300px;" >
</ textarea >



显示的样式,自然就是51cto博客编辑器的样子了。

3.xheditor  ,号称最干净整洁的在线编辑器

下载地址:http://xheditor.com/download

复制到plugins下改名

在需要的模版中添加

1
2
< 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 >
1
< textarea  name = "content"  class = "xheditor" ></ textarea >

即可,剩下的就是和后端的处理了。

   一般我就比较喜欢使用这三种编辑器,而且各有特点,现在不喜欢fckeditor了,外观不美观,而且上传之类的,容易出问题,包括有上传漏洞。就不说了。










本文转自 3147972 51CTO博客,原文链接:http://blog.51cto.com/a3147972/1243384,如需转载请自行联系原作者
目录
相关文章
|
8月前
|
前端开发 Android开发
前端项目实战壹-安卓4.4/6.0无法安装非原生项目无法渲染样式
前端项目实战壹-安卓4.4/6.0无法安装非原生项目无法渲染样式
47 0
|
IDE 安全 数据可视化
优雅!用了这两款插件,我成了整个公司代码写得最规范的码农
我:我写的代码怎么可能不规范,不要胡说。 于是同事打开我的 IDEA ,安装了一个插件,然后执行了一下,规范不规范,看报告吧。
|
小程序 JavaScript 前端开发
目前为止最全的微信小程序项目实例
目前为止最全的微信小程序项目实例
246 0
|
存储 数据可视化 前端开发
这款国外开源框架, 让你轻松构建自己的页面编辑器
前段时间我一直在设计和研究低代码搭建平台,也开源了几款可视化编辑器框架,最近在 github 上发现了一款非常强大的基于自然流布局的页面搭建框架 GrapesJS,接下来我就带大家摸索一下这款框架。
465 0
|
Web App开发 Kubernetes JavaScript
真爱!微软宣布新开源网站,由 Jekyll 一键生成,代码所见即所得
近日,微软上线了一个新的开源网站。这不是微软唯一的开源网站,但却代表了新的起点。网友表示:这次真的拥抱开源了!从「恨」到「爱」,微软与开源有着一段长达30年的故事。
125 0
真爱!微软宣布新开源网站,由 Jekyll 一键生成,代码所见即所得
|
前端开发
浅析三大主流的APP开发方式
我们都知道目前的几大主流的移动应用开发方式:Native App,Web App,Hybrid App。那他们之间的联系和优缺点各是什么呢? 1.Native App:本地应用程序(原生App) Native开发也即原生开发,如果你是做Android 开发,那么大部分都是用Java 语言来编写的,如果你是做IOS开发,则是使用Objecttive C 或者Swift来进行编写的,这些都是官方的标准,好处显而易见,利用官方提供的API ,开发的APP有更好的性能,可以实现各种酷炫的效果,有更好的兼容性,对用户来说体验更好。
2076 0