api.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <!--
  3. Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
  4. For licensing, see LICENSE.html or http://ckeditor.com/license
  5. -->
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <title>API Usage &mdash; CKEditor Sample</title>
  9. <meta content="text/html; charset=utf-8" http-equiv="content-type" />
  10. <script type="text/javascript" src="../ckeditor.js"></script>
  11. <script src="sample.js" type="text/javascript"></script>
  12. <link href="sample.css" rel="stylesheet" type="text/css" />
  13. <script type="text/javascript">
  14. //<![CDATA[
  15. // The instanceReady event is fired, when an instance of CKEditor has finished
  16. // its initialization.
  17. CKEDITOR.on( 'instanceReady', function( ev )
  18. {
  19. // Show the editor name and description in the browser status bar.
  20. document.getElementById( 'eMessage' ).innerHTML = '<p>Instance <code>' + ev.editor.name + '<\/code> loaded.<\/p>';
  21. // Show this sample buttons.
  22. document.getElementById( 'eButtons' ).style.display = 'block';
  23. });
  24. function InsertHTML()
  25. {
  26. // Get the editor instance that we want to interact with.
  27. var oEditor = CKEDITOR.instances.editor1;
  28. var value = document.getElementById( 'htmlArea' ).value;
  29. // Check the active editing mode.
  30. if ( oEditor.mode == 'wysiwyg' )
  31. {
  32. // Insert HTML code.
  33. // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#insertHtml
  34. oEditor.insertHtml( value );
  35. }
  36. else
  37. alert( 'You must be in WYSIWYG mode!' );
  38. }
  39. function InsertText()
  40. {
  41. // Get the editor instance that we want to interact with.
  42. var oEditor = CKEDITOR.instances.editor1;
  43. var value = document.getElementById( 'txtArea' ).value;
  44. // Check the active editing mode.
  45. if ( oEditor.mode == 'wysiwyg' )
  46. {
  47. // Insert as plain text.
  48. // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#insertText
  49. oEditor.insertText( value );
  50. }
  51. else
  52. alert( 'You must be in WYSIWYG mode!' );
  53. }
  54. function SetContents()
  55. {
  56. // Get the editor instance that we want to interact with.
  57. var oEditor = CKEDITOR.instances.editor1;
  58. var value = document.getElementById( 'htmlArea' ).value;
  59. // Set editor contents (replace current contents).
  60. // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData
  61. oEditor.setData( value );
  62. }
  63. function GetContents()
  64. {
  65. // Get the editor instance that you want to interact with.
  66. var oEditor = CKEDITOR.instances.editor1;
  67. // Get editor contents
  68. // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#getData
  69. alert( oEditor.getData() );
  70. }
  71. function ExecuteCommand( commandName )
  72. {
  73. // Get the editor instance that we want to interact with.
  74. var oEditor = CKEDITOR.instances.editor1;
  75. // Check the active editing mode.
  76. if ( oEditor.mode == 'wysiwyg' )
  77. {
  78. // Execute the command.
  79. // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#execCommand
  80. oEditor.execCommand( commandName );
  81. }
  82. else
  83. alert( 'You must be in WYSIWYG mode!' );
  84. }
  85. function CheckDirty()
  86. {
  87. // Get the editor instance that we want to interact with.
  88. var oEditor = CKEDITOR.instances.editor1;
  89. // Checks whether the current editor contents present changes when compared
  90. // to the contents loaded into the editor at startup
  91. // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#checkDirty
  92. alert( oEditor.checkDirty() );
  93. }
  94. function ResetDirty()
  95. {
  96. // Get the editor instance that we want to interact with.
  97. var oEditor = CKEDITOR.instances.editor1;
  98. // Resets the "dirty state" of the editor (see CheckDirty())
  99. // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#resetDirty
  100. oEditor.resetDirty();
  101. alert( 'The "IsDirty" status has been reset' );
  102. }
  103. //]]>
  104. </script>
  105. </head>
  106. <body>
  107. <h1 class="samples">
  108. CKEditor Sample &mdash; Using CKEditor JavaScript API
  109. </h1>
  110. <div class="description">
  111. <p>
  112. This sample shows how to use the
  113. <a class="samples" href="http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html">CKEditor JavaScript API</a>
  114. to interact with the editor at runtime.
  115. </p>
  116. <p>
  117. For details on how to create this setup check the source code of this sample page.
  118. </p>
  119. </div>
  120. <!-- This <div> holds alert messages to be display in the sample page. -->
  121. <div id="alerts">
  122. <noscript>
  123. <p>
  124. <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
  125. support, like yours, you should still see the contents (HTML data) and you should
  126. be able to edit it normally, without a rich editor interface.
  127. </p>
  128. </noscript>
  129. </div>
  130. <form action="sample_posteddata.php" method="post">
  131. <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>
  132. <script type="text/javascript">
  133. //<![CDATA[
  134. // Replace the <textarea id="editor1"> with an CKEditor instance.
  135. var editor = CKEDITOR.replace( 'editor1' );
  136. //]]>
  137. </script>
  138. <div id="eMessage">
  139. </div>
  140. <div id="eButtons" style="display: none">
  141. <input onclick="InsertHTML();" type="button" value="Insert HTML" />
  142. <input onclick="SetContents();" type="button" value="Set Editor Contents" />
  143. <input onclick="GetContents();" type="button" value="Get Editor Contents (XHTML)" />
  144. <br />
  145. <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>
  146. <br />
  147. <br />
  148. <input onclick="InsertText();" type="button" value="Insert Text" />
  149. <br />
  150. <textarea cols="100" id="txtArea" rows="3"> First line with some leading whitespaces.
  151. Second line of text preceded by two line breaks.</textarea>
  152. <br />
  153. <input onclick="ExecuteCommand('bold');" type="button" value="Execute &quot;bold&quot; Command" />
  154. <input onclick="ExecuteCommand('link');" type="button" value="Execute &quot;link&quot; Command" />
  155. <br />
  156. <br />
  157. <input onclick="CheckDirty();" type="button" value="checkDirty()" />
  158. <input onclick="ResetDirty();" type="button" value="resetDirty()" />
  159. </div>
  160. </form>
  161. <div id="footer">
  162. <hr />
  163. <p>
  164. CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
  165. </p>
  166. <p id="copy">
  167. Copyright &copy; 2003-2011, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
  168. Knabben. All rights reserved.
  169. </p>
  170. </div>
  171. </body>
  172. </html>