JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
9042e0fefdbffdab00ca48666ad97bddf38929c8
[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-2009, 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>Sample - CKEditor</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 id="headscript" 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( 'plainArea' ).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 SetContents()\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( 'plainArea' ).value ;\r
48 \r
49         // Set the editor contents (replace the actual one).\r
50         oEditor.setData( value ) ;\r
51 }\r
52 \r
53 function GetContents()\r
54 {\r
55         // Get the editor instance that we want to interact with.\r
56         var oEditor = CKEDITOR.instances.editor1 ;\r
57 \r
58         // Get the editor contents\r
59         alert( oEditor.getData() ) ;\r
60 }\r
61 \r
62 function ExecuteCommand( commandName )\r
63 {\r
64         // Get the editor instance that we want to interact with.\r
65         var oEditor = CKEDITOR.instances.editor1 ;\r
66 \r
67         // Check the active editing mode.\r
68         if (oEditor.mode == 'wysiwyg' )\r
69         {\r
70                 // Execute the command.\r
71                 oEditor.execCommand( commandName ) ;\r
72         }\r
73         else\r
74                 alert( 'You must be on WYSIWYG mode!' ) ;\r
75 }\r
76 \r
77 function CheckDirty()\r
78 {\r
79         // Get the editor instance that we want to interact with.\r
80         var oEditor = CKEDITOR.instances.editor1 ;\r
81         alert( oEditor.checkDirty() ) ;\r
82 }\r
83 \r
84 function ResetDirty()\r
85 {\r
86         // Get the editor instance that we want to interact with.\r
87         var oEditor = CKEDITOR.instances.editor1 ;\r
88         oEditor.resetDirty() ;\r
89         alert( 'The "IsDirty" status has been reset' ) ;\r
90 }\r
91 \r
92         //]]>\r
93         </script>\r
94 </head>\r
95 <body>\r
96         <h1>\r
97                 CKEditor Sample\r
98         </h1>\r
99         <!-- This <div> holds alert messages to be display in the sample page. -->\r
100         <div id="alerts">\r
101                 <noscript>\r
102                         <p>\r
103                                 <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript\r
104                                 support, like yours, you should still see the contents (HTML data) and you should\r
105                                 be able to edit it normally, without a rich editor interface.\r
106                         </p>\r
107                 </noscript>\r
108         </div>\r
109         <!-- This <fieldset> holds the HTML that you will usually find in your\r
110              pages. -->\r
111         <form action="sample_posteddata.php" method="post">\r
112                 <p>\r
113                 This sample shows how to use the CKeditor JavaScript API to interact with the editor\r
114                 at runtime.</p>\r
115                 <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
116                 <script type="text/javascript">\r
117                 //<![CDATA[\r
118                         // Replace the <textarea id="editor1"> with an CKEditor instance.\r
119                         var editor = CKEDITOR.replace( 'editor1');\r
120                 //]]>\r
121                 </script>\r
122                 <div id="eMessage">\r
123 \r
124                 </div>\r
125                 <div id="eButtons" style="visibility: hidden">\r
126                         <input onclick="InsertHTML();" type="button" value="Insert HTML"/>\r
127                         <input onclick="SetContents();" type="button" value="Set Editor Contents"/>\r
128                         <input onclick="GetContents();" type="button" value="Get Editor Contents (XHTML)"/>\r
129                         <br/>\r
130                         <textarea cols="80" id="plainArea" 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
131                         <br/>\r
132                         <br/>\r
133                         <input onclick="ExecuteCommand('bold');" type="button" value="Execute &quot;bold&quot; Command"/>\r
134                         <input onclick="ExecuteCommand('link');" type="button" value="Execute &quot;link&quot; Command"/>\r
135                 <br/>\r
136                 <br/>\r
137                 <input onclick="CheckDirty();" type="button" value="checkDirty()"/>\r
138                 <input onclick="ResetDirty();" type="button" value="resetDirty()"/>\r
139                 </div>\r
140                 </form>\r
141         <div id="footer">\r
142                 <hr/>\r
143                 <p>\r
144                         CKEditor - The text editor for Internet - <a href="http://ckeditor.com/" shape="rect">http://ckeditor.com</a>\r
145                 </p>\r
146                 <p id="copy">\r
147                         Copyright © 2003-2009, <a href="http://cksource.com/" shape="rect">CKSource</a> - Frederico Knabben. All rights reserved.\r
148                 </p>\r
149         </div>\r
150 </body>\r
151 </html>\r