events.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. - name: "valuechanged"
  2. params:
  3. - name: "e"
  4. type: "jQuery Event"
  5. description: |
  6. Event fires when body content has changed
  7. - name: "selectionchanged"
  8. params:
  9. - name: "e"
  10. type: "jQuery Event"
  11. description: |
  12. Event fires when cursor position or selected text has changed
  13. - name: "decorate"
  14. params:
  15. - name: "e"
  16. type: "jQuery Event"
  17. - name: "$el"
  18. type: "jQuery Object"
  19. description: |
  20. Event fires when pasting content and calling [**setValue**](../docs/doc-method.html#anchor-setValue).
  21. #####Example:
  22. Some features will insert extra attributes or tags in order to make the element looks nicer. That is "decorating".
  23. These elements should never be included when getting the content from the editor.
  24. ```html
  25. <div class="simditor-table"> <!-- extra tags -->
  26. <table>...</table>
  27. <div class="simditor-resize-handle" contenteditable="false"></div> <!-- extra tags -->
  28. </div>
  29. ```
  30. When inserting the above table, Simditor needs to call 'decorate' method to create extra tags in 'decorate' event.
  31. When getting the content value, it will call 'undecorate' method to remove all extra tags.
  32. ```coffee
  33. class TableButton extends Button
  34. constructor: (@editor) ->
  35. ...
  36. @editor.on 'decorate', (e, $el) =>
  37. $el.find('table').each (i, table) =>
  38. @decorate $(table)
  39. @editor.on 'undecorate', (e, $el) =>
  40. $el.find('table').each (i, table) =>
  41. @undecorate $(table)
  42. ...
  43. decorate: ($table) ->
  44. if $table.parent('.simditor-table').length > 0
  45. @undecorate $table
  46. $table.wrap '<div class="simditor-table"></div>'
  47. @initResize $table
  48. $table.parent()
  49. undecorate: ($table) ->
  50. return unless $table.parent('.simditor-table').length > 0
  51. $table.parent().replaceWith($table)
  52. ```
  53. - name: "undecorate"
  54. params:
  55. - name: "e"
  56. type: "jQuery Event"
  57. - name: "$el"
  58. type: "jQuery Object"
  59. description: |
  60. Event fires when calling [**getValue**](../docs/doc-method.html#anchor-decorate) and [**sync**](../docs/doc-method.html#anchor-sync).<br />
  61. Refer to [decorate](../docs/doc-event.html#anchor-decorate) event
  62. - name: "pasting"
  63. params:
  64. - name: "e"
  65. type: "jQuery Event"
  66. - name: "$pasteContent"
  67. type: "jQuery Object"
  68. description: |
  69. Event fires when pasting content into editor.<br />
  70. Param `$pasteContent` is the pasted content. You can valid the content and stop paste.
  71. ######Example:
  72. ```js
  73. // stop paste if the content contains images
  74. editor.on 'pasting', (e, $pasteContent) ->
  75. if $pasteContent.find("img").length > 0
  76. return false
  77. ```
  78. - name: "focus"
  79. params:
  80. - name: "e"
  81. type: "jQuery Event"
  82. description: |
  83. Event fires when textarea is focused.
  84. - name: "blur"
  85. params:
  86. - name: "e"
  87. type: "jQuery Event"
  88. description: |
  89. Event fires when textarea is blur.
  90. - name: "destroy"
  91. params:
  92. - name: "e"
  93. type: "jQuery Event"
  94. description: |
  95. Event fires when calling destroy method.