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