divreplace.html 4.4 KB

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