| 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-2009, 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>API usage - CKEditor Sample</title> |
|---|
| 9 | <script type="text/javascript" src="sample.js"></script> |
|---|
| 10 | <script id="headscript" type="text/javascript"> |
|---|
| 11 | //<![CDATA[ |
|---|
| 12 | |
|---|
| 13 | // The instanceReady event is fired when an instance of CKEditor has finished |
|---|
| 14 | // its initialization. |
|---|
| 15 | CKEDITOR.on( 'instanceReady', function( ev ) |
|---|
| 16 | { |
|---|
| 17 | // Show the editor name and description in the browser status bar. |
|---|
| 18 | document.getElementById('eMessage').innerHTML = '<p>Instance "' + ev.editor.name + '" loaded.</p>' ; |
|---|
| 19 | |
|---|
| 20 | // Show this sample buttons. |
|---|
| 21 | document.getElementById('eButtons').style.visibility = '' ; |
|---|
| 22 | }); |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | function InsertHTML() |
|---|
| 26 | { |
|---|
| 27 | // Get the editor instance that we want to interact with. |
|---|
| 28 | var oEditor = CKEDITOR.instances.editor1 ; |
|---|
| 29 | var value = document.getElementById( 'plainArea' ).value ; |
|---|
| 30 | |
|---|
| 31 | // Check the active editing mode. |
|---|
| 32 | if (oEditor.mode == 'wysiwyg' ) |
|---|
| 33 | { |
|---|
| 34 | // Insert the desired HTML. |
|---|
| 35 | oEditor.insertHtml( value ) ; |
|---|
| 36 | } |
|---|
| 37 | else |
|---|
| 38 | alert( 'You must be on WYSIWYG mode!' ) ; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | function SetContents() |
|---|
| 42 | { |
|---|
| 43 | // Get the editor instance that we want to interact with. |
|---|
| 44 | var oEditor = CKEDITOR.instances.editor1 ; |
|---|
| 45 | var value = document.getElementById( 'plainArea' ).value ; |
|---|
| 46 | |
|---|
| 47 | // Set the editor contents (replace the actual one). |
|---|
| 48 | oEditor.setData( value ) ; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | function GetContents() |
|---|
| 52 | { |
|---|
| 53 | // Get the editor instance that we want to interact with. |
|---|
| 54 | var oEditor = CKEDITOR.instances.editor1 ; |
|---|
| 55 | |
|---|
| 56 | // Get the editor contents |
|---|
| 57 | alert( oEditor.getData() ) ; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | function ExecuteCommand( commandName ) |
|---|
| 61 | { |
|---|
| 62 | // Get the editor instance that we want to interact with. |
|---|
| 63 | var oEditor = CKEDITOR.instances.editor1 ; |
|---|
| 64 | |
|---|
| 65 | // Execute the command. |
|---|
| 66 | oEditor.execCommand( commandName ) ; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | function CheckDirty() |
|---|
| 70 | { |
|---|
| 71 | // Get the editor instance that we want to interact with. |
|---|
| 72 | var oEditor = CKEDITOR.instances.editor1 ; |
|---|
| 73 | alert( oEditor.checkDirty() ) ; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | function ResetDirty() |
|---|
| 77 | { |
|---|
| 78 | // Get the editor instance that we want to interact with. |
|---|
| 79 | var oEditor = CKEDITOR.instances.editor1 ; |
|---|
| 80 | oEditor.resetDirty() ; |
|---|
| 81 | alert( 'The "IsDirty" status has been reset' ) ; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | //]]> |
|---|
| 85 | </script> |
|---|
| 86 | </head> |
|---|
| 87 | <body> |
|---|
| 88 | <div id="html"> |
|---|
| 89 | <p> |
|---|
| 90 | This sample shows how to use the CKeditor JavaScript API to interact with the editor |
|---|
| 91 | at runtime.</p> |
|---|
| 92 | <textarea id="editor1" name="editor1" rows="10" cols="80"><p>This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">CKEditor</a>.</p></textarea> |
|---|
| 93 | <script type="text/javascript"> |
|---|
| 94 | //<![CDATA[ |
|---|
| 95 | // Replace the <textarea id="editor1"> with an CKEditor instance. |
|---|
| 96 | var editor = CKEDITOR.replace( 'editor1'); |
|---|
| 97 | //]]> |
|---|
| 98 | </script> |
|---|
| 99 | <div id="eMessage"> |
|---|
| 100 | |
|---|
| 101 | </div> |
|---|
| 102 | <div id="eButtons" style="visibility: hidden"> |
|---|
| 103 | <input type="button" value="Insert HTML" onclick="InsertHTML();" /> |
|---|
| 104 | <input type="button" value="Set Editor Contents" onclick="SetContents();" /> |
|---|
| 105 | <input type="button" value="Get Editor Contents (XHTML)" onclick="GetContents();" /> |
|---|
| 106 | <br /> |
|---|
| 107 | <textarea id="plainArea" cols="80" rows="3"><h2>Test</h2><p>This is some <a href="/Test1.html">sample</a> HTML</p></textarea> |
|---|
| 108 | <br /> |
|---|
| 109 | <br /> |
|---|
| 110 | <input type="button" value='Execute "bold" Command' onclick="ExecuteCommand('bold');" /> |
|---|
| 111 | <input type="button" value='Execute "link" Command' onclick="ExecuteCommand('link');" /> |
|---|
| 112 | <br /> |
|---|
| 113 | <br /> |
|---|
| 114 | <input type="button" value="checkDirty()" onclick="CheckDirty();" /> |
|---|
| 115 | <input type="button" value="resetDirty()" onclick="ResetDirty();" /> |
|---|
| 116 | </div> |
|---|
| 117 | |
|---|
| 118 | </div> |
|---|
| 119 | </body> |
|---|
| 120 | </html> |
|---|