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