plugin.rst 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 添加自定义插件
  2. ========================================================
  3. 1. 添加"hello"插件
  4. --------------------------------------------------------
  5. 1) 添加plugins/hello/hello.js文件。
  6. .. sourcecode:: js
  7. KindEditor.plugin('hello', function(K) {
  8. var editor = this, name = 'hello';
  9. // 点击图标时执行
  10. editor.clickToolbar(name, function() {
  11. editor.insertHtml('你好');
  12. });
  13. });
  14. 2) 定义语言,在页面的<script>标签里添加以下脚本。
  15. .. sourcecode:: js
  16. KindEditor.lang({
  17. hello : '你好'
  18. });
  19. 3) 定义工具栏图标的CSS,在页面的<style>标签里添加以下CSS。
  20. .. sourcecode:: css
  21. .ke-icon-hello {
  22. background-image: url(../skins/default/default.gif);
  23. background-position: 0px -672px;
  24. width: 16px;
  25. height: 16px;
  26. }
  27. 4) 最后调用编辑器时items数组里添加hello。
  28. .. sourcecode:: js
  29. K.create('#id', {
  30. items : ['hello']
  31. });
  32. 完整代码:
  33. .. sourcecode:: html
  34. <!doctype html>
  35. <html>
  36. <head>
  37. <meta charset="utf-8" />
  38. <title>Hello</title>
  39. <style>
  40. .ke-icon-hello {
  41. background-image: url(../skins/default/default.gif);
  42. background-position: 0px -672px;
  43. width: 16px;
  44. height: 16px;
  45. }
  46. </style>
  47. <link rel="stylesheet" href="../themes/default/default.css" />
  48. <script charset="utf-8" src="../kindeditor.js"></script>
  49. <script charset="utf-8" src="../lang/zh-CN.js"></script>
  50. <script>
  51. KindEditor.lang({
  52. hello : '你好'
  53. });
  54. KindEditor.ready(function(K) {
  55. K.create('#id', {
  56. items : ['hello']
  57. });
  58. });
  59. </script>
  60. </head>
  61. <body>
  62. <textarea id="editor_id" name="content" style="width:700px;height:300px;"></textarea>
  63. </body>
  64. </html>