index.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  5. <title>UMEDITOR 完整demo</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  7. <link href="themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
  8. <script type="text/javascript" src="third-party/jquery.min.js"></script>
  9. <script type="text/javascript" charset="utf-8" src="umeditor.config.js"></script>
  10. <script type="text/javascript" charset="utf-8" src="umeditor.min.js"></script>
  11. <script type="text/javascript" src="lang/zh-cn/zh-cn.js"></script>
  12. <style type="text/css">
  13. h1{
  14. font-family: "微软雅黑";
  15. font-weight: normal;
  16. }
  17. .btn {
  18. display: inline-block;
  19. *display: inline;
  20. padding: 4px 12px;
  21. margin-bottom: 0;
  22. *margin-left: .3em;
  23. font-size: 14px;
  24. line-height: 20px;
  25. color: #333333;
  26. text-align: center;
  27. text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
  28. vertical-align: middle;
  29. cursor: pointer;
  30. background-color: #f5f5f5;
  31. *background-color: #e6e6e6;
  32. background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6);
  33. background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6));
  34. background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6);
  35. background-image: -o-linear-gradient(top, #ffffff, #e6e6e6);
  36. background-image: linear-gradient(to bottom, #ffffff, #e6e6e6);
  37. background-repeat: repeat-x;
  38. border: 1px solid #cccccc;
  39. *border: 0;
  40. border-color: #e6e6e6 #e6e6e6 #bfbfbf;
  41. border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
  42. border-bottom-color: #b3b3b3;
  43. -webkit-border-radius: 4px;
  44. -moz-border-radius: 4px;
  45. border-radius: 4px;
  46. filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe6e6e6', GradientType=0);
  47. filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
  48. *zoom: 1;
  49. -webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
  50. -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
  51. box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05);
  52. }
  53. .btn:hover,
  54. .btn:focus,
  55. .btn:active,
  56. .btn.active,
  57. .btn.disabled,
  58. .btn[disabled] {
  59. color: #333333;
  60. background-color: #e6e6e6;
  61. *background-color: #d9d9d9;
  62. }
  63. .btn:active,
  64. .btn.active {
  65. background-color: #cccccc \9;
  66. }
  67. .btn:first-child {
  68. *margin-left: 0;
  69. }
  70. .btn:hover,
  71. .btn:focus {
  72. color: #333333;
  73. text-decoration: none;
  74. background-position: 0 -15px;
  75. -webkit-transition: background-position 0.1s linear;
  76. -moz-transition: background-position 0.1s linear;
  77. -o-transition: background-position 0.1s linear;
  78. transition: background-position 0.1s linear;
  79. }
  80. .btn:focus {
  81. outline: thin dotted #333;
  82. outline: 5px auto -webkit-focus-ring-color;
  83. outline-offset: -2px;
  84. }
  85. .btn.active,
  86. .btn:active {
  87. background-image: none;
  88. outline: 0;
  89. -webkit-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
  90. -moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
  91. box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
  92. }
  93. .btn.disabled,
  94. .btn[disabled] {
  95. cursor: default;
  96. background-image: none;
  97. opacity: 0.65;
  98. filter: alpha(opacity=65);
  99. -webkit-box-shadow: none;
  100. -moz-box-shadow: none;
  101. box-shadow: none;
  102. }
  103. </style>
  104. </head>
  105. <body>
  106. <h1>UMEDITOR 完整demo</h1>
  107. <!--style给定宽度可以影响编辑器的最终宽度-->
  108. <script type="text/plain" id="myEditor" style="width:1000px;height:240px;">
  109. <p>这里我可以写一些输入提示</p>
  110. </script>
  111. <div class="clear"></div>
  112. <div id="btns">
  113. <table>
  114. <tr>
  115. <td>
  116. <button class="btn" unselected="on" onclick="getAllHtml()">获得整个html的内容</button>&nbsp;
  117. <button class="btn" onclick="getContent()">获得内容</button>&nbsp;
  118. <button class="btn" onclick="setContent()">写入内容</button>&nbsp;
  119. <button class="btn" onclick="setContent(true)">追加内容</button>&nbsp;
  120. <button class="btn" onclick="getContentTxt()">获得纯文本</button>&nbsp;
  121. <button class="btn" onclick="getPlainTxt()">获得带格式的纯文本</button>&nbsp;
  122. <button class="btn" onclick="hasContent()">判断是否有内容</button>
  123. </td>
  124. </tr>
  125. <tr>
  126. <td>
  127. <button class="btn" onclick="setFocus()">编辑器获得焦点</button>&nbsp;
  128. <button class="btn" onmousedown="isFocus();return false;">编辑器是否获得焦点</button>&nbsp;
  129. <button class="btn" onclick="doBlur()">编辑器取消焦点</button>&nbsp;
  130. <button class="btn" onclick="insertHtml()">插入给定的内容</button>&nbsp;
  131. <button class="btn" onclick="getContentTxt()">获得纯文本</button>&nbsp;
  132. <button class="btn" id="enable" onclick="setEnabled()">可以编辑</button>&nbsp;
  133. <button class="btn" onclick="setDisabled()">不可编辑</button>
  134. </td>
  135. </tr>
  136. <tr>
  137. <td>
  138. <button class="btn" onclick="UM.getEditor('myEditor').setHide()">隐藏编辑器</button>&nbsp;
  139. <button class="btn" onclick="UM.getEditor('myEditor').setShow()">显示编辑器</button>&nbsp;
  140. <button class="btn" onclick="UM.getEditor('myEditor').setHeight(300)">设置编辑器的高度为300</button>&nbsp;
  141. <button class="btn" onclick="UM.getEditor('myEditor').setWidth(1200)">设置编辑器的宽度为1200</button>
  142. </td>
  143. </tr>
  144. </table>
  145. </div>
  146. <table>
  147. <tr>
  148. <td>
  149. <button class="btn" onclick="createEditor()"/>创建编辑器</button>
  150. <button class="btn" onclick="deleteEditor()"/>删除编辑器</button>
  151. </td>
  152. </tr>
  153. </table>
  154. <div>
  155. <h3 id="focush2"></h3>
  156. </div>
  157. <script type="text/javascript">
  158. //实例化编辑器
  159. var um = UM.getEditor('myEditor');
  160. um.addListener('blur',function(){
  161. $('#focush2').html('编辑器失去焦点了')
  162. });
  163. um.addListener('focus',function(){
  164. $('#focush2').html('')
  165. });
  166. //按钮的操作
  167. function insertHtml() {
  168. var value = prompt('插入html代码', '');
  169. um.execCommand('insertHtml', value)
  170. }
  171. function isFocus(){
  172. alert(um.isFocus())
  173. }
  174. function doBlur(){
  175. um.blur()
  176. }
  177. function createEditor() {
  178. enableBtn();
  179. um = UM.getEditor('myEditor');
  180. }
  181. function getAllHtml() {
  182. alert(UM.getEditor('myEditor').getAllHtml())
  183. }
  184. function getContent() {
  185. var arr = [];
  186. arr.push("使用editor.getContent()方法可以获得编辑器的内容");
  187. arr.push("内容为:");
  188. arr.push(UM.getEditor('myEditor').getContent());
  189. alert(arr.join("\n"));
  190. }
  191. function getPlainTxt() {
  192. var arr = [];
  193. arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
  194. arr.push("内容为:");
  195. arr.push(UM.getEditor('myEditor').getPlainTxt());
  196. alert(arr.join('\n'))
  197. }
  198. function setContent(isAppendTo) {
  199. var arr = [];
  200. arr.push("使用editor.setContent('欢迎使用umeditor')方法可以设置编辑器的内容");
  201. UM.getEditor('myEditor').setContent('欢迎使用umeditor', isAppendTo);
  202. alert(arr.join("\n"));
  203. }
  204. function setDisabled() {
  205. UM.getEditor('myEditor').setDisabled('fullscreen');
  206. disableBtn("enable");
  207. }
  208. function setEnabled() {
  209. UM.getEditor('myEditor').setEnabled();
  210. enableBtn();
  211. }
  212. function getText() {
  213. //当你点击按钮时编辑区域已经失去了焦点,如果直接用getText将不会得到内容,所以要在选回来,然后取得内容
  214. var range = UM.getEditor('myEditor').selection.getRange();
  215. range.select();
  216. var txt = UM.getEditor('myEditor').selection.getText();
  217. alert(txt)
  218. }
  219. function getContentTxt() {
  220. var arr = [];
  221. arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
  222. arr.push("编辑器的纯文本内容为:");
  223. arr.push(UM.getEditor('myEditor').getContentTxt());
  224. alert(arr.join("\n"));
  225. }
  226. function hasContent() {
  227. var arr = [];
  228. arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
  229. arr.push("判断结果为:");
  230. arr.push(UM.getEditor('myEditor').hasContents());
  231. alert(arr.join("\n"));
  232. }
  233. function setFocus() {
  234. UM.getEditor('myEditor').focus();
  235. }
  236. function deleteEditor() {
  237. disableBtn();
  238. UM.getEditor('myEditor').destroy();
  239. }
  240. function disableBtn(str) {
  241. var div = document.getElementById('btns');
  242. var btns = domUtils.getElementsByTagName(div, "button");
  243. for (var i = 0, btn; btn = btns[i++];) {
  244. if (btn.id == str) {
  245. domUtils.removeAttributes(btn, ["disabled"]);
  246. } else {
  247. btn.setAttribute("disabled", "true");
  248. }
  249. }
  250. }
  251. function enableBtn() {
  252. var div = document.getElementById('btns');
  253. var btns = domUtils.getElementsByTagName(div, "button");
  254. for (var i = 0, btn; btn = btns[i++];) {
  255. domUtils.removeAttributes(btn, ["disabled"]);
  256. }
  257. }
  258. </script>
  259. </body>
  260. </html>