divreplace.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
  4. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  5. -->
  6. <html lang="en">
  7. <head>
  8. <meta charset="utf-8">
  9. <title>Replace DIV &mdash; CKEditor Sample</title>
  10. <script src="../../ckeditor.js"></script>
  11. <link href="sample.css" rel="stylesheet">
  12. <meta name="description" content="Try the latest sample of CKEditor 4 and learn more about customizing your WYSIWYG editor with endless possibilities.">
  13. <style>
  14. div.editable
  15. {
  16. border: solid 2px transparent;
  17. padding-left: 15px;
  18. padding-right: 15px;
  19. }
  20. div.editable:hover
  21. {
  22. border-color: black;
  23. }
  24. </style>
  25. <script>
  26. // Uncomment the following code to test the "Timeout Loading Method".
  27. // CKEDITOR.loadFullCoreTimeout = 5;
  28. window.onload = function() {
  29. // Listen to the double click event.
  30. if ( window.addEventListener )
  31. document.body.addEventListener( 'dblclick', onDoubleClick, false );
  32. else if ( window.attachEvent )
  33. document.body.attachEvent( 'ondblclick', onDoubleClick );
  34. };
  35. function onDoubleClick( ev ) {
  36. // Get the element which fired the event. This is not necessarily the
  37. // element to which the event has been attached.
  38. var element = ev.target || ev.srcElement;
  39. // Find out the div that holds this element.
  40. var name;
  41. do {
  42. element = element.parentNode;
  43. }
  44. while ( element && ( name = element.nodeName.toLowerCase() ) &&
  45. ( name != 'div' || element.className.indexOf( 'editable' ) == -1 ) && name != 'body' );
  46. if ( name == 'div' && element.className.indexOf( 'editable' ) != -1 )
  47. replaceDiv( element );
  48. }
  49. var editor;
  50. function replaceDiv( div ) {
  51. if ( editor )
  52. editor.destroy();
  53. editor = CKEDITOR.replace( div );
  54. }
  55. </script>
  56. </head>
  57. <body>
  58. <h1 class="samples">
  59. <a href="index.html">CKEditor Samples</a> &raquo; Replace DIV with CKEditor on the Fly
  60. </h1>
  61. <div class="warning deprecated">
  62. This sample is not maintained anymore. Check out the <a href="https://ckeditor.com/docs/ckeditor4/latest/examples/index.html">brand new samples in CKEditor Examples</a>.
  63. </div>
  64. <div class="description">
  65. <p>
  66. This sample shows how to automatically replace <code>&lt;div&gt;</code> elements
  67. with a CKEditor instance on the fly, following user's doubleclick. The content
  68. that was previously placed inside the <code>&lt;div&gt;</code> element will now
  69. be moved into CKEditor editing area.
  70. </p>
  71. <p>
  72. For details on how to create this setup check the source code of this sample page.
  73. </p>
  74. </div>
  75. <p>
  76. Double-click any of the following <code>&lt;div&gt;</code> elements to transform them into
  77. editor instances.
  78. </p>
  79. <div class="editable">
  80. <h3>
  81. Part 1
  82. </h3>
  83. <p>
  84. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras et ipsum quis mi
  85. semper accumsan. Integer pretium dui id massa. Suspendisse in nisl sit amet urna
  86. rutrum imperdiet. Nulla eu tellus. Donec ante nisi, ullamcorper quis, fringilla
  87. nec, sagittis eleifend, pede. Nulla commodo interdum massa. Donec id metus. Fusce
  88. eu ipsum. Suspendisse auctor. Phasellus fermentum porttitor risus.
  89. </p>
  90. </div>
  91. <div class="editable">
  92. <h3>
  93. Part 2
  94. </h3>
  95. <p>
  96. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras et ipsum quis mi
  97. semper accumsan. Integer pretium dui id massa. Suspendisse in nisl sit amet urna
  98. rutrum imperdiet. Nulla eu tellus. Donec ante nisi, ullamcorper quis, fringilla
  99. nec, sagittis eleifend, pede. Nulla commodo interdum massa. Donec id metus. Fusce
  100. eu ipsum. Suspendisse auctor. Phasellus fermentum porttitor risus.
  101. </p>
  102. <p>
  103. Donec velit. Mauris massa. Vestibulum non nulla. Nam suscipit arcu nec elit. Phasellus
  104. sollicitudin iaculis ante. Ut non mauris et sapien tincidunt adipiscing. Vestibulum
  105. vitae leo. Suspendisse nec mi tristique nulla laoreet vulputate.
  106. </p>
  107. </div>
  108. <div class="editable">
  109. <h3>
  110. Part 3
  111. </h3>
  112. <p>
  113. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras et ipsum quis mi
  114. semper accumsan. Integer pretium dui id massa. Suspendisse in nisl sit amet urna
  115. rutrum imperdiet. Nulla eu tellus. Donec ante nisi, ullamcorper quis, fringilla
  116. nec, sagittis eleifend, pede. Nulla commodo interdum massa. Donec id metus. Fusce
  117. eu ipsum. Suspendisse auctor. Phasellus fermentum porttitor risus.
  118. </p>
  119. </div>
  120. <div id="footer">
  121. <hr>
  122. <p>
  123. CKEditor - The text editor for the Internet - <a class="samples" href="https://ckeditor.com/">https://ckeditor.com</a>
  124. </p>
  125. <p id="copy">
  126. Copyright &copy; 2003-2023, <a class="samples" href="https://cksource.com/">CKSource</a> Holding sp. z o.o. All rights reserved.
  127. </p>
  128. </div>
  129. </body>
  130. </html>