clipboard.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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>Clipboard playground &ndash; CKEditor Sample</title>
  10. <script src="../../../ckeditor.js"></script>
  11. <link href="../../../samples/old/sample.css" rel="stylesheet">
  12. <style>
  13. body {
  14. margin: 0;
  15. }
  16. #editables, #console
  17. {
  18. width: 48%;
  19. }
  20. #editable {
  21. padding: 5px 10px;
  22. }
  23. #console {
  24. position: fixed;
  25. top: 10px;
  26. right: 30px;
  27. height: 500px;
  28. border: solid 3px #555;
  29. overflow: auto;
  30. }
  31. #console > p {
  32. border-bottom: solid 1px #555;
  33. margin: 0;
  34. padding: 0 5px;
  35. background: rgba(0, 0, 0, 0.25);
  36. transition: background-color 1s;
  37. }
  38. #console > p.old {
  39. background: rgba(0, 0, 0, 0);
  40. }
  41. #console time, #console .prompt {
  42. padding: 0 5px;
  43. display: inline-block;
  44. }
  45. #console time {
  46. background: #999;
  47. background: rgba(0, 0, 0, 0.5 );
  48. color: #FFF;
  49. margin-left: -5px;
  50. }
  51. #console .prompt {
  52. background: #DDD;
  53. background: rgba(0, 0, 0, 0.1 );
  54. min-width: 200px;
  55. }
  56. .someClass {
  57. color: blue;
  58. }
  59. .specChar {
  60. color: #777;
  61. background-color: #EEE;
  62. background-color: rgba(0, 0, 0, 0.1);
  63. font-size: 0.8em;
  64. border-radius: 2px;
  65. padding: 1px;
  66. }
  67. </style>
  68. </head>
  69. <body>
  70. <h1 class="samples">
  71. CKEditor Sample &mdash; clipboard plugin playground
  72. </h1>
  73. <div id="editables">
  74. <p>
  75. <label for="editor1">
  76. Editor 1:</label>
  77. <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>
  78. </p>
  79. <p>
  80. <label for="editor2">
  81. Editor 2:</label>
  82. <textarea cols="80" id="editor2" name="editor2" rows="10">&lt;p&gt;This is more &lt;strong class="MsoNormal"&gt;sample text&lt;/strong&gt;.&lt;/p&gt;</textarea>
  83. </p>
  84. <p>
  85. <label for="editor3">
  86. Editor 3:</label>
  87. <textarea cols="80" id="editor3" name="editor3" rows="10">&lt;p&gt;This editor &lt;strong&gt;forces pasting in text mode&lt;/strong&gt; by listening for "beforePaste" event.&lt;/p&gt;</textarea>
  88. </p>
  89. <p>
  90. <label for="editor4">
  91. Editor 4:</label>
  92. <textarea cols="80" id="editor4" name="editor4" rows="10">&lt;p&gt;This editor &lt;strong&gt;forces pasting in text mode&lt;/strong&gt; by "forcePasteAsPlainText" config option.&lt;/p&gt;</textarea>
  93. </p>
  94. <p>
  95. <label for="editor5">
  96. Editor 5:</label>
  97. <textarea cols="80" id="editor5" name="editor5" rows="10">Editor with autoParagraphing set to off.</textarea>
  98. </p>
  99. <div id="editor6" contenteditable="true" style="font-family: Georgia; font-size: 14px">
  100. <h1>Editor 6</h1>
  101. <p>Content content content.</p>
  102. <p class="someClass">Styled by <code>.someClass</code>.</p>
  103. </div>
  104. </div>
  105. <div id="console">
  106. </div>
  107. <script>
  108. ( function()
  109. {
  110. 'use strict';
  111. var log = window.__log = function( title, msg ) {
  112. var msgEl = new CKEDITOR.dom.element( 'p' ),
  113. consoleEl = CKEDITOR.document.getById( 'console' ),
  114. time = new Date().toString().match( /\d\d:\d\d:\d\d/ )[ 0 ],
  115. format = function( tpl ) {
  116. return tpl.replace( /{time}/g, time ).replace( '{title}', title ).replace( '{msg}', msg || '' );
  117. };
  118. window.console && console.log && console.log( format( '[{time}] {title}: {msg}' ) );
  119. msg = ( msg || '' ).replace( /\r/g, '{\\r}' ).replace( /\n/g, '{\\n}' ).replace( /\t/g, '{\\t}' );
  120. msg = CKEDITOR.tools.htmlEncode( msg );
  121. msg = msg.replace( /\{(\\\w)\}/g, '<code class="specChar">$1</code>' );
  122. msgEl.setHtml( format( '<time datetime="{time}">{time}</time><span class="prompt">{title}</span> {msg}' ) );
  123. consoleEl.append( msgEl );
  124. consoleEl.$.scrollTop = consoleEl.$.scrollHeight;
  125. setTimeout( function() { msgEl.addClass( 'old' ); }, 250 );
  126. };
  127. var observe = function( editor, num ) {
  128. var p = 'EDITOR ' + num + ' > ';
  129. editor.on( 'paste', function( event ) {
  130. log( p + 'paste(prior:-1)', event.data.type + ' - "' + event.data.dataValue + '"' );
  131. }, null, null, -1 );
  132. editor.on( 'paste', function( event ) {
  133. log( p + 'paste(prior:10)', event.data.type + ' - "' + event.data.dataValue + '"' );
  134. } );
  135. editor.on( 'paste', function( event ) {
  136. log( p + 'paste(prior:999)', event.data.type + ' - "' + event.data.dataValue + '"' );
  137. }, null, null, 999 );
  138. editor.on( 'beforePaste', function( event ) {
  139. log( p + 'beforePaste', event.data.type );
  140. } );
  141. editor.on( 'beforePaste', function( event ) {
  142. log( p + 'beforePaste(prior:999)', event.data.type );
  143. }, null, null, 999 );
  144. editor.on( 'afterPaste', function( event ) {
  145. log( p + 'afterPaste' );
  146. } );
  147. editor.on( 'copy', function( event ) {
  148. log( p + 'copy' );
  149. } );
  150. editor.on( 'cut', function( event ) {
  151. log( p + 'cut' );
  152. } );
  153. };
  154. CKEDITOR.disableAutoInline = true;
  155. var config = {
  156. height: 120,
  157. toolbar: [ [ 'Source' ] ],
  158. allowedContent: true
  159. },
  160. editor1 = CKEDITOR.replace( 'editor1', config ),
  161. editor2 = CKEDITOR.replace( 'editor2', config ),
  162. editor3 = CKEDITOR.replace( 'editor3', config ),
  163. editor4 = CKEDITOR.replace( 'editor4', CKEDITOR.tools.extend( { forcePasteAsPlainText: true }, config ) ),
  164. editor5 = CKEDITOR.replace( 'editor5', CKEDITOR.tools.extend( { autoParagraph: false }, config ) ),
  165. editor6 = CKEDITOR.inline( document.getElementById( 'editor6' ), config );
  166. editor3.on( 'beforePaste', function( evt ) {
  167. evt.data.type = 'text';
  168. } );
  169. observe( editor1, 1 );
  170. observe( editor2, 2 );
  171. observe( editor3, 3 );
  172. observe( editor4, 4 );
  173. observe( editor5, 5 );
  174. observe( editor6, 6 );
  175. })();
  176. </script>
  177. </body>
  178. </html>