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