JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-4.0.1_full
[ckeditor.git] / 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.html 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         CKEDITOR.config.extraPlugins = 'toolbar';\r
99 \r
100         CKEDITOR.on( 'instanceReady', function( evt ) {\r
101                 var editor = evt.editor,\r
102                         editorCurrent = editor.name == 'editorCurrent',\r
103                         defaultToolbar = !( editor.config.toolbar || editor.config.toolbarGroups ),\r
104                         pre = CKEDITOR.document.getById( editor.name + 'Cfg' ),\r
105                         output = '';\r
106 \r
107                 if ( editorCurrent ) {\r
108                         // If default toolbar configuration has been modified, show "current toolbar" section.\r
109                         if ( !defaultToolbar )\r
110                                 CKEDITOR.document.getById( 'currentToolbar' ).show();\r
111                         else\r
112                                 return;\r
113                 }\r
114 \r
115                 // Toolbar isn't set explicitly, so it was created automatically from toolbarGroups.\r
116                 if ( !editor.config.toolbar ) {\r
117                         output +=\r
118                                 '// Toolbar configuration generated automatically by the editor based on config.toolbarGroups.\n' +\r
119                                 dumpToolbarConfiguration( editor ) +\r
120                                 '\n\n' +\r
121                                 '// Toolbar groups configuration.\n' +\r
122                                 dumpToolbarConfiguration( editor, true )\r
123                 }\r
124                 // Toolbar groups doesn't count in this case - print only toolbar.\r
125                 else {\r
126                         output += '// Toolbar configuration.\n' +\r
127                                 dumpToolbarConfiguration( editor );\r
128                 }\r
129 \r
130                 // Recreate to avoid old IE from loosing whitespaces on filling <pre> content.\r
131                 var preOutput = pre.getOuterHtml().replace( /(?=<\/)/, output );\r
132                 CKEDITOR.dom.element.createFromHtml( preOutput ).replace( pre );\r
133         } );\r
134 \r
135 \r
136         CKEDITOR.replace( 'editorCurrent', { height: 100 } );\r
137         CKEDITOR.replace( 'editorFull', {\r
138                 // Reset toolbar settings, so full toolbar will be generated automatically.\r
139                 toolbar: null,\r
140                 toolbarGroups: null,\r
141                 height: 100\r
142         } );\r
143 \r
144         function dumpToolbarConfiguration( editor, printGroups ) {\r
145                 var output = [],\r
146                         toolbar = editor.toolbar;\r
147 \r
148                 for ( var i = 0; i < toolbar.length; ++i ) {\r
149                         var group = dumpToolbarGroup( toolbar[ i ], printGroups );\r
150                         if ( group )\r
151                                 output.push( group );\r
152                 }\r
153 \r
154                 return 'config.toolbar' + ( printGroups ? 'Groups' : '' ) + ' = [\n\t' + output.join( ',\n\t' ) + '\n];';\r
155         }\r
156 \r
157         function dumpToolbarGroup( group, printGroups ) {\r
158                 var output = [];\r
159 \r
160                 if ( typeof group == 'string' )\r
161                         return '\'' + group + '\'';\r
162                 if ( CKEDITOR.tools.isArray( group ) )\r
163                         return dumpToolbarItems( group );\r
164                 // Skip group when printing entire toolbar configuration and there are no items in this group.\r
165                 if ( !printGroups && !group.items )\r
166                         return;\r
167 \r
168                 if ( group.name )\r
169                         output.push( 'name: \'' + group.name + '\'' );\r
170 \r
171                 if ( group.groups )\r
172                         output.push( 'groups: ' + dumpToolbarItems( group.groups ) );\r
173 \r
174                 if ( !printGroups )\r
175                         output.push( 'items: ' + dumpToolbarItems( group.items ) );\r
176 \r
177                 return '{ ' + output.join( ', ' ) + ' }';\r
178         }\r
179 \r
180         function dumpToolbarItems( items ) {\r
181                 if ( typeof items == 'string' )\r
182                         return '\'' + items + '\'';\r
183                 return '[ \'' + items.join( '\', \'' ) + '\' ]';\r
184         }\r
185 \r
186 })();\r
187         </script>\r
188 \r
189         <div id="footer">\r
190                 <hr>\r
191                 <p>\r
192                         CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>\r
193                 </p>\r
194                 <p id="copy">\r
195                         Copyright &copy; 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico\r
196                         Knabben. All rights reserved.\r
197                 </p>\r
198         </div>\r
199 </body>\r
200 </html>\r