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