1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
\r
3 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
\r
4 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 <html xmlns="http://www.w3.org/1999/xhtml">
\r
8 <title>API usage - CKEditor Sample</title>
\r
9 <meta content="text/html; charset=utf-8" http-equiv="content-type" />
\r
10 <script type="text/javascript" src="../ckeditor.js"></script>
\r
11 <script src="sample.js" type="text/javascript"></script>
\r
12 <link href="sample.css" rel="stylesheet" type="text/css" />
\r
13 <script type="text/javascript">
\r
16 // The instanceReady event is fired when an instance of CKEditor has finished
\r
17 // its initialization.
\r
18 CKEDITOR.on( 'instanceReady', function( ev )
\r
20 // Show the editor name and description in the browser status bar.
\r
21 document.getElementById( 'eMessage' ).innerHTML = '<p>Instance "' + ev.editor.name + '" loaded.<\/p>';
\r
23 // Show this sample buttons.
\r
24 document.getElementById( 'eButtons' ).style.visibility = '';
\r
27 function InsertHTML()
\r
29 // Get the editor instance that we want to interact with.
\r
30 var oEditor = CKEDITOR.instances.editor1;
\r
31 var value = document.getElementById( 'plainArea' ).value;
\r
33 // Check the active editing mode.
\r
34 if ( oEditor.mode == 'wysiwyg' )
\r
36 // Insert the desired HTML.
\r
37 oEditor.insertHtml( value );
\r
40 alert( 'You must be on WYSIWYG mode!' );
\r
43 function SetContents()
\r
45 // Get the editor instance that we want to interact with.
\r
46 var oEditor = CKEDITOR.instances.editor1;
\r
47 var value = document.getElementById( 'plainArea' ).value;
\r
49 // Set the editor contents (replace the actual one).
\r
50 oEditor.setData( value );
\r
53 function GetContents()
\r
55 // Get the editor instance that we want to interact with.
\r
56 var oEditor = CKEDITOR.instances.editor1;
\r
58 // Get the editor contents
\r
59 alert( oEditor.getData() );
\r
62 function ExecuteCommand(commandName)
\r
64 // Get the editor instance that we want to interact with.
\r
65 var oEditor = CKEDITOR.instances.editor1;
\r
67 // Check the active editing mode.
\r
68 if ( oEditor.mode == 'wysiwyg' )
\r
70 // Execute the command.
\r
71 oEditor.execCommand( commandName );
\r
74 alert( 'You must be on WYSIWYG mode!' );
\r
77 function CheckDirty()
\r
79 // Get the editor instance that we want to interact with.
\r
80 var oEditor = CKEDITOR.instances.editor1;
\r
81 alert( oEditor.checkDirty() );
\r
84 function ResetDirty()
\r
86 // Get the editor instance that we want to interact with.
\r
87 var oEditor = CKEDITOR.instances.editor1;
\r
88 oEditor.resetDirty();
\r
89 alert( 'The "IsDirty" status has been reset' );
\r
100 <!-- This <div> holds alert messages to be display in the sample page. -->
\r
104 <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
\r
105 support, like yours, you should still see the contents (HTML data) and you should
\r
106 be able to edit it normally, without a rich editor interface.
\r
110 <form action="sample_posteddata.php" method="post">
\r
112 This sample shows how to use the CKeditor JavaScript API to interact with the editor
\r
114 <textarea cols="80" id="editor1" name="editor1" rows="10"><p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p></textarea>
\r
116 <script type="text/javascript">
\r
118 // Replace the <textarea id="editor1"> with an CKEditor instance.
\r
119 var editor = CKEDITOR.replace( 'editor1' );
\r
123 <div id="eMessage">
\r
125 <div id="eButtons" style="visibility: hidden">
\r
126 <input onclick="InsertHTML();" type="button" value="Insert HTML" />
\r
127 <input onclick="SetContents();" type="button" value="Set Editor Contents" />
\r
128 <input onclick="GetContents();" type="button" value="Get Editor Contents (XHTML)" />
\r
130 <textarea cols="80" id="plainArea" rows="3"><h2>Test</h2><p>This is some <a href="/Test1.html">sample</a> HTML</p></textarea>
\r
133 <input onclick="ExecuteCommand('bold');" type="button" value="Execute "bold" Command" />
\r
134 <input onclick="ExecuteCommand('link');" type="button" value="Execute "link" Command" />
\r
137 <input onclick="CheckDirty();" type="button" value="checkDirty()" />
\r
138 <input onclick="ResetDirty();" type="button" value="resetDirty()" />
\r
144 CKEditor - The text editor for Internet - <a href="http://ckeditor.com/">http://ckeditor.com</a>
\r
147 Copyright © 2003-2010, <a href="http://cksource.com/">CKSource</a> - Frederico
\r
148 Knabben. All rights reserved.
\r