indvd00m@0
|
1 |
<!DOCTYPE html>
|
indvd00m@0
|
2 |
<!--
|
indvd00m@0
|
3 |
Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
|
indvd00m@0
|
4 |
For licensing, see LICENSE.md or http://ckeditor.com/license
|
indvd00m@0
|
5 |
-->
|
indvd00m@0
|
6 |
<html>
|
indvd00m@0
|
7 |
<head>
|
indvd00m@0
|
8 |
<meta charset="utf-8">
|
indvd00m@0
|
9 |
<title>API Usage — CKEditor Sample</title>
|
indvd00m@0
|
10 |
<script src="../../ckeditor.js"></script>
|
indvd00m@0
|
11 |
<link href="sample.css" rel="stylesheet">
|
indvd00m@0
|
12 |
<script>
|
indvd00m@0
|
13 |
|
indvd00m@0
|
14 |
// The instanceReady event is fired, when an instance of CKEditor has finished
|
indvd00m@0
|
15 |
// its initialization.
|
indvd00m@0
|
16 |
CKEDITOR.on( 'instanceReady', function( ev ) {
|
indvd00m@0
|
17 |
// Show the editor name and description in the browser status bar.
|
indvd00m@0
|
18 |
document.getElementById( 'eMessage' ).innerHTML = 'Instance <code>' + ev.editor.name + '<\/code> loaded.';
|
indvd00m@0
|
19 |
|
indvd00m@0
|
20 |
// Show this sample buttons.
|
indvd00m@0
|
21 |
document.getElementById( 'eButtons' ).style.display = 'block';
|
indvd00m@0
|
22 |
});
|
indvd00m@0
|
23 |
|
indvd00m@0
|
24 |
function InsertHTML() {
|
indvd00m@0
|
25 |
// Get the editor instance that we want to interact with.
|
indvd00m@0
|
26 |
var editor = CKEDITOR.instances.editor1;
|
indvd00m@0
|
27 |
var value = document.getElementById( 'htmlArea' ).value;
|
indvd00m@0
|
28 |
|
indvd00m@0
|
29 |
// Check the active editing mode.
|
indvd00m@0
|
30 |
if ( editor.mode == 'wysiwyg' )
|
indvd00m@0
|
31 |
{
|
indvd00m@0
|
32 |
// Insert HTML code.
|
indvd00m@0
|
33 |
// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-insertHtml
|
indvd00m@0
|
34 |
editor.insertHtml( value );
|
indvd00m@0
|
35 |
}
|
indvd00m@0
|
36 |
else
|
indvd00m@0
|
37 |
alert( 'You must be in WYSIWYG mode!' );
|
indvd00m@0
|
38 |
}
|
indvd00m@0
|
39 |
|
indvd00m@0
|
40 |
function InsertText() {
|
indvd00m@0
|
41 |
// Get the editor instance that we want to interact with.
|
indvd00m@0
|
42 |
var editor = CKEDITOR.instances.editor1;
|
indvd00m@0
|
43 |
var value = document.getElementById( 'txtArea' ).value;
|
indvd00m@0
|
44 |
|
indvd00m@0
|
45 |
// Check the active editing mode.
|
indvd00m@0
|
46 |
if ( editor.mode == 'wysiwyg' )
|
indvd00m@0
|
47 |
{
|
indvd00m@0
|
48 |
// Insert as plain text.
|
indvd00m@0
|
49 |
// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-insertText
|
indvd00m@0
|
50 |
editor.insertText( value );
|
indvd00m@0
|
51 |
}
|
indvd00m@0
|
52 |
else
|
indvd00m@0
|
53 |
alert( 'You must be in WYSIWYG mode!' );
|
indvd00m@0
|
54 |
}
|
indvd00m@0
|
55 |
|
indvd00m@0
|
56 |
function SetContents() {
|
indvd00m@0
|
57 |
// Get the editor instance that we want to interact with.
|
indvd00m@0
|
58 |
var editor = CKEDITOR.instances.editor1;
|
indvd00m@0
|
59 |
var value = document.getElementById( 'htmlArea' ).value;
|
indvd00m@0
|
60 |
|
indvd00m@0
|
61 |
// Set editor contents (replace current contents).
|
indvd00m@0
|
62 |
// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-setData
|
indvd00m@0
|
63 |
editor.setData( value );
|
indvd00m@0
|
64 |
}
|
indvd00m@0
|
65 |
|
indvd00m@0
|
66 |
function GetContents() {
|
indvd00m@0
|
67 |
// Get the editor instance that you want to interact with.
|
indvd00m@0
|
68 |
var editor = CKEDITOR.instances.editor1;
|
indvd00m@0
|
69 |
|
indvd00m@0
|
70 |
// Get editor contents
|
indvd00m@0
|
71 |
// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-getData
|
indvd00m@0
|
72 |
alert( editor.getData() );
|
indvd00m@0
|
73 |
}
|
indvd00m@0
|
74 |
|
indvd00m@0
|
75 |
function ExecuteCommand( commandName ) {
|
indvd00m@0
|
76 |
// Get the editor instance that we want to interact with.
|
indvd00m@0
|
77 |
var editor = CKEDITOR.instances.editor1;
|
indvd00m@0
|
78 |
|
indvd00m@0
|
79 |
// Check the active editing mode.
|
indvd00m@0
|
80 |
if ( editor.mode == 'wysiwyg' )
|
indvd00m@0
|
81 |
{
|
indvd00m@0
|
82 |
// Execute the command.
|
indvd00m@0
|
83 |
// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-execCommand
|
indvd00m@0
|
84 |
editor.execCommand( commandName );
|
indvd00m@0
|
85 |
}
|
indvd00m@0
|
86 |
else
|
indvd00m@0
|
87 |
alert( 'You must be in WYSIWYG mode!' );
|
indvd00m@0
|
88 |
}
|
indvd00m@0
|
89 |
|
indvd00m@0
|
90 |
function CheckDirty() {
|
indvd00m@0
|
91 |
// Get the editor instance that we want to interact with.
|
indvd00m@0
|
92 |
var editor = CKEDITOR.instances.editor1;
|
indvd00m@0
|
93 |
// Checks whether the current editor contents present changes when compared
|
indvd00m@0
|
94 |
// to the contents loaded into the editor at startup
|
indvd00m@0
|
95 |
// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-checkDirty
|
indvd00m@0
|
96 |
alert( editor.checkDirty() );
|
indvd00m@0
|
97 |
}
|
indvd00m@0
|
98 |
|
indvd00m@0
|
99 |
function ResetDirty() {
|
indvd00m@0
|
100 |
// Get the editor instance that we want to interact with.
|
indvd00m@0
|
101 |
var editor = CKEDITOR.instances.editor1;
|
indvd00m@0
|
102 |
// Resets the "dirty state" of the editor (see CheckDirty())
|
indvd00m@0
|
103 |
// http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-resetDirty
|
indvd00m@0
|
104 |
editor.resetDirty();
|
indvd00m@0
|
105 |
alert( 'The "IsDirty" status has been reset' );
|
indvd00m@0
|
106 |
}
|
indvd00m@0
|
107 |
|
indvd00m@0
|
108 |
function Focus() {
|
indvd00m@0
|
109 |
CKEDITOR.instances.editor1.focus();
|
indvd00m@0
|
110 |
}
|
indvd00m@0
|
111 |
|
indvd00m@0
|
112 |
function onFocus() {
|
indvd00m@0
|
113 |
document.getElementById( 'eMessage' ).innerHTML = '<b>' + this.name + ' is focused </b>';
|
indvd00m@0
|
114 |
}
|
indvd00m@0
|
115 |
|
indvd00m@0
|
116 |
function onBlur() {
|
indvd00m@0
|
117 |
document.getElementById( 'eMessage' ).innerHTML = this.name + ' lost focus';
|
indvd00m@0
|
118 |
}
|
indvd00m@0
|
119 |
|
indvd00m@0
|
120 |
</script>
|
indvd00m@0
|
121 |
|
indvd00m@0
|
122 |
</head>
|
indvd00m@0
|
123 |
<body>
|
indvd00m@0
|
124 |
<h1 class="samples">
|
indvd00m@0
|
125 |
<a href="index.html">CKEditor Samples</a> » Using CKEditor JavaScript API
|
indvd00m@0
|
126 |
</h1>
|
indvd00m@0
|
127 |
<div class="warning deprecated">
|
indvd00m@0
|
128 |
This sample is not maintained anymore. Check out its <a href="http://sdk.ckeditor.com/samples/api.html">brand new version in CKEditor SDK</a>.
|
indvd00m@0
|
129 |
</div>
|
indvd00m@0
|
130 |
<div class="description">
|
indvd00m@0
|
131 |
<p>
|
indvd00m@0
|
132 |
This sample shows how to use the
|
indvd00m@0
|
133 |
<a class="samples" href="http://docs.ckeditor.com/#!/api/CKEDITOR.editor">CKEditor JavaScript API</a>
|
indvd00m@0
|
134 |
to interact with the editor at runtime.
|
indvd00m@0
|
135 |
</p>
|
indvd00m@0
|
136 |
<p>
|
indvd00m@0
|
137 |
For details on how to create this setup check the source code of this sample page.
|
indvd00m@0
|
138 |
</p>
|
indvd00m@0
|
139 |
</div>
|
indvd00m@0
|
140 |
|
indvd00m@0
|
141 |
<!-- This <div> holds alert messages to be display in the sample page. -->
|
indvd00m@0
|
142 |
<div id="alerts">
|
indvd00m@0
|
143 |
<noscript>
|
indvd00m@0
|
144 |
<p>
|
indvd00m@0
|
145 |
<strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
|
indvd00m@0
|
146 |
support, like yours, you should still see the contents (HTML data) and you should
|
indvd00m@0
|
147 |
be able to edit it normally, without a rich editor interface.
|
indvd00m@0
|
148 |
</p>
|
indvd00m@0
|
149 |
</noscript>
|
indvd00m@0
|
150 |
</div>
|
indvd00m@0
|
151 |
<form action="../../../samples/sample_posteddata.php" method="post">
|
indvd00m@0
|
152 |
<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>
|
indvd00m@0
|
153 |
|
indvd00m@0
|
154 |
<script>
|
indvd00m@0
|
155 |
// Replace the <textarea id="editor1"> with an CKEditor instance.
|
indvd00m@0
|
156 |
CKEDITOR.replace( 'editor1', {
|
indvd00m@0
|
157 |
on: {
|
indvd00m@0
|
158 |
focus: onFocus,
|
indvd00m@0
|
159 |
blur: onBlur,
|
indvd00m@0
|
160 |
|
indvd00m@0
|
161 |
// Check for availability of corresponding plugins.
|
indvd00m@0
|
162 |
pluginsLoaded: function( evt ) {
|
indvd00m@0
|
163 |
var doc = CKEDITOR.document, ed = evt.editor;
|
indvd00m@0
|
164 |
if ( !ed.getCommand( 'bold' ) )
|
indvd00m@0
|
165 |
doc.getById( 'exec-bold' ).hide();
|
indvd00m@0
|
166 |
if ( !ed.getCommand( 'link' ) )
|
indvd00m@0
|
167 |
doc.getById( 'exec-link' ).hide();
|
indvd00m@0
|
168 |
}
|
indvd00m@0
|
169 |
}
|
indvd00m@0
|
170 |
});
|
indvd00m@0
|
171 |
</script>
|
indvd00m@0
|
172 |
|
indvd00m@0
|
173 |
<p id="eMessage">
|
indvd00m@0
|
174 |
</p>
|
indvd00m@0
|
175 |
|
indvd00m@0
|
176 |
<div id="eButtons" style="display: none">
|
indvd00m@0
|
177 |
<input id="exec-bold" onclick="ExecuteCommand('bold');" type="button" value="Execute "bold" Command">
|
indvd00m@0
|
178 |
<input id="exec-link" onclick="ExecuteCommand('link');" type="button" value="Execute "link" Command">
|
indvd00m@0
|
179 |
<input onclick="Focus();" type="button" value="Focus">
|
indvd00m@0
|
180 |
<br><br>
|
indvd00m@0
|
181 |
<input onclick="InsertHTML();" type="button" value="Insert HTML">
|
indvd00m@0
|
182 |
<input onclick="SetContents();" type="button" value="Set Editor Contents">
|
indvd00m@0
|
183 |
<input onclick="GetContents();" type="button" value="Get Editor Contents (HTML)">
|
indvd00m@0
|
184 |
<br>
|
indvd00m@0
|
185 |
<textarea cols="100" id="htmlArea" rows="3"><h2>Test</h2><p>This is some <a href="/Test1.html">sample</a> HTML code.</p></textarea>
|
indvd00m@0
|
186 |
<br>
|
indvd00m@0
|
187 |
<br>
|
indvd00m@0
|
188 |
<input onclick="InsertText();" type="button" value="Insert Text">
|
indvd00m@0
|
189 |
<br>
|
indvd00m@0
|
190 |
<textarea cols="100" id="txtArea" rows="3"> First line with some leading whitespaces.
|
indvd00m@0
|
191 |
|
indvd00m@0
|
192 |
Second line of text preceded by two line breaks.</textarea>
|
indvd00m@0
|
193 |
<br>
|
indvd00m@0
|
194 |
<br>
|
indvd00m@0
|
195 |
<input onclick="CheckDirty();" type="button" value="checkDirty()">
|
indvd00m@0
|
196 |
<input onclick="ResetDirty();" type="button" value="resetDirty()">
|
indvd00m@0
|
197 |
</div>
|
indvd00m@0
|
198 |
</form>
|
indvd00m@0
|
199 |
<div id="footer">
|
indvd00m@0
|
200 |
<hr>
|
indvd00m@0
|
201 |
<p>
|
indvd00m@0
|
202 |
CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
|
indvd00m@0
|
203 |
</p>
|
indvd00m@0
|
204 |
<p id="copy">
|
indvd00m@0
|
205 |
Copyright © 2003-2016, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
|
indvd00m@0
|
206 |
Knabben. All rights reserved.
|
indvd00m@0
|
207 |
</p>
|
indvd00m@0
|
208 |
</div>
|
indvd00m@0
|
209 |
</body>
|
indvd00m@0
|
210 |
</html>
|