将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 ...
随机推荐
- <摘录>如何在64位linux强制编译32位应用程序
GDC注:因为需要解决在linux64机上编译32位的mongodb(没办法,因为编译的php是32位,然后我想将mongdb扩展添加到php中),在网上搜了很多文章,感觉这篇好懂,而且好用.我使用的 ...
- 英文论文中i.e.,e.g.,etc.,viz.的简要小结
英文论文中i.e.,e.g.,etc.,viz.的简要小结 看了一堆用法,全白扯,自己总结的最好记,最实用 i.e. =即.换句话说.也就是说."'In essence' or 'in ot ...
- Marshal
https://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx http://tomosoft.jp/design/?p=4647 ht ...
- XtraFinder在OSX10.11的使用
重启系统,按住command键加上R键 进入恢复模式还是什么模式里,然后启动terminal 然后键入 csrutil enable --without debug 重启电脑,可正常使用 居然上传不了 ...
- 【转】SPDY协议
SPDY协议 - v3 原文:SPDY Protocol - Draft 3 翻译:邱鹏滔(QQ: 95350530,主页:www.fireflysource.com) 1 概述 HTTP协议的瓶颈在 ...
- 我的J2EE学习历程
由于最近手头没有JSP项目,所以暂停Hibernate和Spring的研究.个人觉得只有发现某个东西的不足之后再去学习新的东西来弥补这个不足比较好.就好比,最开始在JSP页面里面写Java代码,每次操 ...
- css sprite
1.What? CSS Sprites其实就是把网页中一些背景图片整合到一张图片文件中,再利用CSS的“background-image”,“background- repeat”,“backgrou ...
- 《UIP在NIOS上的移植》
移植环境:Cyclone IV 开发板,网卡芯片为ENC28J60,浏览器(Firefox_24.0.0.5001a) 首先,需要了解网卡芯片ENC28J60,有中文版的说明书:http://wenk ...
- Linux 中常见的命令行,持续更新
1.添加自己的环境变量 root@adonis:~# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin r ...
- 使用LIBSVM工具实现样本分类预测——MatLab
准备工作: https://www.csie.ntu.edu.tw/~cjlin/libsvm/,下载LIBSVM:(LIBSVM工具相较于MATLAB自带的工具:1).支持多分类及回归(‘-s 0’ ...