outputforflash.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  4. For licensing, see LICENSE.md or http://ckeditor.com/license
  5. -->
  6. <html>
  7. <head>
  8. <meta charset="utf-8">
  9. <title>Output for Flash &mdash; CKEditor Sample</title>
  10. <script src="../../../ckeditor.js"></script>
  11. <script src="../../../samples/old/sample.js"></script>
  12. <script src="assets/outputforflash/swfobject.js"></script>
  13. <link href="../../../samples/old/sample.css" rel="stylesheet">
  14. <meta name="ckeditor-sample-required-plugins" content="sourcearea">
  15. <meta name="ckeditor-sample-name" content="Output for Flash">
  16. <meta name="ckeditor-sample-group" content="Advanced Samples">
  17. <meta name="ckeditor-sample-description" content="Configuring CKEditor to produce HTML code that can be used with Adobe Flash.">
  18. <style>
  19. .alert
  20. {
  21. background: #ffa84c;
  22. padding: 10px 15px;
  23. font-weight: bold;
  24. display: block;
  25. margin-bottom: 20px;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <h1 class="samples">
  31. <a href="../../../samples/old/index.html">CKEditor Samples</a> &raquo; Producing Flash Compliant HTML Output
  32. </h1>
  33. <div class="warning deprecated">
  34. This sample is not maintained anymore. Check out the <a href="http://sdk.ckeditor.com/">brand new samples in CKEditor SDK</a>.
  35. </div>
  36. <div class="description">
  37. <p>
  38. This sample shows how to configure CKEditor to output
  39. HTML code that can be used with
  40. <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">
  41. Adobe Flash</a>.
  42. The code will contain a subset of standard HTML elements like <code>&lt;b&gt;</code>,
  43. <code>&lt;i&gt;</code>, and <code>&lt;p&gt;</code> as well as HTML attributes.
  44. </p>
  45. <p>
  46. To add a CKEditor instance outputting Flash compliant HTML code, load the editor using a standard
  47. JavaScript call, and define CKEditor features to use HTML elements and attributes.
  48. </p>
  49. <p>
  50. For details on how to create this setup check the source code of this sample page.
  51. </p>
  52. </div>
  53. <p>
  54. To see how it works, create some content in the editing area of CKEditor on the left
  55. and send it to the Flash object on the right side of the page by using the
  56. <strong>Send to Flash</strong> button.
  57. </p>
  58. <table style="width: 100%; border-spacing: 0; border-collapse:collapse;">
  59. <tr>
  60. <td style="width: 100%">
  61. <textarea cols="80" id="editor1" name="editor1" rows="10">&lt;p&gt;&lt;b&gt;&lt;font size=&quot;18&quot; style=&quot;font-size:18px;&quot;&gt;Flash and HTML&lt;/font&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;It is possible to have &lt;a href=&quot;http://ckeditor.com&quot;&gt;CKEditor&lt;/a&gt; creating content that will be later loaded inside &lt;b&gt;Flash&lt;/b&gt; objects and animations.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Flash has a few limitations when dealing with HTML:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;It has limited support on tags.&lt;/li&gt;&lt;li&gt;There is no margin between block elements, like paragraphs.&lt;/li&gt;&lt;/ul&gt;</textarea>
  62. <script>
  63. if ( document.location.protocol == 'file:' )
  64. alert( 'Warning: This samples does not work when loaded from local filesystem' +
  65. 'due to security restrictions implemented in Flash.' +
  66. '\n\nPlease load the sample from a web server instead.' );
  67. var editor = CKEDITOR.replace( 'editor1', {
  68. /*
  69. * Ensure that htmlwriter plugin, which is required for this sample, is loaded.
  70. */
  71. extraPlugins: 'htmlwriter',
  72. height: 290,
  73. width: '100%',
  74. toolbar: [
  75. [ 'Source', '-', 'Bold', 'Italic', 'Underline', '-', 'BulletedList', '-', 'Link', 'Unlink' ],
  76. [ 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ],
  77. '/',
  78. [ 'Font', 'FontSize' ],
  79. [ 'TextColor', '-', 'About' ]
  80. ],
  81. /*
  82. * Style sheet for the contents
  83. */
  84. contentsCss: 'body {color:#000; background-color#FFF; font-family: Arial; font-size:80%;} p, ol, ul {margin-top: 0px; margin-bottom: 0px;}',
  85. /*
  86. * Quirks doctype
  87. */
  88. docType: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">',
  89. /*
  90. * Core styles.
  91. */
  92. coreStyles_bold: { element: 'b' },
  93. coreStyles_italic: { element: 'i' },
  94. coreStyles_underline: { element: 'u' },
  95. /*
  96. * Font face.
  97. */
  98. // Define the way font elements will be applied to the document. The "font"
  99. // element will be used.
  100. font_style: {
  101. element: 'font',
  102. attributes: { 'face': '#(family)' }
  103. },
  104. /*
  105. * Font sizes.
  106. */
  107. // The CSS part of the font sizes isn't used by Flash, it is there to get the
  108. // font rendered correctly in CKEditor.
  109. 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',
  110. fontSize_style: {
  111. element: 'font',
  112. attributes: { 'size': '#(size)' },
  113. styles: { 'font-size': '#(size)px' }
  114. } ,
  115. /*
  116. * Font colors.
  117. */
  118. colorButton_enableMore: true,
  119. colorButton_foreStyle: {
  120. element: 'font',
  121. attributes: { 'color': '#(color)' }
  122. },
  123. colorButton_backStyle: {
  124. element: 'font',
  125. styles: { 'background-color': '#(color)' }
  126. },
  127. on: { 'instanceReady': configureFlashOutput }
  128. });
  129. /*
  130. * Adjust the behavior of the dataProcessor to match the
  131. * requirements of Flash
  132. */
  133. function configureFlashOutput( ev ) {
  134. var editor = ev.editor,
  135. dataProcessor = editor.dataProcessor,
  136. htmlFilter = dataProcessor && dataProcessor.htmlFilter;
  137. // Out self closing tags the HTML4 way, like <br>.
  138. dataProcessor.writer.selfClosingEnd = '>';
  139. // Make output formatting match Flash expectations
  140. var dtd = CKEDITOR.dtd;
  141. for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) {
  142. dataProcessor.writer.setRules( e, {
  143. indent: false,
  144. breakBeforeOpen: false,
  145. breakAfterOpen: false,
  146. breakBeforeClose: false,
  147. breakAfterClose: false
  148. });
  149. }
  150. dataProcessor.writer.setRules( 'br', {
  151. indent: false,
  152. breakBeforeOpen: false,
  153. breakAfterOpen: false,
  154. breakBeforeClose: false,
  155. breakAfterClose: false
  156. });
  157. // Output properties as attributes, not styles.
  158. htmlFilter.addRules( {
  159. elements: {
  160. $: function( element ) {
  161. var style, match, width, height, align;
  162. // Output dimensions of images as width and height
  163. if ( element.name == 'img' ) {
  164. style = element.attributes.style;
  165. if ( style ) {
  166. // Get the width from the style.
  167. match = ( /(?:^|\s)width\s*:\s*(\d+)px/i ).exec( style );
  168. width = match && match[1];
  169. // Get the height from the style.
  170. match = ( /(?:^|\s)height\s*:\s*(\d+)px/i ).exec( style );
  171. height = match && match[1];
  172. if ( width ) {
  173. element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' );
  174. element.attributes.width = width;
  175. }
  176. if ( height ) {
  177. element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' );
  178. element.attributes.height = height;
  179. }
  180. }
  181. }
  182. // Output alignment of paragraphs using align
  183. if ( element.name == 'p' ) {
  184. style = element.attributes.style;
  185. if ( style ) {
  186. // Get the align from the style.
  187. match = ( /(?:^|\s)text-align\s*:\s*(\w*);?/i ).exec( style );
  188. align = match && match[1];
  189. if ( align ) {
  190. element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' );
  191. element.attributes.align = align;
  192. }
  193. }
  194. }
  195. if ( element.attributes.style === '' )
  196. delete element.attributes.style;
  197. return element;
  198. }
  199. }
  200. });
  201. }
  202. function sendToFlash() {
  203. var html = CKEDITOR.instances.editor1.getData() ;
  204. // Quick fix for link color.
  205. html = html.replace( /<a /g, '<font color="#0000FF"><u><a ' )
  206. html = html.replace( /<\/a>/g, '</a></u></font>' )
  207. var flash = document.getElementById( 'ckFlashContainer' ) ;
  208. flash.setData( html ) ;
  209. }
  210. CKEDITOR.domReady( function() {
  211. if ( !swfobject.hasFlashPlayerVersion( '8' ) ) {
  212. CKEDITOR.dom.element.createFromHtml( '<span class="alert">' +
  213. 'At least Adobe Flash Player 8 is required to run this sample. ' +
  214. 'You can download it from <a href="http://get.adobe.com/flashplayer">Adobe\'s website</a>.' +
  215. '</span>' ).insertBefore( editor.element );
  216. }
  217. swfobject.embedSWF(
  218. 'assets/outputforflash/outputforflash.swf',
  219. 'ckFlashContainer',
  220. '550',
  221. '400',
  222. '8',
  223. { wmode: 'transparent' }
  224. );
  225. });
  226. </script>
  227. <p>
  228. <input type="button" value="Send to Flash" onclick="sendToFlash();">
  229. </p>
  230. </td>
  231. <td style="vertical-align: top; padding-left: 20px">
  232. <div id="ckFlashContainer"></div>
  233. </td>
  234. </tr>
  235. </table>
  236. <div id="footer">
  237. <hr>
  238. <p>
  239. CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
  240. </p>
  241. <p id="copy">
  242. Copyright &copy; 2003-2016, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
  243. Knabben. All rights reserved.
  244. </p>
  245. </div>
  246. </body>
  247. </html>