3 Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
\r
4 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
8 <title>Output for Flash — 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
22 background: #ffa84c;
\r
26 margin-bottom: 20px;
\r
32 <h1 class="samples">
\r
33 <a href="../../../samples/index.html">CKEditor Samples</a> » Producing Flash Compliant HTML Output
\r
35 <div class="description">
\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&file=00000922.html">
\r
41 The code will contain a subset of standard HTML elements like <code><b></code>,
\r
42 <code><i></code>, and <code><p></code> as well as HTML attributes.
\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
49 For details on how to create this setup check the source code of this sample page.
\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
57 <table style="width: 100%; border-spacing: 0; border-collapse:collapse;">
\r
59 <td style="width: 100%">
\r
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>
\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
68 var editor = CKEDITOR.replace( 'editor1', {
\r
70 * Ensure that htmlwriter plugin, which is required for this sample, is loaded.
\r
72 extraPlugins: 'htmlwriter',
\r
77 [ 'Source', '-', 'Bold', 'Italic', 'Underline', '-', 'BulletedList', '-', 'Link', 'Unlink' ],
\r
78 [ 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ],
\r
80 [ 'Font', 'FontSize' ],
\r
81 [ 'TextColor', '-', 'About' ]
\r
85 * Style sheet for the contents
\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
92 docType: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">',
\r
97 coreStyles_bold: { element: 'b' },
\r
98 coreStyles_italic: { element: 'i' },
\r
99 coreStyles_underline: { element: 'u' },
\r
105 // Define the way font elements will be applied to the document. The "font"
\r
106 // element will be used.
\r
109 attributes: { 'face': '#(family)' }
\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
121 attributes: { 'size': '#(size)' },
\r
122 styles: { 'font-size': '#(size)px' }
\r
128 colorButton_enableMore: true,
\r
130 colorButton_foreStyle: {
\r
132 attributes: { 'color': '#(color)' }
\r
135 colorButton_backStyle: {
\r
137 styles: { 'background-color': '#(color)' }
\r
140 on: { 'instanceReady': configureFlashOutput }
\r
144 * Adjust the behavior of the dataProcessor to match the
\r
145 * requirements of Flash
\r
147 function configureFlashOutput( ev ) {
\r
148 var editor = ev.editor,
\r
149 dataProcessor = editor.dataProcessor,
\r
150 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
\r
152 // Out self closing tags the HTML4 way, like <br>.
\r
153 dataProcessor.writer.selfClosingEnd = '>';
\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
160 breakBeforeOpen: false,
\r
161 breakAfterOpen: false,
\r
162 breakBeforeClose: false,
\r
163 breakAfterClose: false
\r
166 dataProcessor.writer.setRules( 'br', {
\r
168 breakBeforeOpen: false,
\r
169 breakAfterOpen: false,
\r
170 breakBeforeClose: false,
\r
171 breakAfterClose: false
\r
174 // Output properties as attributes, not styles.
\r
175 htmlFilter.addRules( {
\r
177 $: function( element ) {
\r
178 var style, match, width, height, align;
\r
180 // Output dimensions of images as width and height
\r
181 if ( element.name == 'img' ) {
\r
182 style = element.attributes.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
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
194 element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' );
\r
195 element.attributes.width = width;
\r
199 element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' );
\r
200 element.attributes.height = height;
\r
205 // Output alignment of paragraphs using align
\r
206 if ( element.name == 'p' ) {
\r
207 style = element.attributes.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
215 element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' );
\r
216 element.attributes.align = align;
\r
221 if ( element.attributes.style === '' )
\r
222 delete element.attributes.style;
\r
230 function sendToFlash() {
\r
231 var html = CKEDITOR.instances.editor1.getData() ;
\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
237 var flash = document.getElementById( 'ckFlashContainer' ) ;
\r
238 flash.setData( html ) ;
\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
249 swfobject.embedSWF(
\r
250 'assets/outputforflash/outputforflash.swf',
\r
251 'ckFlashContainer',
\r
255 { wmode: 'transparent' }
\r
261 <input type="button" value="Send to Flash" onclick="sendToFlash();">
\r
264 <td style="vertical-align: top; padding-left: 20px">
\r
265 <div id="ckFlashContainer"></div>
\r
272 CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
\r
275 Copyright © 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
\r
276 Knabben. All rights reserved.
\r