将kindeditor在线编辑器制作成smarty插件
在web开发中,在线编辑器是经常要用到的功能模块,虽说配置在线编辑器没有多大难度,但是每一次编写重复的代码,总是让人感觉不爽。
本篇,就来讲解一下,如何将kindeditor制作成smarty的一个自定义函数。
为什么要制作成自定义函数呢?当然是为了避免写很多重复的代码。
{html_kindeditor name="kindcontent"}

假如在模板中调用一个smarty标签,就能生成一个文本编辑器(如上),那开发起来会不会感觉很过瘾呢?
好了,说下流程(本文以集成了smarty模板的ci框架为例)。
首先,将下载好的kindeditor解压后放在项目根目录。
然后在smarty的plugins目录新建一个文件function.html_kindeditor.php
<?php /**
* kindeditor 在线编辑器
* @author rick <shaoyikai@qq.com>
*
* 使用举例:
* {html_kindeditor name="kindcontent" width="700" height="250" theame="simple" lang="en" items="simple"}
*/
function smarty_function_html_kindeditor($params)
{ $params['height'] = empty($params['height']) ? 300: $params['height'];
$params['theame'] = empty($params['theame']) ? 'default': $params['theame'];
$params['name'] = empty($params['name']) ? 'content': $params['name'];
$params['lang'] = empty($params['lang']) ? 'zh_CN': $params['lang']; //可选择的语言zh_CN,zh_TW,en,ko,ar
$params['items'] = empty($params['items']) ? 'default': $params['items']; if($params['items'] === 'simple')
{
$params['width'] = empty($params['width']) ? 480: $params['width'];
$items = '["source","preview","code","|","cut","copy","paste","|","justifyleft","justifycenter","justifyright",
"justifyfull","|","insertorderedlist","insertunorderedlist","indent","outdent","|","subscript",
"superscript","clearhtml","fullscreen","/",
"formatblock","fontname","fontsize","|","forecolor","hilitecolor","bold",
"italic","underline","lineheight","removeformat","|","image","multiimage","table","emoticons","|",
"anchor","link","unlink"]';
}
else
{
$params['width'] = empty($params['width']) ? 680: $params['width'];
$items = '["source","|","undo","redo","|","preview","print","template","code","cut","copy","paste","plainpaste","wordpaste","|","justifyleft","justifycenter","justifyright",
"justifyfull","insertorderedlist","insertunorderedlist","indent","outdent","subscript",
"superscript","clearhtml","quickformat","selectall","|","fullscreen","/",
"formatblock","fontname","fontsize","|","forecolor","hilitecolor","bold",
"italic","underline","strikethrough","lineheight","removeformat","|","image","multiimage",
"flash","media","insertfile","table","hr","emoticons","baidumap","pagebreak",
"anchor","link","unlink","|","about"]';
} $editor = '<script charset="utf-8" src="/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="/kindeditor/lang/'.$params["lang"].'.js"></script>
<link rel="stylesheet" href="/kindeditor/themes/'.$params["theame"].'/'.$params["theame"].'.css" />
<script>
KindEditor.ready(function(K) {
window.editor = K.create("#editor_id",{
themeType:"'.$params["theame"].'",
langType : "'.$params["lang"].'",
items: '.$items.',
minWidth: 400,
});
});
</script> <textarea id="editor_id" name="'.$params["name"].'" style="width:'.$params["width"].'px;height:'.$params["height"].'px;">
</textarea>'; return $editor;
}
注意js,css路径要根据自己的项目灵活修改,当然也可以放进参数里面,不过这样的话调用的时候就麻烦些。鉴于这些路径不会经常改动,所以这里直接写死了。
然后,就可以在模板中使用html_kindeditor插件函数了,比如:
{html_kindeditor name="kindcontent" width="700" height="250" theame="simple" lang="en" items="simple"}
以后,项目中需要编辑器的地方,直接写个这样的标签就行,是不是很方便呢?
将kindeditor在线编辑器制作成smarty插件的更多相关文章
- CKEditor在线编辑器增加一个自定义插件
CKEditor是一个非常优秀的在线编辑器,它的前身就是FCKEditor,CKEditor据官方说是重写了内核的,但功能和性能比FCKEditor更为强大和优越.记得07年的时候第一次接触FCKEd ...
- kindeditor在线编辑器的使用心得
1. 如何声明引用? <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...
- jsp解决kindeditor在线编辑器struts图片上传问题
1.下载 官网下载ckeditor,解压后去掉不需要的部分,仅需保留plugin,lang,theme文件夹,这三个文件夹中用不到的东西可以删除, 比如lang文件下存放所有语言文件js,仅仅 保留e ...
- .Net在线编辑器:KindEditor及CkEditor+CkFinder配置说明
Net在线编辑器:KindEditor及CkEditor+CkFinder配置说明 一.KindEditor(免费) KindEditor是一套开源的HTML可视化编辑器,主要用于让用户在网站上获得所 ...
- 在线编辑器Ckeditor (1) - php (30)
在线编辑器 在线编辑器也称之为所见即所得编辑器,是一种常见的html源码编辑器. 所见即所得:用户在输入的时候,不论是格式和是样式都能被系统原封不动的保存,最后在查看的时候,可以按照用户输入的原来的结 ...
- js组件在线编辑器插件、图表库插件、文件树插件
在线编辑器插件: 一.kindeditor 二.UEditor 图表库插件: 一.echart 二.highchart 文件树插件: 一.zTree -- jQuery 树插件 http://www. ...
- jquery插件课程2 放大镜、多文件上传和在线编辑器插件如何使用
jquery插件课程2 放大镜.多文件上传和在线编辑器插件如何使用 一.总结 一句话总结:插件使用真的还是比较简单的,引包,初始化,配置参数(json),配置数据(json),而后两步不是必须的.而且 ...
- 在线编辑器的使用-KindEditor
第一种:KindEditor编辑器 步骤一:加载相应的核心的文件 下载地址:http://kindeditor.net/demo.php <link rel="stylesheet&q ...
- 在线编辑器的使用总结(kindeditor , )
1).kindedtor中让编辑框默认为“HTML代码/源代码”模式 [javascript] view plaincopyprint? <script> // 自定义插件 #1 Kind ...
随机推荐
- Python标准库:内置函数hasattr(object, name)
Python标准库:内置函数hasattr(object, name) 本函数是用来判断对象object的属性(name表示)是否存在.如果属性(name表示)存在,则返回True,否则返回False ...
- VS2013-解决error C4996: 'fopen'问题
VS2013中如何解决error C4996: 'fopen'问题 初次使用vs系列编辑器编写控制台应用程序时常出现如下错误: error C4996: 'fopen': This function ...
- Autofac.Integration.Mvc分析
Autofac.Integration.Mvc static ILifetimeScope LifetimeScope { get { return (ILifetimeScope)HttpConte ...
- 新浪微博客户端(59)-hitTest withEvent方法的使用说明
iOS中的触摸事件总是由最顶层的View首先得到的,当这个View得到该触摸事件的时候可以选择通过 - (BOOL)pointInside:(CGPoint)point withEvent:(UIEv ...
- [Js/Jquery]jquery插件开发
摘要 上篇文章简单学习了js自调用方法.今天就趁热打铁,学一学怎么编写一个jquery插件. JQuery 参考地址:http://www.cnblogs.com/playerlife/archive ...
- [MongoDB]对数组操作
摘要 在实际开发中遇到更新某个document中的数组的值,这里做一下记录. 这里使用的驱动为 using MongoDB.Bson;using MongoDB.Driver; 相关文章 [Mongo ...
- Web API 身份验证 不记名令牌验证 Bearer Token Authentication
1. Startup.Auth.cs文件 添加属性 public static OAuthBearerAuthenticationOptions OAuthBearerOptions { get; p ...
- linux下的chm阅读器?
pre和code标签是可以同时使用的, 通常pre放在code的前面. 由于 code, pre中不能使用 换行, 段落, 和 尖括号标签, 所以, 对于尖括号, 要换成 html的 实体符号 < ...
- CxImage
启动项目的时候显示此时 百度“无法启动程序cximage.lib” 得到http://tieba.baidu.com/p/1935208210把第二项设为启动项即可 为什么设置第二项为启动项呢 因为h ...
- ngCordova插件安装使用
为什么ngCordova ngCordova是在Cordova Api基础上封装的一系列开源的AngularJs服务和扩展,让开发者可以方便的在HybridApp开发中调用设备能力,即可以在Angul ...