extended-module.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>vue html5 editor demo</title>
  6. <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
  7. <script src="../dist/vue-html5-editor.js"></script>
  8. <script src="https://cdn.bootcss.com/vue/2.2.6/vue.js"></script>
  9. <script src="https://cdn.bootcss.com/moment.js/2.14.1/moment.min.js"></script>
  10. <link href="https://cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  11. <style>
  12. #app {
  13. margin: 50px auto;
  14. width: 800px;
  15. max-width: 100%;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <div id="app">
  21. <vue-html5-editor :content.sync="content" :height="500"></vue-html5-editor>
  22. </div>
  23. <script type="x/template" id="template-emoji">
  24. <div>
  25. <button v-for="s in symbols" type="button" @click="insertSymbol(s)">{{s}}</button>
  26. </div>
  27. </script>
  28. <script>
  29. Vue.use(VueHtml5Editor, {
  30. i18n: {
  31. //i18n for custom module
  32. "en-us": {
  33. date: "insert current time",
  34. emoji: "emoji"
  35. }
  36. },
  37. //config custom module
  38. date: {
  39. format: "YYYY-MM-DD"
  40. },
  41. modules: [
  42. {
  43. name: "date",
  44. icon: "fa fa-calendar",
  45. i18n: "time",
  46. show: true,
  47. init: function (editor) {
  48. alert("time module init, config is \r\n" + JSON.stringify(this.config))
  49. },
  50. handler: function (editor) {
  51. editor.execCommand("insertHTML", moment().format(this.config.format || "YYYY-MM-DD HH:mm"))
  52. },
  53. destroyed: function (editor) {
  54. alert("time module destroyed")
  55. }
  56. },
  57. {
  58. //custom module with dashboard.html
  59. name: "emoji",
  60. icon: "fa fa-smile-o",
  61. i18n: "emoji",
  62. show: true,
  63. init: function (editor) {
  64. console.log("emoji module init")
  65. },
  66. //vue component
  67. dashboard: {
  68. template: "#template-emoji",
  69. data: function () {
  70. return {
  71. symbols: [
  72. ">_<|||",
  73. "^_^;",
  74. "⊙﹏⊙‖∣°",
  75. "^_^|||",
  76. "^_^\"",
  77. "→_→",
  78. "..@_@|||||..",
  79. "…(⊙_⊙;)…",
  80. "o_o ....",
  81. "O__O",
  82. "///^_^.......",
  83. "?o?|||",
  84. "( ^_^ )? ",
  85. "(+_+)?",
  86. "(?ε?)? ",
  87. "o_O???",
  88. "@_@a",
  89. "一 一+",
  90. ">\"<||||",
  91. "‘(*>﹏<*)′"
  92. ]
  93. }
  94. },
  95. methods: {
  96. insertSymbol: function (symbol) {
  97. //$parent is editor component instance
  98. this.$parent.execCommand("insertHTML", symbol)
  99. }
  100. }
  101. }
  102. }
  103. ]
  104. })
  105. new Vue({
  106. el: "#app",
  107. data: {
  108. content: "<h3>vue html5 editor</h3>",
  109. }
  110. })
  111. </script>
  112. </body>
  113. </html>