+++ /dev/null
-<!DOCTYPE html>\r
-<!--\r
-Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.\r
-For licensing, see LICENSE.md or http://ckeditor.com/license\r
--->\r
-<html>\r
-<head>\r
- <title>Toolbar Configuration — CKEditor Sample</title>\r
- <meta charset="utf-8">\r
- <meta name="ckeditor-sample-name" content="Toolbar Configurations">\r
- <meta name="ckeditor-sample-group" content="Advanced Samples">\r
- <meta name="ckeditor-sample-description" content="Configuring CKEditor to display full or custom toolbar layout.">\r
- <meta name="ckeditor-sample-isnew" content="1">\r
- <script src="../../../ckeditor.js"></script>\r
- <link href="../../../samples/sample.css" rel="stylesheet">\r
-</head>\r
-<body>\r
- <h1 class="samples">\r
- <a href="../../../samples/index.html">CKEditor Samples</a> » Toolbar Configuration\r
- </h1>\r
- <div class="description">\r
- <p>\r
- This sample page demonstrates editor with loaded <a href="#fullToolbar">full toolbar</a> (all registered buttons) and, if\r
- current editor's configuration modifies default settings, also editor with <a href="#currentToolbar">modified toolbar</a>.\r
- </p>\r
-\r
- <p>Since CKEditor 4 there are two ways to configure toolbar buttons.</p>\r
-\r
- <h2 class="samples">By <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbar">config.toolbar</a></h2>\r
-\r
- <p>\r
- You can explicitly define which buttons are displayed in which groups and in which order.\r
- This is the more precise setting, but less flexible. If newly added plugin adds its\r
- own button you'll have to add it manually to your <code>config.toolbar</code> setting as well.\r
- </p>\r
-\r
- <p>To add a CKEditor instance with custom toolbar setting, insert the following JavaScript call to your code:</p>\r
-\r
- <pre class="samples">\r
-CKEDITOR.replace( <em>'textarea_id'</em>, {\r
- <strong>toolbar:</strong> [\r
- { name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] }, // Defines toolbar group with name (used to create voice label) and items in 3 subgroups.\r
- [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ], // Defines toolbar group without name.\r
- '/', // Line break - next group will be placed in new line.\r
- { name: 'basicstyles', items: [ 'Bold', 'Italic' ] }\r
- ]\r
-});</pre>\r
-\r
- <h2 class="samples">By <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbarGroups">config.toolbarGroups</a></h2>\r
-\r
- <p>\r
- You can define which groups of buttons (like e.g. <code>basicstyles</code>, <code>clipboard</code>\r
- and <code>forms</code>) are displayed and in which order. Registered buttons are associated\r
- with toolbar groups by <code>toolbar</code> property in their definition.\r
- This setting's advantage is that you don't have to modify toolbar configuration\r
- when adding/removing plugins which register their own buttons.\r
- </p>\r
-\r
- <p>To add a CKEditor instance with custom toolbar groups setting, insert the following JavaScript call to your code:</p>\r
-\r
- <pre class="samples">\r
-CKEDITOR.replace( <em>'textarea_id'</em>, {\r
- <strong>toolbarGroups:</strong> [\r
- { name: 'document', groups: [ 'mode', 'document' ] }, // Displays document group with its two subgroups.\r
- { name: 'clipboard', groups: [ 'clipboard', 'undo' ] }, // Group's name will be used to create voice label.\r
- '/', // Line break - next group will be placed in new line.\r
- { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },\r
- { name: 'links' }\r
- ]\r
-\r
- // NOTE: Remember to leave 'toolbar' property with the default value (null).\r
-});</pre>\r
- </div>\r
-\r
- <div id="currentToolbar" style="display: none">\r
- <h2 class="samples">Current toolbar configuration</h2>\r
- <p>Below you can see editor with current toolbar definition.</p>\r
- <textarea cols="80" id="editorCurrent" name="editorCurrent" rows="10"><p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p></textarea>\r
- <pre id="editorCurrentCfg" class="samples"></pre>\r
- </div>\r
-\r
- <div id="fullToolbar">\r
- <h2 class="samples">Full toolbar configuration</h2>\r
- <p>Below you can see editor with full toolbar, generated automatically by the editor.</p>\r
- <p>\r
- <strong>Note</strong>: To create editor instance with full toolbar you don't have to set anything.\r
- Just leave <code>toolbar</code> and <code>toolbarGroups</code> with the default, <code>null</code> values.\r
- </p>\r
- <textarea cols="80" id="editorFull" name="editorFull" rows="10"><p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p></textarea>\r
- <pre id="editorFullCfg" class="samples"></pre>\r
- </div>\r
-\r
- <script>\r
-\r
-(function() {\r
- 'use strict';\r
-\r
- var buttonsNames;\r
-\r
- CKEDITOR.config.extraPlugins = 'toolbar';\r
-\r
- CKEDITOR.on( 'instanceReady', function( evt ) {\r
- var editor = evt.editor,\r
- editorCurrent = editor.name == 'editorCurrent',\r
- defaultToolbar = !( editor.config.toolbar || editor.config.toolbarGroups ),\r
- pre = CKEDITOR.document.getById( editor.name + 'Cfg' ),\r
- output = '';\r
-\r
- if ( editorCurrent ) {\r
- // If default toolbar configuration has been modified, show "current toolbar" section.\r
- if ( !defaultToolbar )\r
- CKEDITOR.document.getById( 'currentToolbar' ).show();\r
- else\r
- return;\r
- }\r
-\r
- if ( !buttonsNames )\r
- buttonsNames = createButtonsNamesHash( editor.ui.items );\r
-\r
- // Toolbar isn't set explicitly, so it was created automatically from toolbarGroups.\r
- if ( !editor.config.toolbar ) {\r
- output +=\r
- '// Toolbar configuration generated automatically by the editor based on config.toolbarGroups.\n' +\r
- dumpToolbarConfiguration( editor ) +\r
- '\n\n' +\r
- '// Toolbar groups configuration.\n' +\r
- dumpToolbarConfiguration( editor, true )\r
- }\r
- // Toolbar groups doesn't count in this case - print only toolbar.\r
- else {\r
- output += '// Toolbar configuration.\n' +\r
- dumpToolbarConfiguration( editor );\r
- }\r
-\r
- // Recreate to avoid old IE from loosing whitespaces on filling <pre> content.\r
- var preOutput = pre.getOuterHtml().replace( /(?=<\/)/, output );\r
- CKEDITOR.dom.element.createFromHtml( preOutput ).replace( pre );\r
- } );\r
-\r
- CKEDITOR.replace( 'editorCurrent', { height: 100 } );\r
- CKEDITOR.replace( 'editorFull', {\r
- // Reset toolbar settings, so full toolbar will be generated automatically.\r
- toolbar: null,\r
- toolbarGroups: null,\r
- height: 100\r
- } );\r
-\r
- function dumpToolbarConfiguration( editor, printGroups ) {\r
- var output = [],\r
- toolbar = editor.toolbar;\r
-\r
- for ( var i = 0; i < toolbar.length; ++i ) {\r
- var group = dumpToolbarGroup( toolbar[ i ], printGroups );\r
- if ( group )\r
- output.push( group );\r
- }\r
-\r
- return 'config.toolbar' + ( printGroups ? 'Groups' : '' ) + ' = [\n\t' + output.join( ',\n\t' ) + '\n];';\r
- }\r
-\r
- function dumpToolbarGroup( group, printGroups ) {\r
- var output = [];\r
-\r
- if ( typeof group == 'string' )\r
- return '\'' + group + '\'';\r
- if ( CKEDITOR.tools.isArray( group ) )\r
- return dumpToolbarItems( group );\r
- // Skip group when printing entire toolbar configuration and there are no items in this group.\r
- if ( !printGroups && !group.items )\r
- return;\r
-\r
- if ( group.name )\r
- output.push( 'name: \'' + group.name + '\'' );\r
-\r
- if ( group.groups )\r
- output.push( 'groups: ' + dumpToolbarItems( group.groups ) );\r
-\r
- if ( !printGroups )\r
- output.push( 'items: ' + dumpToolbarItems( group.items ) );\r
-\r
- return '{ ' + output.join( ', ' ) + ' }';\r
- }\r
-\r
- function dumpToolbarItems( items ) {\r
- if ( typeof items == 'string' )\r
- return '\'' + items + '\'';\r
-\r
- var names = [],\r
- i, item;\r
-\r
- for ( var i = 0; i < items.length; ++i ) {\r
- item = items[ i ];\r
- if ( typeof item == 'string' )\r
- names.push( item );\r
- else {\r
- if ( item.type == CKEDITOR.UI_SEPARATOR )\r
- names.push( '-' );\r
- else\r
- names.push( buttonsNames[ item.name ] );\r
- }\r
- }\r
-\r
- return '[ \'' + names.join( '\', \'' ) + '\' ]';\r
- }\r
-\r
- // Creates { 'lowercased': 'LowerCased' } buttons names hash.\r
- function createButtonsNamesHash( items ) {\r
- var hash = {},\r
- name;\r
-\r
- for ( name in items ) {\r
- hash[ items[ name ].name ] = name;\r
- }\r
-\r
- return hash;\r
- }\r
-\r
-})();\r
- </script>\r
-\r
- <div id="footer">\r
- <hr>\r
- <p>\r
- CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>\r
- </p>\r
- <p id="copy">\r
- Copyright © 2003-2013, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico\r
- Knabben. All rights reserved.\r
- </p>\r
- </div>\r
-</body>\r
-</html>\r