JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5.3
[ckeditor.git] / _samples / api.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
2 <!--\r
3 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
4 For licensing, see LICENSE.html or http://ckeditor.com/license\r
5 -->\r
6 <html xmlns="http://www.w3.org/1999/xhtml">\r
7 <head>\r
8         <title>API Usage &mdash; 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
14         //<![CDATA[\r
15 \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
19 {\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
22 \r
23         // Show this sample buttons.\r
24          document.getElementById( 'eButtons' ).style.display = 'block';\r
25 });\r
26 \r
27 function InsertHTML()\r
28 {\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
32 \r
33         // Check the active editing mode.\r
34         if ( oEditor.mode == 'wysiwyg' )\r
35         {\r
36                 // Insert HTML code.\r
37                 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#insertHtml\r
38                 oEditor.insertHtml( value );\r
39         }\r
40         else\r
41                 alert( 'You must be in WYSIWYG mode!' );\r
42 }\r
43 \r
44 function InsertText()\r
45 {\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
49 \r
50         // Check the active editing mode.\r
51         if ( oEditor.mode == 'wysiwyg' )\r
52         {\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
56         }\r
57         else\r
58                 alert( 'You must be in WYSIWYG mode!' );\r
59 }\r
60 \r
61 function SetContents()\r
62 {\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
66 \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
70 }\r
71 \r
72 function GetContents()\r
73 {\r
74         // Get the editor instance that you want to interact with.\r
75         var oEditor = CKEDITOR.instances.editor1;\r
76 \r
77         // Get editor contents\r
78         // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#getData\r
79         alert( oEditor.getData() );\r
80 }\r
81 \r
82 function ExecuteCommand( commandName )\r
83 {\r
84         // Get the editor instance that we want to interact with.\r
85         var oEditor = CKEDITOR.instances.editor1;\r
86 \r
87         // Check the active editing mode.\r
88         if ( oEditor.mode == 'wysiwyg' )\r
89         {\r
90                 // Execute the command.\r
91                 // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#execCommand\r
92                 oEditor.execCommand( commandName );\r
93         }\r
94         else\r
95                 alert( 'You must be in WYSIWYG mode!' );\r
96 }\r
97 \r
98 function CheckDirty()\r
99 {\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
106 }\r
107 \r
108 function ResetDirty()\r
109 {\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
116 }\r
117 \r
118         //]]>\r
119         </script>\r
120 \r
121 </head>\r
122 <body>\r
123         <h1 class="samples">\r
124                 CKEditor Sample &mdash; Using CKEditor JavaScript API\r
125         </h1>\r
126         <div class="description">\r
127         <p>\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
131         </p>\r
132         <p>\r
133                 For details on how to create this setup check the source code of this sample page.\r
134         </p>\r
135         </div>\r
136 \r
137         <!-- This <div> holds alert messages to be display in the sample page. -->\r
138         <div id="alerts">\r
139                 <noscript>\r
140                         <p>\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
144                         </p>\r
145                 </noscript>\r
146         </div>\r
147         <form action="sample_posteddata.php" method="post">\r
148                 <textarea cols="100" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>\r
149 \r
150                 <script type="text/javascript">\r
151                 //<![CDATA[\r
152                         // Replace the <textarea id="editor1"> with an CKEditor instance.\r
153                         var editor = CKEDITOR.replace( 'editor1' );\r
154                 //]]>\r
155                 </script>\r
156 \r
157                 <div id="eMessage">\r
158                 </div>\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
163                         <br />\r
164                         <textarea cols="100" id="htmlArea" rows="3">&lt;h2&gt;Test&lt;/h2&gt;&lt;p&gt;This is some &lt;a href="/Test1.html"&gt;sample&lt;/a&gt; HTML code.&lt;/p&gt;</textarea>\r
165                         <br />\r
166                         <br />\r
167                         <input onclick="InsertText();" type="button" value="Insert Text" />\r
168                         <br />\r
169                         <textarea cols="100" id="txtArea" rows="3">   First line with some leading whitespaces.\r
170 \r
171 Second line of text preceded by two line breaks.</textarea>\r
172                         <br />\r
173                         <input onclick="ExecuteCommand('bold');" type="button" value="Execute &quot;bold&quot; Command" />\r
174                         <input onclick="ExecuteCommand('link');" type="button" value="Execute &quot;link&quot; Command" />\r
175                         <br />\r
176                         <br />\r
177                         <input onclick="CheckDirty();" type="button" value="checkDirty()" />\r
178                         <input onclick="ResetDirty();" type="button" value="resetDirty()" />\r
179                 </div>\r
180         </form>\r
181         <div id="footer">\r
182                 <hr />\r
183                 <p>\r
184                         CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>\r
185                 </p>\r
186                 <p id="copy">\r
187                         Copyright &copy; 2003-2011, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico\r
188                         Knabben. All rights reserved.\r
189                 </p>\r
190         </div>\r
191 </body>\r
192 </html>\r