3 Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved.
4 For licensing, see LICENSE.md or http://ckeditor.com/license
9 <title>Output for Flash
— CKEditor Sample
</title>
10 <script src=
"../../../ckeditor.js"></script>
11 <script src=
"../../../samples/sample.js"></script>
12 <script src=
"assets/outputforflash/swfobject.js"></script>
13 <link href=
"../../../samples/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.">
33 <a href=
"../../../samples/index.html">CKEditor Samples
</a> » Producing Flash Compliant HTML Output
35 <div class=
"description">
37 This sample shows how to configure CKEditor to output
38 HTML code that can be used with
39 <a class=
"samples" href=
"http://www.adobe.com/livedocs/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000922.html">
41 The code will contain a subset of standard HTML elements like
<code><b
></code>,
42 <code><i
></code>, and
<code><p
></code> as well as HTML attributes.
45 To add a CKEditor instance outputting Flash compliant HTML code, load the editor using a standard
46 JavaScript call, and define CKEditor features to use HTML elements and attributes.
49 For details on how to create this setup check the source code of this sample page.
53 To see how it works, create some content in the editing area of CKEditor on the left
54 and send it to the Flash object on the right side of the page by using the
55 <strong>Send to Flash
</strong> button.
57 <table style=
"width: 100%; border-spacing: 0; border-collapse:collapse;">
59 <td style=
"width: 100%">
60 <textarea cols=
"80" id=
"editor1" name=
"editor1" rows=
"10"><p
><b
><font size=
"18" style=
"font-size:
18px;
">Flash and HTML
</font
></b
></p
><p
>&nbsp;
</p
><p
>It is possible to have
<a href=
"http://ckeditor.com
">CKEditor
</a
> creating content that will be later loaded inside
<b
>Flash
</b
> objects and animations.
</p
><p
>&nbsp;
</p
><p
>Flash has a few limitations when dealing with HTML:
</p
><p
>&nbsp;
</p
><ul
><li
>It has limited support on tags.
</li
><li
>There is no margin between block elements, like paragraphs.
</li
></ul
></textarea>
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.' );
68 var editor = CKEDITOR.replace( 'editor1', {
70 * Ensure that htmlwriter plugin, which is required for this sample, is loaded.
72 extraPlugins: 'htmlwriter',
77 [ 'Source', '-', 'Bold', 'Italic', 'Underline', '-', 'BulletedList', '-', 'Link', 'Unlink' ],
78 [ 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ],
80 [ 'Font', 'FontSize' ],
81 [ 'TextColor', '-', 'About' ]
85 * Style sheet for the contents
87 contentsCss: 'body {color:#
000; background-color#FFF; font-family: Arial; font-size:
80%;} p, ol, ul {margin-top:
0px; margin-bottom:
0px;}',
92 docType: '
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">',
97 coreStyles_bold: { element: 'b' },
98 coreStyles_italic: { element: 'i' },
99 coreStyles_underline: { element: 'u' },
105 // Define the way font elements will be applied to the document. The
"font"
106 // element will be used.
109 attributes: { 'face': '#(family)' }
116 // The CSS part of the font sizes isn't used by Flash, it is there to get the
117 // font rendered correctly in CKEditor.
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',
121 attributes: { 'size': '#(size)' },
122 styles: { 'font-size': '#(size)px' }
128 colorButton_enableMore: true,
130 colorButton_foreStyle: {
132 attributes: { 'color': '#(color)' }
135 colorButton_backStyle: {
137 styles: { 'background-color': '#(color)' }
140 on: { 'instanceReady': configureFlashOutput }
144 * Adjust the behavior of the dataProcessor to match the
145 * requirements of Flash
147 function configureFlashOutput( ev ) {
148 var editor = ev.editor,
149 dataProcessor = editor.dataProcessor,
150 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
152 // Out self closing tags the HTML4 way, like
<br>.
153 dataProcessor.writer.selfClosingEnd = '
>';
155 // Make output formatting match Flash expectations
156 var dtd = CKEDITOR.dtd;
157 for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) {
158 dataProcessor.writer.setRules( e, {
160 breakBeforeOpen: false,
161 breakAfterOpen: false,
162 breakBeforeClose: false,
163 breakAfterClose: false
166 dataProcessor.writer.setRules( 'br', {
168 breakBeforeOpen: false,
169 breakAfterOpen: false,
170 breakBeforeClose: false,
171 breakAfterClose: false
174 // Output properties as attributes, not styles.
175 htmlFilter.addRules( {
177 $: function( element ) {
178 var style, match, width, height, align;
180 // Output dimensions of images as width and height
181 if ( element.name == 'img' ) {
182 style = element.attributes.style;
185 // Get the width from the style.
186 match = ( /(?:^|\s)width\s*:\s*(\d+)px/i ).exec( style );
187 width = match && match[
1];
189 // Get the height from the style.
190 match = ( /(?:^|\s)height\s*:\s*(\d+)px/i ).exec( style );
191 height = match && match[
1];
194 element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' );
195 element.attributes.width = width;
199 element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' );
200 element.attributes.height = height;
205 // Output alignment of paragraphs using align
206 if ( element.name == 'p' ) {
207 style = element.attributes.style;
210 // Get the align from the style.
211 match = ( /(?:^|\s)text-align\s*:\s*(\w*);?/i ).exec( style );
212 align = match && match[
1];
215 element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' );
216 element.attributes.align = align;
221 if ( element.attributes.style === '' )
222 delete element.attributes.style;
230 function sendToFlash() {
231 var html = CKEDITOR.instances.editor1.getData() ;
233 // Quick fix for link color.
234 html = html.replace( /
<a /g, '
<font color=
"#0000FF"><u><a ' )
235 html = html.replace( /<\/a
>/g, '
</a></u></font>' )
237 var flash = document.getElementById( 'ckFlashContainer' ) ;
238 flash.setData( html ) ;
241 CKEDITOR.domReady( function() {
242 if ( !swfobject.hasFlashPlayerVersion( '
8' ) ) {
243 CKEDITOR.dom.element.createFromHtml( '
<span class=
"alert">' +
244 'At least Adobe Flash Player
8 is required to run this sample. ' +
245 'You can download it from
<a href=
"http://get.adobe.com/flashplayer">Adobe\'s website
</a>.' +
246 '
</span>' ).insertBefore( editor.element );
250 'assets/outputforflash/outputforflash.swf',
255 { wmode: 'transparent' }
261 <input type=
"button" value=
"Send to Flash" onclick=
"sendToFlash();">
264 <td style=
"vertical-align: top; padding-left: 20px">
265 <div id=
"ckFlashContainer"></div>
272 CKEditor - The text editor for the Internet -
<a class=
"samples" href=
"http://ckeditor.com/">http://ckeditor.com
</a>
275 Copyright
© 2003-
2014,
<a class=
"samples" href=
"http://cksource.com/">CKSource
</a> - Frederico
276 Knabben. All rights reserved.