output_for_flash.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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>Output for Flash &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" src="assets/swfobject.js"></script>
  14. <script type="text/javascript">
  15. function sendToFlash()
  16. {
  17. var html = CKEDITOR.instances.editor1.getData() ;
  18. var flash = document.getElementById( 'ckFlash' ) ;
  19. flash.setData( html ) ;
  20. }
  21. function init()
  22. {
  23. var so = new SWFObject("assets/output_for_flash.swf", "ckFlash", "550", "400", "8", "#ffffff") ;
  24. so.addParam("wmode", "transparent");
  25. so.write("ckFlashContainer") ;
  26. }
  27. </script>
  28. </head>
  29. <body onload="init()">
  30. <h1 class="samples">
  31. CKEditor Sample &mdash; Producing Flash Compliant HTML Output
  32. </h1>
  33. <div class="description">
  34. <p>
  35. This sample shows how to configure CKEditor to output
  36. HTML code that can be used with
  37. <a class="samples" href="http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00000922.html">
  38. Adobe Flash</a>.
  39. The code will contain a subset of standard HTML elements like <code>&lt;b&gt;</code>,
  40. <code>&lt;i&gt;</code>, and <code>&lt;p&gt;</code> as well as HTML attributes.
  41. </p>
  42. <p>
  43. To add a CKEditor instance outputting Flash compliant HTML code, load the editor using a standard
  44. JavaScript call, and define CKEditor features to use HTML elements and attributes.
  45. </p>
  46. <p>
  47. For details on how to create this setup check the source code of this sample page.
  48. </p>
  49. </div>
  50. <p>
  51. To see how it works, create some content in the editing area of CKEditor on the left
  52. and send it to the Flash object on the right side of the page by using the
  53. <strong>Send to Flash</strong> button.
  54. </p>
  55. <!-- This <div> holds alert messages to be display in the sample page. -->
  56. <div id="alerts">
  57. <noscript>
  58. <p>
  59. <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
  60. support, like yours, you should still see the contents (HTML data) and you should
  61. be able to edit it normally, without a rich editor interface.
  62. </p>
  63. </noscript>
  64. </div>
  65. <hr />
  66. <table width="100%" cellpadding="0" cellspacing="0">
  67. <tr>
  68. <td style="width: 100%">
  69. <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;This is some &lt;b&gt;sample text&lt;/b&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>
  70. <script type="text/javascript">
  71. //<![CDATA[
  72. if ( document.location.protocol == 'file:' )
  73. alert( 'Warning: This samples does not work when loaded from local filesystem due to security restrictions implemented in Flash.' +
  74. '\n\nPlease load the sample from a web server instead.') ;
  75. CKEDITOR.replace( 'editor1',
  76. {
  77. height : 300,
  78. width : '100%',
  79. toolbar : [
  80. ['Source','-','Bold','Italic','Underline','-','BulletedList','-','Link','Unlink'],
  81. ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
  82. '/',
  83. ['Font','FontSize'],
  84. ['TextColor','-','About']
  85. ],
  86. /*
  87. * Style sheet for the contents
  88. */
  89. contentsCss : 'body {color:#000; background-color#FFF; font-family: Arial; font-size:80%;} p, ol, ul {margin-top: 0px; margin-bottom: 0px;}',
  90. /*
  91. * Quirks doctype
  92. */
  93. docType : '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">',
  94. /*
  95. * Core styles.
  96. */
  97. coreStyles_bold : { element : 'b' },
  98. coreStyles_italic : { element : 'i' },
  99. coreStyles_underline : { element : 'u'},
  100. /*
  101. * Font face
  102. */
  103. // Define the way font elements will be applied to the document. The "font"
  104. // element will be used.
  105. font_style :
  106. {
  107. element : 'font',
  108. attributes : { 'face' : '#(family)' }
  109. },
  110. /*
  111. * Font sizes.
  112. * The CSS part of the font sizes isn't used by Flash, it is there to get the
  113. * font rendered correctly in CKEditor.
  114. */
  115. fontSize_sizes : '8px/8;9px/9;10px/10;11px/11;12px/12;14px/14;16px/16;18px/18;20px/20;22px/22;24px/24;26px/26;28px/28;36px/36;48px/48;72px/72',
  116. fontSize_style :
  117. {
  118. element : 'font',
  119. attributes : { 'size' : '#(size)' },
  120. styles : { 'font-size' : '#(size)px' }
  121. } ,
  122. /*
  123. * Font colors.
  124. */
  125. colorButton_enableMore : true,
  126. colorButton_foreStyle :
  127. {
  128. element : 'font',
  129. attributes : { 'color' : '#(color)' }
  130. },
  131. colorButton_backStyle :
  132. {
  133. element : 'font',
  134. styles : { 'background-color' : '#(color)' }
  135. },
  136. on : { 'instanceReady' : configureFlashOutput }
  137. });
  138. /*
  139. * Adjust the behavior of the dataProcessor to match the
  140. * requirements of Flash
  141. */
  142. function configureFlashOutput( ev )
  143. {
  144. var editor = ev.editor,
  145. dataProcessor = editor.dataProcessor,
  146. htmlFilter = dataProcessor && dataProcessor.htmlFilter;
  147. // Out self closing tags the HTML4 way, like <br>.
  148. dataProcessor.writer.selfClosingEnd = '>';
  149. // Make output formatting match Flash expectations
  150. var dtd = CKEDITOR.dtd;
  151. for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
  152. {
  153. dataProcessor.writer.setRules( e,
  154. {
  155. indent : false,
  156. breakBeforeOpen : false,
  157. breakAfterOpen : false,
  158. breakBeforeClose : false,
  159. breakAfterClose : false
  160. });
  161. }
  162. dataProcessor.writer.setRules( 'br',
  163. {
  164. indent : false,
  165. breakBeforeOpen : false,
  166. breakAfterOpen : false,
  167. breakBeforeClose : false,
  168. breakAfterClose : false
  169. });
  170. // Output properties as attributes, not styles.
  171. htmlFilter.addRules(
  172. {
  173. elements :
  174. {
  175. $ : function( element )
  176. {
  177. var style, match, width, height, align;
  178. // Output dimensions of images as width and height
  179. if ( element.name == 'img' )
  180. {
  181. style = element.attributes.style;
  182. if ( style )
  183. {
  184. // Get the width from the style.
  185. match = /(?:^|\s)width\s*:\s*(\d+)px/i.exec( style );
  186. width = match && match[1];
  187. // Get the height from the style.
  188. match = /(?:^|\s)height\s*:\s*(\d+)px/i.exec( style );
  189. height = match && match[1];
  190. if ( width )
  191. {
  192. element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' );
  193. element.attributes.width = width;
  194. }
  195. if ( height )
  196. {
  197. element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' );
  198. element.attributes.height = height;
  199. }
  200. }
  201. }
  202. // Output alignment of paragraphs using align
  203. if ( element.name == 'p' )
  204. {
  205. style = element.attributes.style;
  206. if ( style )
  207. {
  208. // Get the align from the style.
  209. match = /(?:^|\s)text-align\s*:\s*(\w*);?/i.exec( style );
  210. align = match && match[1];
  211. if ( align )
  212. {
  213. element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' );
  214. element.attributes.align = align;
  215. }
  216. }
  217. }
  218. if ( element.attributes.style === '' )
  219. delete element.attributes.style;
  220. return element;
  221. }
  222. }
  223. } );
  224. }
  225. //]]>
  226. </script>
  227. <input type="button" value="Send to Flash" onclick="sendToFlash();" />
  228. </td>
  229. <td valign="top" style="padding-left: 15px" id="ckFlashContainer">
  230. </td>
  231. </tr>
  232. </table>
  233. <div id="footer">
  234. <hr />
  235. <p>
  236. CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
  237. </p>
  238. <p id="copy">
  239. Copyright &copy; 2003-2011, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
  240. Knabben. All rights reserved.
  241. </p>
  242. </div>
  243. </body>
  244. </html>