在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插件的更多相关文章

  1. CKEditor在线编辑器增加一个自定义插件

    CKEditor是一个非常优秀的在线编辑器,它的前身就是FCKEditor,CKEditor据官方说是重写了内核的,但功能和性能比FCKEditor更为强大和优越.记得07年的时候第一次接触FCKEd ...

  2. kindeditor在线编辑器的使用心得

    1. 如何声明引用? <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> ...

  3. jsp解决kindeditor在线编辑器struts图片上传问题

    1.下载 官网下载ckeditor,解压后去掉不需要的部分,仅需保留plugin,lang,theme文件夹,这三个文件夹中用不到的东西可以删除, 比如lang文件下存放所有语言文件js,仅仅 保留e ...

  4. .Net在线编辑器:KindEditor及CkEditor+CkFinder配置说明

    Net在线编辑器:KindEditor及CkEditor+CkFinder配置说明 一.KindEditor(免费) KindEditor是一套开源的HTML可视化编辑器,主要用于让用户在网站上获得所 ...

  5. 在线编辑器Ckeditor (1) - php (30)

    在线编辑器 在线编辑器也称之为所见即所得编辑器,是一种常见的html源码编辑器. 所见即所得:用户在输入的时候,不论是格式和是样式都能被系统原封不动的保存,最后在查看的时候,可以按照用户输入的原来的结 ...

  6. js组件在线编辑器插件、图表库插件、文件树插件

    在线编辑器插件: 一.kindeditor 二.UEditor 图表库插件: 一.echart 二.highchart 文件树插件: 一.zTree -- jQuery 树插件 http://www. ...

  7. jquery插件课程2 放大镜、多文件上传和在线编辑器插件如何使用

    jquery插件课程2 放大镜.多文件上传和在线编辑器插件如何使用 一.总结 一句话总结:插件使用真的还是比较简单的,引包,初始化,配置参数(json),配置数据(json),而后两步不是必须的.而且 ...

  8. 在线编辑器的使用-KindEditor

    第一种:KindEditor编辑器 步骤一:加载相应的核心的文件 下载地址:http://kindeditor.net/demo.php <link rel="stylesheet&q ...

  9. 在线编辑器的使用总结(kindeditor , )

    1).kindedtor中让编辑框默认为“HTML代码/源代码”模式 [javascript] view plaincopyprint? <script> // 自定义插件 #1 Kind ...

随机推荐

  1. SVN中Branch和Merge实践

    参考资料:http://blog.csdn.net/eggcalm/article/details/6606520 branch主要用于新功能的开发,开发过程中不断从trunk merge revis ...

  2. PHP 出现 502 解决方案

    原文:http://www.ahlinux.com/php/10319.html nginx+php 出现502 bad gateway,一般这都不是nginx的问题,而是由于 fastcgi或者ph ...

  3. 对二进制加密(分散保存-s=sy+a+b)

    #include <stdio.h> #define L 40 void jiaM(int * s,int * a,int *b,int *sy); void jieM(int * a,i ...

  4. [Unity3D][转] 关于Assets资源目录结构管理

    分享个我们项目常用的目录结构,微调过很多次,最终到了这个版本.个人认为这种管理资源方式是不错的.欢迎探讨各个细节~ 更新于2013.5.30   Asserts   --Editor 自写的灵活方便插 ...

  5. css书写规则总结

    1. JavaScript钩子使用的class不能是css class,要加j或j-前缀 2. 选择器 2.1 css选择器尽量简短,层级要少,最好是1-2层 例如:.nav{} 优于 ul.nav{ ...

  6. Spring--Spring容器

    在使用Spring所提供的各种丰富而神奇的功能之前,必须要在Spring IoC容器中装配好Bean,并建立Bean和Bean之间的关联关系. Spring提供了多种配置方式来实现Bean的装配.但在 ...

  7. Jetty与tomcat的比较

    Google 应用系统引擎最初是以 Apache Tomcat 作为其 webserver/servlet 容器的,但最终将切换到 Jetty 上. 这个决定让许多开发人员都诧异的想问:为什么要做这样 ...

  8. java从一个目录拷贝文件到另一个目录下

    ** * 复制单个文件 * @param oldPath String 原文件路径 如:c:/fqf.txt * @param newPath String 复制后路径 如:f:/fqf.txt * ...

  9. 【转】【整理】将Linux脚本中的正常输出,警告,错误等信息输出到文件中

     本文来自:http://blog.csdn.net/woshinia/article/details/18040063   很早以前  编译的时候 就在用 2>&1,但是一直没有生成一 ...

  10. jquery 中一些 特殊方法 的特殊使用 一览表

    cnblogs的页面, 一种是管理页面, 是随笔的列表 a full list of essays. 另一种是 首页. 要搜索文档的话, 就使用 "首页"的那种方式. 一个jque ...