添加自定义插件


1. 添加”hello”插件¶

  1. 添加plugins/hello/hello.js文件。
  1. KindEditor.plugin('hello', function(K) {
  2. var editor = this, name = 'hello';
  3. // 点击图标时执行
  4. editor.clickToolbar(name, function() {
  5. editor.insertHtml('你好');
  6. });
  7. });
  1. 定义语言,在页面的<script>标签里添加以下脚本。
  1. KindEditor.lang({
  2. hello : '你好'
  3. });
  1. 定义工具栏图标的CSS,在页面的<style>标签里添加以下CSS。
  1. .ke-icon-hello {
  2. background-image: url(../skins/default/default.gif);
  3. background-position: 0px -672px;
  4. width: 16px;
  5. height: 16px;
  6. }
  1. 最后调用编辑器时items数组里添加hello。
  1. K.create('#id', {
  2. items : ['hello']
  3. });

完整代码:

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Hello</title>
  6. <style>
  7. .ke-icon-hello {
  8. background-image: url(../skins/default/default.gif);
  9. background-position: 0px -672px;
  10. width: 16px;
  11. height: 16px;
  12. }
  13. </style>
  14. <link rel="stylesheet" href="../themes/default/default.css" />
  15. <script charset="utf-8" src="../kindeditor.js"></script>
  16. <script charset="utf-8" src="../lang/zh_CN.js"></script>
  17. <script>
  18. KindEditor.lang({
  19. hello : '你好'
  20. });
  21. KindEditor.ready(function(K) {
  22. K.create('#id', {
  23. items : ['hello']
  24. });
  25. });
  26. </script>
  27. </head>
  28. <body>
  29. <textarea id="editor_id" name="content" style="width:700px;height:300px;"></textarea>
  30. </body>
  31. </html>