将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 ...
随机推荐
- ubuntu下增加中文编码
在Ubuntu中,利用命令:locale,来查看系统的语言环境 参考:http://blog.chinaunix.net/uid-94449-id-2002589.html Windows的默认编码为 ...
- FBX
http://docs.autodesk.com/FBX/2014/ENU/FBX-SDK-Documentation/index.html http://forums.autodesk.com/t5 ...
- input的onkeyup效果 超级简短代码
效果代码 title="请输入正确的十六位数字" onkeyup="javascript: return this.value = this.value.toUpperC ...
- JS之function的应用
1.最基本的作为一个本本分分的函数声明使用. 复制代码代码如下: function func(){} 或 var func=function(){}; 2.作为一个类构造器使用: 复制代码代码如下: ...
- Java中hashCode的作用
转 http://blog.csdn.net/fenglibing/article/details/8905007 Java中hashCode的作用 2013-05-09 13:54 64351人阅 ...
- Linux负载均衡软件LVS简介
Linux负载均衡软件LVS LVS集群的体系结构以及特点 1. LVS简介 LVS是Linux Virtual Server的简称,也就是Linux虚拟服务器, 是一个由章文嵩博士发起 ...
- angularjs之自己定义指令篇
1>指令基础知识 directive() 参考资料 http://www.tuicool.com/articles/aAveEj http://damoqiongqiu.iteye.com/bl ...
- js jquery, jquery-ui 获取form各种表单input的值?
如何获取? make up (for): 弥补, 补偿, her beaty cannot make up for her stu'pidity. five Basic laws of human s ...
- vim的寄存器和剪贴簿操作?
vim 复制/ 删除 多行? 有确定序号的行: :10,15m20, 10,15co20 没有确定序号的行: ndd, nyy. 其中的n表示, 从当前行开始算起(当前行本身要包含!!!), 向下共删 ...
- Cannot install NodeJs: /usr/bin/env: node: No such file or directory
安装doxmate时,doxmate地址是:https://github.com/JacksonTian/doxmatenpm install doxmate -g 安装完后把错误:Cannot in ...