indent.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  4. For licensing, see LICENSE.md or http://ckeditor.com/license
  5. -->
  6. <html>
  7. <head>
  8. <meta charset="utf-8">
  9. <title>Indent DEV sample</title>
  10. <script src="../../../ckeditor.js"></script>
  11. <style>
  12. body {
  13. padding: 20px;
  14. margin: 0;
  15. }
  16. .editors {
  17. display: block;
  18. overflow: hidden;
  19. width: 100%;
  20. margin: 0px auto;
  21. list-style-type: none;
  22. margin: 0;
  23. padding: 0;
  24. box-sizing: content-box;
  25. background: #eee;
  26. }
  27. .editors li {
  28. width: 50%;
  29. margin: 0;
  30. padding: 10px;
  31. float: left;
  32. box-sizing: border-box;
  33. }
  34. .editors li:nth-child(2n) {
  35. background: #D4E59A;
  36. }
  37. #menu {
  38. position: fixed;
  39. top: 0;
  40. right: 20px;
  41. padding: 5px;
  42. border: 1px solid #aaa;
  43. background: #eee;
  44. }
  45. </style>
  46. </head>
  47. <body>
  48. <p id="menu">
  49. <a href="#listnblock">List &amp; Block</a>,
  50. <a href="#classes">Classes</a>,
  51. <a href="#list">List</a>,
  52. <a href="#block">Block</a>,
  53. <a href="#br">ENTER_BR</a>
  54. </p>
  55. <h1 class="samples">Indent DEV sample</h1>
  56. <h2 id="listnblock">List &amp; Block</h2>
  57. <ul class="editors">
  58. <li>
  59. <textarea cols="80" id="editor1" rows="10">
  60. <p>xx</p>
  61. <ul>
  62. <li>x</li>
  63. <li>y</li>
  64. </ul>
  65. <p>xx</p>
  66. <br>
  67. <ul><li><ol><li>xx</li></ol></li><li>yy</li></ul>
  68. </textarea>
  69. </li>
  70. <li>
  71. <pre id="editor1_out"></pre>
  72. </li>
  73. </ul>
  74. <h2 id="classes">Indent classes</h2>
  75. <ul class="editors">
  76. <li>
  77. <textarea cols="80" id="editor2" rows="10">
  78. <ul>
  79. <li>a</li>
  80. <li>
  81. b
  82. <ol>
  83. <li>inner</li>
  84. </ol>
  85. </li>
  86. <li>c</li>
  87. </ul>
  88. <p>moo</p>
  89. </textarea>
  90. </li>
  91. <li>
  92. <pre id="editor2_out"></pre>
  93. </li>
  94. </ul>
  95. <h2 id="list">List only</h2>
  96. <ul class="editors">
  97. <li>
  98. <textarea cols="80" id="editor3" rows="10">
  99. <ul>
  100. <li>a</li>
  101. <li>
  102. b
  103. <ol>
  104. <li>inner</li>
  105. </ol>
  106. </li>
  107. <li>c</li>
  108. </ul>
  109. <p>moo</p>
  110. </textarea>
  111. </li>
  112. <li>
  113. <pre id="editor3_out"></pre>
  114. </li>
  115. </ul>
  116. <h2 id="block">Block only</h2>
  117. <ul class="editors">
  118. <li>
  119. <textarea cols="80" id="editor4" rows="10">
  120. <ul>
  121. <li>a</li>
  122. <li>
  123. b
  124. <ol>
  125. <li>inner</li>
  126. </ol>
  127. </li>
  128. <li>c</li>
  129. </ul>
  130. <p>moo</p>
  131. </textarea>
  132. </li>
  133. <li>
  134. <pre id="editor4_out"></pre>
  135. </li>
  136. </ul>
  137. <h2 id="br">CKEDITOR.ENTER_BR</h2>
  138. <ul class="editors">
  139. <li>
  140. <textarea cols="80" id="editor5" rows="10">
  141. Text
  142. <br>
  143. <ul>
  144. <li>a</li>
  145. <li>b</li>
  146. </ul>
  147. </textarea>
  148. </li>
  149. <li>
  150. <pre id="editor5_out"></pre>
  151. </li>
  152. </ul>
  153. <script>
  154. var plugins = 'enterkey,toolbar,htmlwriter,wysiwygarea,undo,sourcearea,clipboard,list,justify,indent,indentlist,indentblock';
  155. CKEDITOR.config.indentOffset = 10;
  156. CKEDITOR.addCss( '\
  157. .i1{ margin-left: 10px}\
  158. .i2{ margin-left: 20px}\
  159. .i3{ margin-left: 30px}' );
  160. function showData( event ) {
  161. CKEDITOR.document.getById( this.name + '_out' ).setText( getHtmlWithSelection( this ) );
  162. }
  163. function browserHtmlFix( html ) {
  164. if ( CKEDITOR.env.ie && ( document.documentMode || CKEDITOR.env.version ) < 9 ) {
  165. // Fix output base href on anchored link.
  166. html = html.replace( /href="(.*?)#(.*?)"/gi,
  167. function( m, base, anchor ) {
  168. if ( base == window.location.href.replace( window.location.hash, '' ) )
  169. return 'href="#' + anchor + '"';
  170. return m;
  171. } );
  172. // Fix output line break after HR.
  173. html = html.replace( /(<HR>)\r\n/gi, function( m, hr ) { return hr; } );
  174. }
  175. return html;
  176. }
  177. function getHtmlWithSelection( editorOrElement, root ) {
  178. var isEditor = editorOrElement instanceof CKEDITOR.editor,
  179. element = isEditor ? editorOrElement.editable() : editorOrElement;
  180. root = isEditor ? element :
  181. root instanceof CKEDITOR.dom.document ?
  182. root.getBody() : root || CKEDITOR.document.getBody();
  183. function replaceWithBookmark( match, startOrEnd ) {
  184. var bookmark;
  185. switch( startOrEnd ) {
  186. case 'S' :
  187. bookmark = '[';
  188. break;
  189. case 'E' :
  190. bookmark = ']';
  191. break;
  192. case 'C' :
  193. bookmark = '^';
  194. break;
  195. }
  196. return bookmark;
  197. }
  198. // Hack: force remove the filling char hack in Webkit.
  199. isEditor && CKEDITOR.env.webkit && editorOrElement.fire( 'beforeSetMode' );
  200. var sel = isEditor ? editorOrElement.getSelection()
  201. : new CKEDITOR.dom.selection( root );
  202. var doc = sel.document;
  203. var ranges = sel.getRanges(),
  204. range;
  205. var bms = [];
  206. var iter = ranges.createIterator();
  207. while( range = iter.getNextRange() )
  208. bms.push( range.createBookmark( 1 ) );
  209. var html = browserHtmlFix( isEditor ? editorOrElement.getData() : element.getHtml() );
  210. html = html.replace( /<span\b[^>]*?id="?cke_bm_\d+(\w)"?\b[^>]*?>.*?<\/span>/gi,
  211. replaceWithBookmark );
  212. for ( var i = 0, bm; i < bms.length; i++ ) {
  213. bm = bms[ i ];
  214. var start = doc.getById( bm.startNode ),
  215. end = doc.getById( bm.endNode );
  216. start && start.remove();
  217. end && end.remove();
  218. }
  219. return html;
  220. }
  221. CKEDITOR.on( 'instanceReady', function ( event ) {
  222. var editor = event.editor;
  223. showData.call( editor );
  224. editor.on( 'afterCommandExec', showData, editor );
  225. });
  226. CKEDITOR.replace( 'editor1', {
  227. plugins: plugins
  228. } );
  229. CKEDITOR.replace( 'editor2', {
  230. plugins: plugins,
  231. indentClasses: [ 'i1', 'i2', 'i3' ]
  232. } );
  233. CKEDITOR.replace( 'editor3', {
  234. plugins: plugins,
  235. removePlugins: 'indentblock'
  236. } );
  237. CKEDITOR.replace( 'editor4', {
  238. plugins: plugins,
  239. removePlugins: 'indentlist'
  240. } );
  241. CKEDITOR.replace( 'editor5', {
  242. plugins: plugins,
  243. enterMode: CKEDITOR.ENTER_BR
  244. } );
  245. </script>
  246. </body>
  247. </html>