ajax.html 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2017, 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>Ajax &mdash; CKEditor Sample</title>
  10. <script src="../../ckeditor.js"></script>
  11. <link rel="stylesheet" href="sample.css">
  12. <script>
  13. var editor, html = '';
  14. function createEditor() {
  15. if ( editor )
  16. return;
  17. // Create a new editor inside the <div id="editor">, setting its value to html
  18. var config = {};
  19. editor = CKEDITOR.appendTo( 'editor', config, html );
  20. }
  21. function removeEditor() {
  22. if ( !editor )
  23. return;
  24. // Retrieve the editor contents. In an Ajax application, this data would be
  25. // sent to the server or used in any other way.
  26. document.getElementById( 'editorcontents' ).innerHTML = html = editor.getData();
  27. document.getElementById( 'contents' ).style.display = '';
  28. // Destroy the editor.
  29. editor.destroy();
  30. editor = null;
  31. }
  32. </script>
  33. </head>
  34. <body>
  35. <h1 class="samples">
  36. <a href="index.html">CKEditor Samples</a> &raquo; Create and Destroy Editor Instances for Ajax Applications
  37. </h1>
  38. <div class="warning deprecated">
  39. This sample is not maintained anymore. Check out its <a href="http://sdk.ckeditor.com/samples/saveajax.html">brand new version in CKEditor SDK</a>.
  40. </div>
  41. <div class="description">
  42. <p>
  43. This sample shows how to create and destroy CKEditor instances on the fly. After the removal of CKEditor the content created inside the editing
  44. area will be displayed in a <code>&lt;div&gt;</code> element.
  45. </p>
  46. <p>
  47. For details of how to create this setup check the source code of this sample page
  48. for JavaScript code responsible for the creation and destruction of a CKEditor instance.
  49. </p>
  50. </div>
  51. <p>Click the buttons to create and remove a CKEditor instance.</p>
  52. <p>
  53. <input onclick="createEditor();" type="button" value="Create Editor">
  54. <input onclick="removeEditor();" type="button" value="Remove Editor">
  55. </p>
  56. <!-- This div will hold the editor. -->
  57. <div id="editor">
  58. </div>
  59. <div id="contents" style="display: none">
  60. <p>
  61. Edited Contents:
  62. </p>
  63. <!-- This div will be used to display the editor contents. -->
  64. <div id="editorcontents">
  65. </div>
  66. </div>
  67. <div id="footer">
  68. <hr>
  69. <p>
  70. CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
  71. </p>
  72. <p id="copy">
  73. Copyright &copy; 2003-2017, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
  74. Knabben. All rights reserved.
  75. </p>
  76. </div>
  77. </body>
  78. </html>