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