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>Toolbar Configuration &mdash; CKEditor Sample</title>
11
        <meta name="ckeditor-sample-name" content="Toolbar Configurations">
12
        <meta name="ckeditor-sample-group" content="Advanced Samples">
13
        <meta name="ckeditor-sample-description" content="Configuring CKEditor to display full or custom toolbar layout.">
14
        <script src="../../../ckeditor.js"></script>
15
        <link href="../../../samples/sample.css" rel="stylesheet"> </head>
16
 
17
    <body>
18
        <h1 class="samples">
19
            <a href="../../../samples/index.html">CKEditor Samples</a> &raquo; Toolbar Configuration </h1>
20
        <div class="description">
21
            <p> This sample page demonstrates editor with loaded
22
                <a href="#fullToolbar">full toolbar</a> (all registered buttons) and, if current editor's configuration modifies default settings, also editor with
23
                <a href="#currentToolbar">modified toolbar</a>. </p>
24
            <p>Since CKEditor 4 there are two ways to configure toolbar buttons.</p>
25
            <h2 class="samples">By
26
                <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbar">config.toolbar</a>
27
            </h2>
28
            <p> You can explicitly define which buttons are displayed in which groups and in which order. This is the more precise setting, but less flexible. If newly added plugin adds its own button you'll have to add it manually to your <code>config.toolbar</code>                setting as well. </p>
29
            <p>To add a CKEditor instance with custom toolbar setting, insert the following JavaScript call to your code:</p> <pre class="samples">
30
CKEDITOR.replace( <em>'textarea_id'</em>, {
31
	<strong>toolbar:</strong> [
32
		{ name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] },	// Defines toolbar group with name (used to create voice label) and items in 3 subgroups.
33
		[ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ],			// Defines toolbar group without name.
34
		'/',																					// Line break - next group will be placed in new line.
35
		{ name: 'basicstyles', items: [ 'Bold', 'Italic' ] }
36
	]
37
});</pre>
38
            <h2 class="samples">By
39
                <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbarGroups">config.toolbarGroups</a>
40
            </h2>
41
            <p> You can define which groups of buttons (like e.g. <code>basicstyles</code>, <code>clipboard</code> and <code>forms</code>) are displayed and in which order. Registered buttons are associated with toolbar groups by <code>toolbar</code> property
42
                in their definition. This setting's advantage is that you don't have to modify toolbar configuration when adding/removing plugins which register their own buttons. </p>
43
            <p>To add a CKEditor instance with custom toolbar groups setting, insert the following JavaScript call to your code:</p> <pre class="samples">
44
CKEDITOR.replace( <em>'textarea_id'</em>, {
45
	<strong>toolbarGroups:</strong> [
46
		{ name: 'document',	   groups: [ 'mode', 'document' ] },			// Displays document group with its two subgroups.
47
 		{ name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },			// Group's name will be used to create voice label.
48
 		'/',																// Line break - next group will be placed in new line.
49
 		{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
50
 		{ name: 'links' }
51
	]
52
 
53
	// NOTE: Remember to leave 'toolbar' property with the default value (null).
54
});</pre> </div>
55
        <div id="currentToolbar" style="display: none">
56
            <h2 class="samples">Current toolbar configuration</h2>
57
            <p>Below you can see editor with current toolbar definition.</p>
58
            <textarea cols="80" id="editorCurrent" name="editorCurrent" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <pre id="editorCurrentCfg" class="samples"></pre> </div>
59
        <div id="fullToolbar">
60
            <h2 class="samples">Full toolbar configuration</h2>
61
            <p>Below you can see editor with full toolbar, generated automatically by the editor.</p>
62
            <p>
63
                <strong>Note</strong>: To create editor instance with full toolbar you don't have to set anything. Just leave <code>toolbar</code> and <code>toolbarGroups</code> with the default, <code>null</code> values. </p>
64
            <textarea cols="80" id="editorFull"
65
                name="editorFull" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea> <pre id="editorFullCfg" class="samples"></pre> </div>
66
        <script>
67
            (function()
68
            {
69
                'use strict';
70
                var buttonsNames;
71
                CKEDITOR.config.extraPlugins = 'toolbar';
72
                CKEDITOR.on('instanceReady', function(evt)
73
                {
74
                    var editor = evt.editor,
75
                        editorCurrent = editor.name == 'editorCurrent',
76
                        defaultToolbar = !(editor.config.toolbar || editor.config.toolbarGroups || editor.config.removeButtons),
77
                        pre = CKEDITOR.document.getById(editor.name + 'Cfg'),
78
                        output = '';
79
                    if (editorCurrent)
80
                    {
81
                        // If default toolbar configuration has been modified, show "current toolbar" section.
82
                        if (!defaultToolbar) CKEDITOR.document.getById('currentToolbar').show();
83
                        else return;
84
                    }
85
                    if (!buttonsNames) buttonsNames = createButtonsNamesHash(editor.ui.items);
86
                    // Toolbar isn't set explicitly, so it was created automatically from toolbarGroups.
87
                    if (!editor.config.toolbar)
88
                    {
89
                        output += '// Toolbar configuration generated automatically by the editor based on config.toolbarGroups.\n' + dumpToolbarConfiguration(editor) + '\n\n' + '// Toolbar groups configuration.\n' + dumpToolbarConfiguration(editor, true)
90
                    }
91
                    // Toolbar groups doesn't count in this case - print only toolbar.
92
                    else
93
                    {
94
                        output += '// Toolbar configuration.\n' + dumpToolbarConfiguration(editor);
95
                    }
96
                    // Recreate to avoid old IE from loosing whitespaces on filling <pre> content.
97
                    var preOutput = pre.getOuterHtml().replace(/(?=<\/)/, output);
98
                    CKEDITOR.dom.element.createFromHtml(preOutput).replace(pre);
99
                });
100
                CKEDITOR.replace('editorCurrent',
101
                {
102
                    height: 100
103
                });
104
                CKEDITOR.replace('editorFull',
105
                {
106
                    // Reset toolbar settings, so full toolbar will be generated automatically.
107
                    toolbar: null,
108
                    toolbarGroups: null,
109
                    removeButtons: null,
110
                    height: 100
111
                });
112
 
113
                function dumpToolbarConfiguration(editor, printGroups)
114
                {
115
                    var output = [],
116
                        toolbar = editor.toolbar;
117
                    for (var i = 0; i < toolbar.length; ++i)
118
                    {
119
                        var group = dumpToolbarGroup(toolbar[i], printGroups);
120
                        if (group) output.push(group);
121
                    }
122
                    return 'config.toolbar' + (printGroups ? 'Groups' : '') + ' = [\n\t' + output.join(',\n\t') + '\n];';
123
                }
124
 
125
                function dumpToolbarGroup(group, printGroups)
126
                {
127
                    var output = [];
128
                    if (typeof group == 'string') return '\'' + group + '\'';
129
                    if (CKEDITOR.tools.isArray(group)) return dumpToolbarItems(group);
130
                    // Skip group when printing entire toolbar configuration and there are no items in this group.
131
                    if (!printGroups && !group.items) return;
132
                    if (group.name) output.push('name: \'' + group.name + '\'');
133
                    if (group.groups) output.push('groups: ' + dumpToolbarItems(group.groups));
134
                    if (!printGroups) output.push('items: ' + dumpToolbarItems(group.items));
135
                    return '{ ' + output.join(', ') + ' }';
136
                }
137
 
138
                function dumpToolbarItems(items)
139
                {
140
                    if (typeof items == 'string') return '\'' + items + '\'';
141
                    var names = [],
142
                        i, item;
143
                    for (var i = 0; i < items.length; ++i)
144
                    {
145
                        item = items[i];
146
                        if (typeof item == 'string') names.push(item);
147
                        else
148
                        {
149
                            if (item.type == CKEDITOR.UI_SEPARATOR) names.push('-');
150
                            else names.push(buttonsNames[item.name]);
151
                        }
152
                    }
153
                    return '[ \'' + names.join('\', \'') + '\' ]';
154
                }
155
                // Creates { 'lowercased': 'LowerCased' } buttons names hash.
156
                function createButtonsNamesHash(items)
157
                {
158
                    var hash = {},
159
                        name;
160
                    for (name in items)
161
                    {
162
                        hash[items[name].name] = name;
163
                    }
164
                    return hash;
165
                }
166
            })();
167
        </script>
168
        <div id="footer">
169
            <hr>
170
            <p> CKEditor - The text editor for the Internet -
171
                <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
172
            </p>
173
            <p id="copy"> Copyright &copy; 2003-2014,
174
                <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico Knabben. All rights reserved. </p>
175
        </div>
176
    </body>
177
 
178
</html>