ckeditor/samples/old/toolbar/toolbar.html
changeset 0 44d330dccc59
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ckeditor/samples/old/toolbar/toolbar.html	Thu Dec 15 18:10:20 2016 +0300
     1.3 @@ -0,0 +1,235 @@
     1.4 +<!DOCTYPE html>
     1.5 +<!--
     1.6 +Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
     1.7 +For licensing, see LICENSE.md or http://ckeditor.com/license
     1.8 +-->
     1.9 +<html>
    1.10 +<head>
    1.11 +	<meta charset="utf-8">
    1.12 +	<title>Toolbar Configuration &mdash; CKEditor Sample</title>
    1.13 +	<meta name="ckeditor-sample-name" content="Toolbar Configurations">
    1.14 +	<meta name="ckeditor-sample-group" content="Advanced Samples">
    1.15 +	<meta name="ckeditor-sample-description" content="Configuring CKEditor to display full or custom toolbar layout.">
    1.16 +	<script src="../../../ckeditor.js"></script>
    1.17 +	<link href="../../../samples/old/sample.css" rel="stylesheet">
    1.18 +</head>
    1.19 +<body>
    1.20 +	<h1 class="samples">
    1.21 +		<a href="../../../samples/old/index.html">CKEditor Samples</a> &raquo; Toolbar Configuration
    1.22 +	</h1>
    1.23 +	<div class="warning deprecated">
    1.24 +		This sample is not maintained anymore. Check out the <a href="../../../samples/toolbarconfigurator/index.html#basic">brand new CKEditor Toolbar Configurator</a>.
    1.25 +	</div>
    1.26 +	<div class="description">
    1.27 +		<p>
    1.28 +			This sample page demonstrates editor with loaded <a href="#fullToolbar">full toolbar</a> (all registered buttons) and, if
    1.29 +			current editor's configuration modifies default settings, also editor with <a href="#currentToolbar">modified toolbar</a>.
    1.30 +		</p>
    1.31 +
    1.32 +		<p>Since CKEditor 4 there are two ways to configure toolbar buttons.</p>
    1.33 +
    1.34 +		<h2 class="samples">By <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbar">config.toolbar</a></h2>
    1.35 +
    1.36 +		<p>
    1.37 +			You can explicitly define which buttons are displayed in which groups and in which order.
    1.38 +			This is the more precise setting, but less flexible. If newly added plugin adds its
    1.39 +			own button you'll have to add it manually to your <code>config.toolbar</code> setting as well.
    1.40 +		</p>
    1.41 +
    1.42 +		<p>To add a CKEditor instance with custom toolbar setting, insert the following JavaScript call to your code:</p>
    1.43 +
    1.44 +		<pre class="samples">
    1.45 +CKEDITOR.replace( <em>'textarea_id'</em>, {
    1.46 +	<strong>toolbar:</strong> [
    1.47 +		{ name: 'document', items: [ 'Source', '-', 'NewPage', 'Preview', '-', 'Templates' ] },	// Defines toolbar group with name (used to create voice label) and items in 3 subgroups.
    1.48 +		[ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ],			// Defines toolbar group without name.
    1.49 +		'/',																					// Line break - next group will be placed in new line.
    1.50 +		{ name: 'basicstyles', items: [ 'Bold', 'Italic' ] }
    1.51 +	]
    1.52 +});</pre>
    1.53 +
    1.54 +		<h2 class="samples">By <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbarGroups">config.toolbarGroups</a></h2>
    1.55 +
    1.56 +		<p>
    1.57 +			You can define which groups of buttons (like e.g. <code>basicstyles</code>, <code>clipboard</code>
    1.58 +			and <code>forms</code>) are displayed and in which order. Registered buttons are associated
    1.59 +			with toolbar groups by <code>toolbar</code> property in their definition.
    1.60 +			This setting's advantage is that you don't have to modify toolbar configuration
    1.61 +			when adding/removing plugins which register their own buttons.
    1.62 +		</p>
    1.63 +
    1.64 +		<p>To add a CKEditor instance with custom toolbar groups setting, insert the following JavaScript call to your code:</p>
    1.65 +
    1.66 +		<pre class="samples">
    1.67 +CKEDITOR.replace( <em>'textarea_id'</em>, {
    1.68 +	<strong>toolbarGroups:</strong> [
    1.69 +		{ name: 'document',	   groups: [ 'mode', 'document' ] },			// Displays document group with its two subgroups.
    1.70 + 		{ name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },			// Group's name will be used to create voice label.
    1.71 + 		'/',																// Line break - next group will be placed in new line.
    1.72 + 		{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
    1.73 + 		{ name: 'links' }
    1.74 +	]
    1.75 +
    1.76 +	// NOTE: Remember to leave 'toolbar' property with the default value (null).
    1.77 +});</pre>
    1.78 +	</div>
    1.79 +
    1.80 +	<div id="currentToolbar" style="display: none">
    1.81 +		<h2 class="samples">Current toolbar configuration</h2>
    1.82 +		<p>Below you can see editor with current toolbar definition.</p>
    1.83 +		<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>
    1.84 +		<pre id="editorCurrentCfg" class="samples"></pre>
    1.85 +	</div>
    1.86 +
    1.87 +	<div id="fullToolbar">
    1.88 +		<h2 class="samples">Full toolbar configuration</h2>
    1.89 +		<p>Below you can see editor with full toolbar, generated automatically by the editor.</p>
    1.90 +		<p>
    1.91 +			<strong>Note</strong>: To create editor instance with full toolbar you don't have to set anything.
    1.92 +			Just leave <code>toolbar</code> and <code>toolbarGroups</code> with the default, <code>null</code> values.
    1.93 +		</p>
    1.94 +		<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>
    1.95 +		<pre id="editorFullCfg" class="samples"></pre>
    1.96 +	</div>
    1.97 +
    1.98 +	<script>
    1.99 +
   1.100 +(function() {
   1.101 +	'use strict';
   1.102 +
   1.103 +	var buttonsNames;
   1.104 +
   1.105 +	CKEDITOR.config.extraPlugins = 'toolbar';
   1.106 +
   1.107 +	CKEDITOR.on( 'instanceReady', function( evt ) {
   1.108 +		var editor = evt.editor,
   1.109 +			editorCurrent = editor.name == 'editorCurrent',
   1.110 +			defaultToolbar = !( editor.config.toolbar || editor.config.toolbarGroups || editor.config.removeButtons ),
   1.111 +			pre = CKEDITOR.document.getById( editor.name + 'Cfg' ),
   1.112 +			output = '';
   1.113 +
   1.114 +		if ( editorCurrent ) {
   1.115 +			// If default toolbar configuration has been modified, show "current toolbar" section.
   1.116 +			if ( !defaultToolbar )
   1.117 +				CKEDITOR.document.getById( 'currentToolbar' ).show();
   1.118 +			else
   1.119 +				return;
   1.120 +		}
   1.121 +
   1.122 +		if ( !buttonsNames )
   1.123 +			buttonsNames = createButtonsNamesHash( editor.ui.items );
   1.124 +
   1.125 +		// Toolbar isn't set explicitly, so it was created automatically from toolbarGroups.
   1.126 +		if ( !editor.config.toolbar ) {
   1.127 +			output +=
   1.128 +				'// Toolbar configuration generated automatically by the editor based on config.toolbarGroups.\n' +
   1.129 +				dumpToolbarConfiguration( editor ) +
   1.130 +				'\n\n' +
   1.131 +				'// Toolbar groups configuration.\n' +
   1.132 +				dumpToolbarConfiguration( editor, true )
   1.133 +		}
   1.134 +		// Toolbar groups doesn't count in this case - print only toolbar.
   1.135 +		else {
   1.136 +			output += '// Toolbar configuration.\n' +
   1.137 +				dumpToolbarConfiguration( editor );
   1.138 +		}
   1.139 +
   1.140 +		// Recreate to avoid old IE from loosing whitespaces on filling <pre> content.
   1.141 +		var preOutput = pre.getOuterHtml().replace( /(?=<\/)/, output );
   1.142 +		CKEDITOR.dom.element.createFromHtml( preOutput ).replace( pre );
   1.143 +	} );
   1.144 +
   1.145 +	CKEDITOR.replace( 'editorCurrent', { height: 100 } );
   1.146 +	CKEDITOR.replace( 'editorFull', {
   1.147 +		// Reset toolbar settings, so full toolbar will be generated automatically.
   1.148 +		toolbar: null,
   1.149 +		toolbarGroups: null,
   1.150 +		removeButtons: null,
   1.151 +		height: 100
   1.152 +	} );
   1.153 +
   1.154 +	function dumpToolbarConfiguration( editor, printGroups ) {
   1.155 +		var output = [],
   1.156 +			toolbar = editor.toolbar;
   1.157 +
   1.158 +		for ( var i = 0; i < toolbar.length; ++i ) {
   1.159 +			var group = dumpToolbarGroup( toolbar[ i ], printGroups );
   1.160 +			if ( group )
   1.161 +				output.push( group );
   1.162 +		}
   1.163 +
   1.164 +		return 'config.toolbar' + ( printGroups ? 'Groups' : '' ) + ' = [\n\t' + output.join( ',\n\t' ) + '\n];';
   1.165 +	}
   1.166 +
   1.167 +	function dumpToolbarGroup( group, printGroups ) {
   1.168 +		var output = [];
   1.169 +
   1.170 +		if ( typeof group == 'string' )
   1.171 +			return '\'' + group + '\'';
   1.172 +		if ( CKEDITOR.tools.isArray( group ) )
   1.173 +			return dumpToolbarItems( group );
   1.174 +		// Skip group when printing entire toolbar configuration and there are no items in this group.
   1.175 +		if ( !printGroups && !group.items )
   1.176 +			return;
   1.177 +
   1.178 +		if ( group.name )
   1.179 +			output.push( 'name: \'' + group.name + '\'' );
   1.180 +
   1.181 +		if ( group.groups )
   1.182 +			output.push( 'groups: ' + dumpToolbarItems( group.groups ) );
   1.183 +
   1.184 +		if ( !printGroups )
   1.185 +			output.push( 'items: ' + dumpToolbarItems( group.items ) );
   1.186 +
   1.187 +		return '{ ' + output.join( ', ' ) + ' }';
   1.188 +	}
   1.189 +
   1.190 +	function dumpToolbarItems( items ) {
   1.191 +		if ( typeof items == 'string' )
   1.192 +			return '\'' + items + '\'';
   1.193 +
   1.194 +		var names = [],
   1.195 +			i, item;
   1.196 +
   1.197 +		for ( var i = 0; i < items.length; ++i ) {
   1.198 +			item = items[ i ];
   1.199 +			if ( typeof item == 'string' )
   1.200 +				names.push( item );
   1.201 +			else {
   1.202 +				if ( item.type == CKEDITOR.UI_SEPARATOR )
   1.203 +					names.push( '-' );
   1.204 +				else
   1.205 +					names.push( buttonsNames[ item.name ] );
   1.206 +			}
   1.207 +		}
   1.208 +
   1.209 +		return '[ \'' + names.join( '\', \'' ) + '\' ]';
   1.210 +	}
   1.211 +
   1.212 +	// Creates { 'lowercased': 'LowerCased' } buttons names hash.
   1.213 +	function createButtonsNamesHash( items ) {
   1.214 +		var hash = {},
   1.215 +			name;
   1.216 +
   1.217 +		for ( name in items ) {
   1.218 +			hash[ items[ name ].name ] = name;
   1.219 +		}
   1.220 +
   1.221 +		return hash;
   1.222 +	}
   1.223 +
   1.224 +})();
   1.225 +	</script>
   1.226 +
   1.227 +	<div id="footer">
   1.228 +		<hr>
   1.229 +		<p>
   1.230 +			CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
   1.231 +		</p>
   1.232 +		<p id="copy">
   1.233 +			Copyright &copy; 2003-2016, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
   1.234 +			Knabben. All rights reserved.
   1.235 +		</p>
   1.236 +	</div>
   1.237 +</body>
   1.238 +</html>