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