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-2012, 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 <code>' + ev.editor.name + '<\/code> loaded.<\/p>';
\r
23 // Show this sample buttons.
\r
24 document.getElementById( 'eButtons' ).style.display = 'block';
\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( 'htmlArea' ).value;
\r
33 // Check the active editing mode.
\r
34 if ( oEditor.mode == 'wysiwyg' )
\r
36 // Insert HTML code.
\r
37 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#insertHtml
\r
38 oEditor.insertHtml( value );
\r
41 alert( 'You must be in WYSIWYG mode!' );
\r
44 function InsertText()
\r
46 // Get the editor instance that we want to interact with.
\r
47 var oEditor = CKEDITOR.instances.editor1;
\r
48 var value = document.getElementById( 'txtArea' ).value;
\r
50 // Check the active editing mode.
\r
51 if ( oEditor.mode == 'wysiwyg' )
\r
53 // Insert as plain text.
\r
54 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#insertText
\r
55 oEditor.insertText( value );
\r
58 alert( 'You must be in WYSIWYG mode!' );
\r
61 function SetContents()
\r
63 // Get the editor instance that we want to interact with.
\r
64 var oEditor = CKEDITOR.instances.editor1;
\r
65 var value = document.getElementById( 'htmlArea' ).value;
\r
67 // Set editor contents (replace current contents).
\r
68 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData
\r
69 oEditor.setData( value );
\r
72 function GetContents()
\r
74 // Get the editor instance that you want to interact with.
\r
75 var oEditor = CKEDITOR.instances.editor1;
\r
77 // Get editor contents
\r
78 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#getData
\r
79 alert( oEditor.getData() );
\r
82 function ExecuteCommand( commandName )
\r
84 // Get the editor instance that we want to interact with.
\r
85 var oEditor = CKEDITOR.instances.editor1;
\r
87 // Check the active editing mode.
\r
88 if ( oEditor.mode == 'wysiwyg' )
\r
90 // Execute the command.
\r
91 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#execCommand
\r
92 oEditor.execCommand( commandName );
\r
95 alert( 'You must be in WYSIWYG mode!' );
\r
98 function CheckDirty()
\r
100 // Get the editor instance that we want to interact with.
\r
101 var oEditor = CKEDITOR.instances.editor1;
\r
102 // Checks whether the current editor contents present changes when compared
\r
103 // to the contents loaded into the editor at startup
\r
104 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#checkDirty
\r
105 alert( oEditor.checkDirty() );
\r
108 function ResetDirty()
\r
110 // Get the editor instance that we want to interact with.
\r
111 var oEditor = CKEDITOR.instances.editor1;
\r
112 // Resets the "dirty state" of the editor (see CheckDirty())
\r
113 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#resetDirty
\r
114 oEditor.resetDirty();
\r
115 alert( 'The "IsDirty" status has been reset' );
\r
123 <h1 class="samples">
\r
124 CKEditor Sample — Using CKEditor JavaScript API
\r
126 <div class="description">
\r
128 This sample shows how to use the
\r
129 <a class="samples" href="http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html">CKEditor JavaScript API</a>
\r
130 to interact with the editor at runtime.
\r
133 For details on how to create this setup check the source code of this sample page.
\r
137 <!-- This <div> holds alert messages to be display in the sample page. -->
\r
141 <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
\r
142 support, like yours, you should still see the contents (HTML data) and you should
\r
143 be able to edit it normally, without a rich editor interface.
\r
147 <form action="sample_posteddata.php" method="post">
\r
148 <textarea cols="100" 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
150 <script type="text/javascript">
\r
152 // Replace the <textarea id="editor1"> with an CKEditor instance.
\r
153 var editor = CKEDITOR.replace( 'editor1' );
\r
157 <div id="eMessage">
\r
159 <div id="eButtons" style="display: none">
\r
160 <input onclick="InsertHTML();" type="button" value="Insert HTML" />
\r
161 <input onclick="SetContents();" type="button" value="Set Editor Contents" />
\r
162 <input onclick="GetContents();" type="button" value="Get Editor Contents (XHTML)" />
\r
164 <textarea cols="100" id="htmlArea" rows="3"><h2>Test</h2><p>This is some <a href="/Test1.html">sample</a> HTML code.</p></textarea>
\r
167 <input onclick="InsertText();" type="button" value="Insert Text" />
\r
169 <textarea cols="100" id="txtArea" rows="3"> First line with some leading whitespaces.
\r
171 Second line of text preceded by two line breaks.</textarea>
\r
173 <input onclick="ExecuteCommand('bold');" type="button" value="Execute "bold" Command" />
\r
174 <input onclick="ExecuteCommand('link');" type="button" value="Execute "link" Command" />
\r
177 <input onclick="CheckDirty();" type="button" value="checkDirty()" />
\r
178 <input onclick="ResetDirty();" type="button" value="resetDirty()" />
\r
184 CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
\r
187 Copyright © 2003-2012, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
\r
188 Knabben. All rights reserved.
\r