JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.5
[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-2010, 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 - 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 "' + ev.editor.name + '" loaded.<\/p>';\r
22 \r
23         // Show this sample buttons.\r
24         document.getElementById( 'eButtons' ).style.visibility = '';\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 the desired HTML.\r
37                 oEditor.insertHtml( value );\r
38         }\r
39         else\r
40                 alert( 'You must be on WYSIWYG mode!' );\r
41 }\r
42 \r
43 function InsertText()\r
44 {\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( 'txtArea' ).value;\r
48 \r
49         // Check the active editing mode.\r
50         if ( oEditor.mode == 'wysiwyg' )\r
51         {\r
52                 // Insert as plain text.\r
53                 oEditor.insertText( value );\r
54         }\r
55         else\r
56                 alert( 'You must be on WYSIWYG mode!' );\r
57 }\r
58 \r
59 function SetContents()\r
60 {\r
61         // Get the editor instance that we want to interact with.\r
62         var oEditor = CKEDITOR.instances.editor1;\r
63         var value = document.getElementById( 'htmlArea' ).value;\r
64 \r
65         // Set the editor contents (replace the actual one).\r
66         oEditor.setData( value );\r
67 }\r
68 \r
69 function GetContents()\r
70 {\r
71         // Get the editor instance that we want to interact with.\r
72         var oEditor = CKEDITOR.instances.editor1;\r
73 \r
74         // Get the editor contents\r
75         alert( oEditor.getData() );\r
76 }\r
77 \r
78 function ExecuteCommand( commandName )\r
79 {\r
80         // Get the editor instance that we want to interact with.\r
81         var oEditor = CKEDITOR.instances.editor1;\r
82 \r
83         // Check the active editing mode.\r
84         if ( oEditor.mode == 'wysiwyg' )\r
85         {\r
86                 // Execute the command.\r
87                 oEditor.execCommand( commandName );\r
88         }\r
89         else\r
90                 alert( 'You must be on WYSIWYG mode!' );\r
91 }\r
92 \r
93 function CheckDirty()\r
94 {\r
95         // Get the editor instance that we want to interact with.\r
96         var oEditor = CKEDITOR.instances.editor1;\r
97         alert( oEditor.checkDirty() );\r
98 }\r
99 \r
100 function ResetDirty()\r
101 {\r
102         // Get the editor instance that we want to interact with.\r
103         var oEditor = CKEDITOR.instances.editor1;\r
104         oEditor.resetDirty();\r
105         alert( 'The "IsDirty" status has been reset' );\r
106 }\r
107 \r
108         //]]>\r
109         </script>\r
110 \r
111 </head>\r
112 <body>\r
113         <h1>\r
114                 CKEditor Sample\r
115         </h1>\r
116         <!-- This <div> holds alert messages to be display in the sample page. -->\r
117         <div id="alerts">\r
118                 <noscript>\r
119                         <p>\r
120                                 <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript\r
121                                 support, like yours, you should still see the contents (HTML data) and you should\r
122                                 be able to edit it normally, without a rich editor interface.\r
123                         </p>\r
124                 </noscript>\r
125         </div>\r
126         <form action="sample_posteddata.php" method="post">\r
127                 <p>\r
128                         This sample shows how to use the CKEditor JavaScript API to interact with the editor\r
129                         at runtime.</p>\r
130                 <textarea cols="80" 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
131 \r
132                 <script type="text/javascript">\r
133                 //<![CDATA[\r
134                         // Replace the <textarea id="editor1"> with an CKEditor instance.\r
135                         var editor = CKEDITOR.replace( 'editor1' );\r
136                 //]]>\r
137                 </script>\r
138 \r
139                 <div id="eMessage">\r
140                 </div>\r
141                 <div id="eButtons" style="visibility: hidden">\r
142                         <input onclick="InsertHTML();" type="button" value="Insert HTML" />\r
143                         <input onclick="SetContents();" type="button" value="Set Editor Contents" />\r
144                         <input onclick="GetContents();" type="button" value="Get Editor Contents (XHTML)" />\r
145                         <br />\r
146                         <textarea cols="80" 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&lt;/p&gt;</textarea>\r
147                         <br />\r
148                         <br />\r
149                         <input onclick="InsertText();" type="button" value="Insert Text" />\r
150                         <br />\r
151                         <textarea cols="80" id="txtArea" rows="3">   First line with some leading whitespaces.\r
152 \r
153 Second line of text preceding by two line-breaks.</textarea>\r
154                         <br />\r
155                         <input onclick="ExecuteCommand('bold');" type="button" value="Execute &quot;bold&quot; Command" />\r
156                         <input onclick="ExecuteCommand('link');" type="button" value="Execute &quot;link&quot; Command" />\r
157                         <br />\r
158                         <br />\r
159                         <input onclick="CheckDirty();" type="button" value="checkDirty()" />\r
160                         <input onclick="ResetDirty();" type="button" value="resetDirty()" />\r
161                 </div>\r
162         </form>\r
163         <div id="footer">\r
164                 <hr />\r
165                 <p>\r
166                         CKEditor - The text editor for Internet - <a href="http://ckeditor.com/">http://ckeditor.com</a>\r
167                 </p>\r
168                 <p id="copy">\r
169                         Copyright &copy; 2003-2010, <a href="http://cksource.com/">CKSource</a> - Frederico\r
170                         Knabben. All rights reserved.\r
171                 </p>\r
172         </div>\r
173 </body>\r
174 </html>\r