| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|---|
| 2 | <!-- |
|---|
| 3 | Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. |
|---|
| 4 | For licensing, see LICENSE.html or http://ckeditor.com/license |
|---|
| 5 | --> |
|---|
| 6 | <html xmlns="http://www.w3.org/1999/xhtml"> |
|---|
| 7 | <head> |
|---|
| 8 | <title>Ajax — CKEditor Sample</title> |
|---|
| 9 | <meta content="text/html; charset=utf-8" http-equiv="content-type" /> |
|---|
| 10 | <script type="text/javascript" src="../ckeditor.js"></script> |
|---|
| 11 | <script src="sample.js" type="text/javascript"></script> |
|---|
| 12 | <link href="sample.css" rel="stylesheet" type="text/css" /> |
|---|
| 13 | <script type="text/javascript"> |
|---|
| 14 | //<![CDATA[ |
|---|
| 15 | |
|---|
| 16 | var editor, html = ''; |
|---|
| 17 | |
|---|
| 18 | function createEditor() |
|---|
| 19 | { |
|---|
| 20 | if ( editor ) |
|---|
| 21 | return; |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | // Create a new editor inside the <div id="editor">, setting its value to html |
|---|
| 25 | var config = {}; |
|---|
| 26 | editor = CKEDITOR.appendTo( 'editor', config, html ); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | function removeEditor() |
|---|
| 30 | { |
|---|
| 31 | if ( !editor ) |
|---|
| 32 | return; |
|---|
| 33 | |
|---|
| 34 | // Retrieve the editor contents. In an Ajax application, this data would be |
|---|
| 35 | // sent to the server or used in any other way. |
|---|
| 36 | document.getElementById( 'editorcontents' ).innerHTML = html = editor.getData(); |
|---|
| 37 | document.getElementById( 'contents' ).style.display = ''; |
|---|
| 38 | |
|---|
| 39 | // Destroy the editor. |
|---|
| 40 | editor.destroy(); |
|---|
| 41 | editor = null; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | function moveEditor() |
|---|
| 45 | { |
|---|
| 46 | if (!editor) |
|---|
| 47 | { |
|---|
| 48 | alert("Create the editor first!"); |
|---|
| 49 | return; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | var editcontainer = document.getElementById("editor"); |
|---|
| 54 | var description = document.getElementById("description"); |
|---|
| 55 | description.parentNode.insertBefore(editcontainer, description); |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | //]]> |
|---|
| 59 | </script> |
|---|
| 60 | </head> |
|---|
| 61 | <body> |
|---|
| 62 | <h1 class="samples"> |
|---|
| 63 | CKEditor Sample — Create and Destroy Editor Instances for Ajax Applications |
|---|
| 64 | </h1> |
|---|
| 65 | <form> |
|---|
| 66 | <div class="description" id="description"> |
|---|
| 67 | <p> |
|---|
| 68 | This sample shows how to create and destroy CKEditor instances on the fly. After the removal of CKEditor the content created inside the editing |
|---|
| 69 | area will be displayed in a <code><div></code> element. |
|---|
| 70 | </p> |
|---|
| 71 | <p> |
|---|
| 72 | For details of how to create this setup check the source code of this sample page |
|---|
| 73 | for JavaScript code responsible for the creation and destruction of a CKEditor instance. |
|---|
| 74 | </p> |
|---|
| 75 | </div> |
|---|
| 76 | </form> |
|---|
| 77 | <!-- This <div> holds alert messages to be display in the sample page. --> |
|---|
| 78 | <div id="alerts"> |
|---|
| 79 | <noscript> |
|---|
| 80 | <p> |
|---|
| 81 | <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript |
|---|
| 82 | support, like yours, you should still see the contents (HTML data) and you should |
|---|
| 83 | be able to edit it normally, without a rich editor interface. |
|---|
| 84 | </p> |
|---|
| 85 | </noscript> |
|---|
| 86 | </div> |
|---|
| 87 | <p>Click the buttons to create and remove a CKEditor instance.</p> |
|---|
| 88 | <p> |
|---|
| 89 | <input onclick="createEditor();" type="button" value="Create Editor" /> |
|---|
| 90 | <input onclick="removeEditor();" type="button" value="Remove Editor" /> |
|---|
| 91 | <input onclick="moveEditor();" type="button" value="Move Editor" /> |
|---|
| 92 | </p> |
|---|
| 93 | <form id="editor"> |
|---|
| 94 | </form> |
|---|
| 95 | <div id="contents" style="display: none"> |
|---|
| 96 | <p> |
|---|
| 97 | Edited Contents:</p> |
|---|
| 98 | <!-- This div will be used to display the editor contents. --> |
|---|
| 99 | <div id="editorcontents"> |
|---|
| 100 | </div> |
|---|
| 101 | </div> |
|---|
| 102 | <div id="footer"> |
|---|
| 103 | <hr /> |
|---|
| 104 | <p> |
|---|
| 105 | CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a> |
|---|
| 106 | </p> |
|---|
| 107 | <p id="copy"> |
|---|
| 108 | Copyright © 2003-2011, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico |
|---|
| 109 | Knabben. All rights reserved. |
|---|
| 110 | </p> |
|---|
| 111 | </div> |
|---|
| 112 | </body> |
|---|
| 113 | </html> |
|---|