You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.4 KiB

  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
  4. For licensing, see LICENSE.html or http://ckeditor.com/license
  5. -->
  6. <html>
  7. <head>
  8. <title>Replace DIV &mdash; CKEditor Sample</title>
  9. <meta charset="utf-8">
  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="description">
  61. <p>
  62. This sample shows how to automatically replace <code>&lt;div&gt;</code> elements
  63. with a CKEditor instance on the fly, following user's doubleclick. The content
  64. that was previously placed inside the <code>&lt;div&gt;</code> element will now
  65. be moved into CKEditor editing area.
  66. </p>
  67. <p>
  68. For details on how to create this setup check the source code of this sample page.
  69. </p>
  70. </div>
  71. <p>
  72. Double-click any of the following <code>&lt;div&gt;</code> elements to transform them into
  73. editor instances.
  74. </p>
  75. <div class="editable">
  76. <h3>
  77. Part 1
  78. </h3>
  79. <p>
  80. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras et ipsum quis mi
  81. semper accumsan. Integer pretium dui id massa. Suspendisse in nisl sit amet urna
  82. rutrum imperdiet. Nulla eu tellus. Donec ante nisi, ullamcorper quis, fringilla
  83. nec, sagittis eleifend, pede. Nulla commodo interdum massa. Donec id metus. Fusce
  84. eu ipsum. Suspendisse auctor. Phasellus fermentum porttitor risus.
  85. </p>
  86. </div>
  87. <div class="editable">
  88. <h3>
  89. Part 2
  90. </h3>
  91. <p>
  92. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras et ipsum quis mi
  93. semper accumsan. Integer pretium dui id massa. Suspendisse in nisl sit amet urna
  94. rutrum imperdiet. Nulla eu tellus. Donec ante nisi, ullamcorper quis, fringilla
  95. nec, sagittis eleifend, pede. Nulla commodo interdum massa. Donec id metus. Fusce
  96. eu ipsum. Suspendisse auctor. Phasellus fermentum porttitor risus.
  97. </p>
  98. <p>
  99. Donec velit. Mauris massa. Vestibulum non nulla. Nam suscipit arcu nec elit. Phasellus
  100. sollicitudin iaculis ante. Ut non mauris et sapien tincidunt adipiscing. Vestibulum
  101. vitae leo. Suspendisse nec mi tristique nulla laoreet vulputate.
  102. </p>
  103. </div>
  104. <div class="editable">
  105. <h3>
  106. Part 3
  107. </h3>
  108. <p>
  109. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Cras et ipsum quis mi
  110. semper accumsan. Integer pretium dui id massa. Suspendisse in nisl sit amet urna
  111. rutrum imperdiet. Nulla eu tellus. Donec ante nisi, ullamcorper quis, fringilla
  112. nec, sagittis eleifend, pede. Nulla commodo interdum massa. Donec id metus. Fusce
  113. eu ipsum. Suspendisse auctor. Phasellus fermentum porttitor risus.
  114. </p>
  115. </div>
  116. <div id="footer">
  117. <hr>
  118. <p>
  119. CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
  120. </p>
  121. <p id="copy">
  122. Copyright &copy; 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
  123. Knabben. All rights reserved.
  124. </p>
  125. </div>
  126. </body>
  127. </html>