index.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 type="text/javascript" charset="utf-8" src="ueditor.config.js"></script>
  9. <script type="text/javascript" charset="utf-8" src="ueditor.all.js"></script>
  10. <script type="text/javascript" charset="utf-8" src="lang/zh-cn/zh-cn.js?7a537435"></script>
  11. <script src="./plugins/demo/demo.js"></script>
  12. <script>
  13. // window.UEDITOR_CONFIG.toolbars[0].push('undo');
  14. </script>
  15. <script>var _hmt = _hmt || [];
  16. (function () {
  17. var hm = document.createElement("script");
  18. hm.src = "https://hm.baidu.com/hm.js?f84f35a44b5cc5c0b10c3fabdf0f322b";
  19. var s = document.getElementsByTagName("script")[0];
  20. s.parentNode.insertBefore(hm, s);
  21. })();</script>
  22. <style>
  23. :root {
  24. /*--ueditor-top-offset: 20px;*/
  25. }
  26. </style>
  27. <link rel="stylesheet" href="./style.css"/>
  28. </head>
  29. <body class="demo-editor-page">
  30. <div>
  31. <h1>完整示例</h1>
  32. <div>
  33. <script id="editor" type="text/plain" style="height:300px;">
  34. <h1>
  35. 你好 UEditorPlus
  36. </h1>
  37. <p>
  38. 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>
  39. </p>
  40. <table data-sort="sortDisabled">
  41. <tbody>
  42. <tr class="firstRow">
  43. <td valign="top" style="word-break: break-all;" rowspan="1" colspan="3">
  44. 我是表格
  45. </td>
  46. </tr>
  47. <tr>
  48. <td width="273" valign="top" style="word-break: break-all;">
  49. 如果
  50. </td>
  51. <td width="273" valign="top" style="word-break: break-all;">
  52. 有一天
  53. </td>
  54. <td width="273" valign="top" style="word-break: break-all;">
  55. 我离开了
  56. </td>
  57. </tr>
  58. <tr>
  59. <td valign="top" colspan="1" rowspan="1" style="word-break: break-all;">
  60. 怎么才能
  61. </td>
  62. <td valign="top" colspan="1" rowspan="1" style="word-break: break-all;">
  63. 证明我
  64. </td>
  65. <td valign="top" colspan="1" rowspan="1" style="word-break: break-all;">
  66. 曾经来过
  67. </td>
  68. </tr>
  69. </tbody>
  70. </table>
  71. <pre class="brush:html;toolbar:false">&lt;div&gt;
  72. &lt;span&gt;这里是HTML标签&lt;/span&gt;
  73. &lt;/div&gt;</pre>
  74. <h2>
  75. 公式支持
  76. </h2>
  77. <p>
  78. <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"
  79. 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"/>
  80. </p>
  81. <p>
  82. <br/>
  83. </p>
  84. </script>
  85. </div>
  86. <div id="btns" style="margin-top:20px;">
  87. <div>
  88. <button onclick="alert(UE.getEditor('editor').getAllHtml())">获得整个html的内容</button>
  89. <button onclick="alert(UE.getEditor('editor').getContent())">获得内容</button>
  90. <button onclick="UE.getEditor('editor').setContent('<p>欢迎使用 UEditorPlus</p>', false)">写入内容</button>
  91. <button onclick="UE.getEditor('editor').setContent('<p>欢迎使用 UEditorPlus</p>', true)">追加内容</button>
  92. <button onclick="alert(UE.getEditor('editor').getContentTxt())">获得纯文本</button>
  93. <button onclick="alert(UE.getEditor('editor').getPlainTxt())">获得带格式的纯文本</button>
  94. <button onclick="alert(UE.getEditor('editor').hasContents())">判断是否有内容</button>
  95. <button onclick="UE.getEditor('editor').focus()">使编辑器获得焦点</button>
  96. <button onmousedown="isFocus()">编辑器是否获得焦点</button>
  97. <button onmousedown="setBlur()">编辑器失去焦点</button>
  98. <button onclick="getSelectText()">获得当前选中的文本</button>
  99. <button onclick="UE.getEditor('editor').execCommand('insertHtml', '插入的内容')">插入内容</button>
  100. <button onclick="UE.getEditor('editor').setEnabled()">设定可编辑</button>
  101. <button onclick="UE.getEditor('editor').setDisabled('fullscreen')">设定不可编辑</button>
  102. <button onclick="UE.getEditor('editor').setHide()">隐藏编辑器</button>
  103. <button onclick="UE.getEditor('editor').setShow()">显示编辑器</button>
  104. <button onclick="UE.getEditor('editor').setHeight(300)">设置固定高度</button>
  105. <button onclick="UE.getEditor('editor')">创建编辑器</button>
  106. <button onclick="UE.getEditor('editor').destroy()">销毁编辑器</button>
  107. <button onclick="alert( UE.getEditor('editor').execCommand('get_auto_save_content') )">草稿箱-获取</button>
  108. <button onclick="UE.getEditor('editor').execCommand('clear_auto_save_content'); alert('已清空草稿箱')">草稿箱-清空
  109. </button>
  110. <button onclick="UE.getEditor('editor').execCommand('set_auto_save_content'); alert('已保存')">草稿箱-立即保存
  111. </button>
  112. <button onclick="UE.getEditor('editor').execCommand('auto_save_restore')">草稿箱-恢复到编辑器</button>
  113. </div>
  114. </div>
  115. <script type="text/javascript">
  116. var ue = UE.getEditor('editor',{
  117. // autoHeightEnabled: false,
  118. });
  119. ue.on('contentchange', function () {
  120. // console.log('contentchange', ue.getContent());
  121. });
  122. function isFocus(e) {
  123. alert(UE.getEditor('editor').isFocus());
  124. UE.dom.domUtils.preventDefault(e)
  125. }
  126. function setBlur(e) {
  127. UE.getEditor('editor').blur();
  128. UE.dom.domUtils.preventDefault(e)
  129. }
  130. function getSelectText() {
  131. var range = UE.getEditor('editor').selection.getRange();
  132. range.select();
  133. var txt = UE.getEditor('editor').selection.getText();
  134. alert(txt)
  135. }
  136. </script>
  137. </div>
  138. </body>
  139. </html>