在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. 面向对象编程OOP-1

    在下面的例子中, 我们定义了 Student类作为 Person类的子类. 之后我们重定义了sayHello() 方法并添加了 sayGoodBye() 方法 // 定义Person构造器 funct ...

  2. Tomcat 系统架构与设计模式

    Tomcat 系统架构与设计模式,第 1 部分: 工作原理 这个分为两个部分的系列文章将研究 Apache Tomcat 的系统架构以及其运用的很多经典设计模式.本文是第 1 部分,将主要从 Tomc ...

  3. php 利用ffmpeg将amr转MP3

    原文地址: http://www.jianshu.com/p/895d5568ce70 http://www.cnblogs.com/wanghetao/p/3386311.html http://w ...

  4. Yii2 redis与cache

    原文地址:http://www.myexception.cn/php/1974979.html composer require yiisoft/yii2-redis 安装后使用超简单,打开 comm ...

  5. .NET4.0 __doPostBack未定义

    方法一.浏览器设置成兼容模式. 方法二.安装服务器版的.Net40的补丁.http://download.csdn.net/detail/5653325/6642051 方法三.点击VS的工具菜单-- ...

  6. jquery判断checkbox是否选中及改变checkbox状态

    转自:http://blog.csdn.net/limingchuan123456789/article/details/11499665 jquery判断checked的三种方法:.attr('ch ...

  7. C# 在字符串指定位置之前插入新的字符串

    http://zhidao.baidu.com/link?url=XbU4souNCiDk9AbdYWMDj6VMO7AxlnIpcEnAy4JgfaZXxlpjVt2cEoL6GPO9B0WytMq ...

  8. document.all的详细解释(document.all基本上所有浏览器可用!)

    从何而来从IE4开始IE的object model才增加了document.all对象,MSDN中也对 Object.all 有详细的说明,Object.all是个HTMLCollection,不是数 ...

  9. PlayMaker 学习笔记

    1.v1.7.8.3版本无法使用全局变量,原因是Assets\Plugins\PlayMaker下的Resources文件夹变成中文了,无法创建全局变量文件,手动创建一个Resources文件夹即可

  10. 【UEditor】 UEditor整合项目上传资源到阿里云服务器

    目录 关于此文 下载源码 JSP代码 Java代码 阿里云jar包引入配置 成功啦! 回到顶部 关于此文 项目中要实现编辑器生成带格式的html文档,存入模板,最后生成html的URL,所以选择了UE ...