index.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>UEditorPlus 完整演示</title>
  5. <meta name="viewport" content="width=device-width, minimum-scale=0.5, maximum-scale=5, user-scalable=no">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  8. <script src="./example.js"></script>
  9. <script type="text/javascript" charset="utf-8" src="ueditor.config.js"></script>
  10. <script type="text/javascript" charset="utf-8" src="ueditor.all.js"></script>
  11. <script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js?94bf6581"></script>
  12. <script src="./plugins/demo/demo.js"></script>
  13. <script>
  14. // window.UEDITOR_CONFIG.toolbars[0].push('undo');
  15. </script>
  16. <script>var _hmt = _hmt || [];
  17. (function () {
  18. var hm = document.createElement("script");
  19. hm.src = "https://hm.baidu.com/hm.js?f84f35a44b5cc5c0b10c3fabdf0f322b";
  20. var s = document.getElementsByTagName("script")[0];
  21. s.parentNode.insertBefore(hm, s);
  22. })();</script>
  23. <style>
  24. :root {
  25. /*--ueditor-top-offset: 20px;*/
  26. }
  27. </style>
  28. <link rel="stylesheet" href="./style.css"/>
  29. </head>
  30. <body class="demo-editor-page">
  31. <div>
  32. <h1>完整示例</h1>
  33. <div>
  34. <script id="editor" type="text/plain" style="height:300px;">
  35. <h1>
  36. 你好 UEditorPlus
  37. </h1>
  38. <p>
  39. UEditorPlus 是基于 UEditor 二次开发的富文本编辑器,让 UEditor <span style="color: #E36C09;">焕<span style="color: #0070C0;">然</span><span style="color: #31859B;"><span style="color: #00B050;">一</span><span style="color: #FF0000;">新</span></span></span>
  40. </p>
  41. <table data-sort="sortDisabled">
  42. <tbody>
  43. <tr class="firstRow">
  44. <td valign="top" style="word-break: break-all;" rowspan="1" colspan="3">
  45. 我是表格
  46. </td>
  47. </tr>
  48. <tr>
  49. <td width="273" valign="top" style="word-break: break-all;">
  50. 如果
  51. </td>
  52. <td width="273" valign="top" style="word-break: break-all;">
  53. 有一天
  54. </td>
  55. <td width="273" valign="top" style="word-break: break-all;">
  56. 我离开了
  57. </td>
  58. </tr>
  59. <tr>
  60. <td valign="top" colspan="1" rowspan="1" style="word-break: break-all;">
  61. 怎么才能
  62. </td>
  63. <td valign="top" colspan="1" rowspan="1" style="word-break: break-all;">
  64. 证明我
  65. </td>
  66. <td valign="top" colspan="1" rowspan="1" style="word-break: break-all;">
  67. 曾经来过
  68. </td>
  69. </tr>
  70. </tbody>
  71. </table>
  72. <pre class="brush:html;toolbar:false">&lt;div&gt;
  73. &lt;span&gt;这里是HTML标签&lt;/span&gt;
  74. &lt;/div&gt;</pre>
  75. <h2>
  76. 公式支持
  77. </h2>
  78. <p>
  79. <img src="https://r.latexeasy.com/image.svg?%5Cint%20%5Cfrac%7B1%7D%7Bx%7D%20dx%20%3D%20%5Cln%20%5Cleft%7C%20x%20%5Cright%7C%20%2B%20C"
  80. data-formula-image="%5Cint%20%5Cfrac%7B1%7D%7Bx%7D%20dx%20%3D%20%5Cln%20%5Cleft%7C%20x%20%5Cright%7C%20%2B%20C"/>
  81. </p>
  82. <p>
  83. <br/>
  84. </p>
  85. </script>
  86. </div>
  87. <div id="btns" style="margin-top:20px;height:2000px;">
  88. <div>
  89. <button onclick="alert(UE.getEditor('editor').getAllHtml())">获得整个html的内容</button>
  90. <button onclick="alert(UE.getEditor('editor').getContent())">获得内容</button>
  91. <button onclick="UE.getEditor('editor').setContent('<p>欢迎使用 UEditorPlus</p>', false)">写入内容</button>
  92. <button onclick="UE.getEditor('editor').setContent('<p>欢迎使用 UEditorPlus</p>', true)">追加内容</button>
  93. <button onclick="alert(UE.getEditor('editor').getContentTxt())">获得纯文本</button>
  94. <button onclick="alert(UE.getEditor('editor').getPlainTxt())">获得带格式的纯文本</button>
  95. <button onclick="alert(UE.getEditor('editor').hasContents())">判断是否有内容</button>
  96. <button onclick="UE.getEditor('editor').focus()">使编辑器获得焦点</button>
  97. <button onmousedown="isFocus()">编辑器是否获得焦点</button>
  98. <button onmousedown="setBlur()">编辑器失去焦点</button>
  99. <button onclick="getSelectText()">获得当前选中的文本</button>
  100. <button onclick="UE.getEditor('editor').execCommand('insertHtml', '插入的内容')">插入内容</button>
  101. <button onclick="UE.getEditor('editor').setEnabled()">设定可编辑</button>
  102. <button onclick="UE.getEditor('editor').setDisabled('fullscreen')">设定不可编辑</button>
  103. <button onclick="UE.getEditor('editor').setHide()">隐藏编辑器</button>
  104. <button onclick="UE.getEditor('editor').setShow()">显示编辑器</button>
  105. <button onclick="UE.getEditor('editor').setHeight(300)">设置固定高度</button>
  106. <button onclick="UE.getEditor('editor')">创建编辑器</button>
  107. <button onclick="UE.getEditor('editor').destroy()">销毁编辑器</button>
  108. <button onclick="alert( UE.getEditor('editor').execCommand('get_auto_save_content') )">草稿箱-获取</button>
  109. <button onclick="UE.getEditor('editor').execCommand('clear_auto_save_content'); alert('已清空草稿箱')">草稿箱-清空
  110. </button>
  111. <button onclick="UE.getEditor('editor').execCommand('set_auto_save_content'); alert('已保存')">草稿箱-立即保存
  112. </button>
  113. <button onclick="UE.getEditor('editor').execCommand('auto_save_restore')">草稿箱-恢复到编辑器</button>
  114. </div>
  115. </div>
  116. <script type="text/javascript">
  117. var ue = UE.getEditor('editor',{
  118. // autoHeightEnabled: false,
  119. // retainOnlyLabelPasted: true,
  120. ai:{
  121. // 自定义接入
  122. driverRequest: function (option) {
  123. console.log('模拟 AI 请求,参数如下:', option);
  124. var texts = []
  125. var i = 0;
  126. var mock = function () {
  127. var text = '测试' + (i++)
  128. texts.push(text)
  129. if (texts.length >= 10) {
  130. // 调用 onFinish 方法表示结束
  131. option.onFinish({code: 0, msg: 'ok', data: {text: texts.join("")}})
  132. return
  133. }
  134. // 调用 onStream 方法模拟流式返回
  135. option.onStream({code: 0, msg: 'ok', data: {text: text}})
  136. setTimeout(mock, 50);
  137. };
  138. mock();
  139. },
  140. }
  141. });
  142. ue.on('contentchange', function () {
  143. // console.log('contentchange', ue.getContent());
  144. });
  145. function isFocus(e) {
  146. alert(UE.getEditor('editor').isFocus());
  147. UE.dom.domUtils.preventDefault(e)
  148. }
  149. function setBlur(e) {
  150. UE.getEditor('editor').blur();
  151. UE.dom.domUtils.preventDefault(e)
  152. }
  153. function getSelectText() {
  154. var range = UE.getEditor('editor').selection.getRange();
  155. range.select();
  156. var txt = UE.getEditor('editor').selection.getText();
  157. alert(txt)
  158. }
  159. </script>
  160. </div>
  161. </body>
  162. </html>