Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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