index.html 15 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
<!DOCTYPE html>
<!--
Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
CKEditor 4 LTS ("Long Term Support") is available under the terms of the Extended Support Model.
-->
<!--[if IE 8]><html class="ie8"><![endif]-->
<!--[if gt IE 8]><html><![endif]-->
<!--[if !IE]><!--><html lang="en"><!--<![endif]-->
<head>
	<meta charset="utf-8">
	<title>Toolbar Configurator</title>
	<script src="../../ckeditor.js"></script>
	<script>
		if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
			CKEDITOR.tools.enableHtml5Elements( document );
	</script>
	<link rel="stylesheet" href="lib/codemirror/codemirror.css">
	<link rel="stylesheet" href="lib/codemirror/show-hint.css">
	<link rel="stylesheet" href="lib/codemirror/neo.css">
	<link rel="stylesheet" href="css/fontello.css">
	<link rel="stylesheet" href="../css/samples.css">
	<meta name="description" content="Try the latest sample of CKEditor 4 and learn more about customizing your WYSIWYG editor with endless possibilities.">
</head>
<body id="toolbar">

<nav class="navigation-a">
	<div class="grid-container">
		<ul class="navigation-a-left grid-width-70">
			<li><a href="https://ckeditor.com/ckeditor-4/">Project Homepage</a></li>
			<li><a href="https://github.com/ckeditor/ckeditor4/issues">I found a bug</a></li>
			<li><a href="https://github.com/ckeditor/ckeditor4" class="icon-pos-right icon-navigation-a-github">Fork CKEditor on GitHub</a></li>
		</ul>
		<ul class="navigation-a-right grid-width-30">
			<li><a href="https://ckeditor.com/blog/">CKEditor Blog</a></li>
		</ul>
	</div>
</nav>

<header class="header-a">
	<div class="grid-container">
		<h1 class="header-a-logo grid-width-30">
			<a href="../index.html"><img src="../img/logo.svg" onerror="this.src='../img/logo.png'; this.onerror=null;" alt="CKEditor Logo"></a>
		</h1>
		<nav class="navigation-b grid-width-70">
			<ul>
				<li><a href="../index.html"  class="button-a">Start</a></li>
				<li><a href="index.html"  class="button-a button-a-background">Toolbar configurator</a></li>
			</ul>
		</nav>
	</div>
</header>

<main>
	<div class="adjoined-top">
		<div class="grid-container">
			<div class="content grid-width-100">
				<div class="grid-container-nested">
					<h1 class="grid-width-60">
						Toolbar Configurator
						<a href="#help-content" type="button" title="Configurator help" id="help" class="button-a button-a-background button-a-no-text icon-pos-left icon-question-mark">Help</a>
					</h1>

					<div class="grid-width-40 grid-switch-magic">
						<div class="switch">
							<span class="balloon-a balloon-a-se">Select configurator type</span>
							<input type="radio" name="radio" data-num="1" id="radio-basic" />
							<input type="radio" name="radio" data-num="2" id="radio-advanced" />
							<label data-for="1" for="radio-basic">Basic</label>
							<span class="switch-inner">
								<span class="handler"></span>
							</span>
							<label data-for="2" for="radio-advanced">Advanced</label>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="adjoined-bottom">
		<div class="grid-container">
			<div class="grid-width-100">
				<div class="editors-container">
					<div id="editor-basic"></div>
					<div id="editor-advanced"></div>
				</div>
			</div>
		</div>
	</div>

	<div class="grid-container configurator">
		<div class="content grid-width-100">
			<div class="configurator">
				<div>
					<div id="toolbarModifierWrapper"></div>
				</div>
			</div>
		</div>
	</div>

	<div id="help-content">
		<div class="grid-container">
			<div class="grid-width-100">
				<h2>What Am I Doing Here?</h2>

				<div class="grid-container grid-container-nested">
					<div class="basic">
						<div class="grid-width-50">
							<p>Arrange <a href="https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-toolbarGroups">toolbar groups</a>, toggle <a href="https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-removeButtons">button visibility</a> according to your needs and get your toolbar configuration.</p>
							<p>You can replace the content of the <a href="../../config.js"><code>config.js</code></a> file with the generated configuration. If you already set some configuration options you will need to merge both configurations.</p>
						</div>
						<div class="grid-width-50">
							<p>Read more about different ways of <a href="https://ckeditor.com/docs/ckeditor4/latest/guide/dev_configuration.html">setting configuration</a> and do not forget about <strong>clearing browser cache</strong>.</p>
							<p>Arranging toolbar groups is the recommended way of configuring the toolbar, but if you need more freedom you can use the <a href="#advanced">advanced configurator</a>.</p>
						</div>
					</div>
					<div class="advanced" style="display: none;">
						<div class="grid-width-50">
							<p>With this code editor you can edit your <a href="https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-toolbar">toolbar configuration</a> live.</p>
							<p>You can replace the content of the <a href="../../config.js"><code>config.js</code></a> file with the generated configuration. If you already set some configuration options you will need to merge both configurations.</p>
						</div>
						<div class="grid-width-50">
							<p>Read more about different ways of <a href="https://ckeditor.com/docs/ckeditor4/latest/guide/dev_configuration.html">setting configuration</a> and do not forget about <strong>clearing browser cache</strong>.</p>
						</div>
					</div>
				</div>

				<p class="grid-container grid-container-nested">
					<button type="button" class="help-content-close grid-width-100 button-a button-a-background">Got it. Let's play!</button>
				</p>
			</div>
		</div>
	</div>
</main>

<footer class="footer-a grid-container">
	<p class="grid-width-100">
		CKEditor &ndash; The text editor for the Internet &ndash; <a class="samples" href="https://ckeditor.com/">https://ckeditor.com</a>
	</p>
	<p class="grid-width-100" id="copy">
		Copyright &copy; 2003-2023, <a class="samples" href="https://cksource.com/">CKSource</a> Holding sp. z o.o. All rights reserved.
	</p>
</footer>

<script src="lib/codemirror/codemirror.js"></script>
<script src="lib/codemirror/javascript.js"></script>
<script src="lib/codemirror/show-hint.js"></script>

<script src="js/fulltoolbareditor.js"></script>
<script src="js/abstracttoolbarmodifier.js"></script>
<script src="js/toolbarmodifier.js"></script>
<script src="js/toolbartextmodifier.js"></script>
<script src="../js/sf.js"></script>

<script>
	( function() {
		'use strict';

		var mode = ( window.location.hash.substr( 1 ) === 'advanced' ) ? 'advanced' : 'basic',
			configuratorSection = CKEDITOR.document.findOne( 'main > .grid-container.configurator' ),
			basicInstruction = CKEDITOR.document.findOne( '#help-content .basic' ),
			advancedInstruction = CKEDITOR.document.findOne( '#help-content .advanced' ),

			// Configurator mode switcher.
			modeSwitchBasic = CKEDITOR.document.getById( 'radio-basic' ),
			modeSwitchAdvanced = CKEDITOR.document.getById( 'radio-advanced' );

		// Initial setup
		function updateSwitcher() {
			if ( mode === 'advanced' ) {
				modeSwitchAdvanced.$.checked = true;
			} else {
				modeSwitchBasic.$.checked = true;
			}
		}

		updateSwitcher();

		CKEDITOR.document.getWindow().on( 'hashchange', function( e ) {
			var hash = window.location.hash.substr( 1 );
			if ( !( hash === 'advanced' || hash === 'basic' ) ) {
				return;
			}
			mode = hash;
			onToolbarsDone( mode );
		} );

		CKEDITOR.document.getWindow().on( 'resize', function() {
			updateToolbar( ( mode === 'basic' ? toolbarModifier : toolbarTextModifier )[ 'editorInstance' ] );
		} );

		function onRefresh( modifier ) {
			modifier = modifier || this;

			if ( mode === 'basic' && modifier instanceof ToolbarConfigurator.ToolbarTextModifier ) {
				return;
			}

			// CodeMirror container becomes visible, so we need to refresh and to avoid rendering problems.
			if ( mode === 'advanced' && modifier instanceof ToolbarConfigurator.ToolbarTextModifier ) {
				modifier.codeContainer.refresh();
			}

			updateToolbar( modifier.editorInstance );
		}

		function updateToolbar( editor ) {
			var editorContainer = editor.container;

			// Not always editor is loaded.
			if ( !editorContainer ) {
				return;
			}

			var displayStyle = editorContainer.getStyle( 'display' );

			editorContainer.setStyle( 'display', 'block' );

			var newHeight = editorContainer.getSize( 'height' );

			var newMarginTop = parseInt( editorContainer.getComputedStyle( 'margin-top' ), 10 );
			newMarginTop = ( isNaN( newMarginTop ) ? 0 : Number( newMarginTop ) );

			var newMarginBottom = parseInt( editorContainer.getComputedStyle( 'margin-bottom' ), 10 );
			newMarginBottom = ( isNaN( newMarginBottom ) ? 0 : Number( newMarginBottom ) );

			var result = newHeight + newMarginTop + newMarginBottom;

			editorContainer.setStyle( 'display', displayStyle );

			editor.container.getAscendant( 'div' ).setStyle( 'height', result + 'px' );
		}

		var toolbarModifier = new ToolbarConfigurator.ToolbarModifier( 'editor-basic' );

		var done = 0;
		toolbarModifier.init( onToolbarInit );
		toolbarModifier.onRefresh = onRefresh;

		CKEDITOR.document.getById( 'toolbarModifierWrapper' ).append( toolbarModifier.mainContainer );

		var toolbarTextModifier = new ToolbarConfigurator.ToolbarTextModifier( 'editor-advanced' );
		toolbarTextModifier.init( onToolbarInit );
		toolbarTextModifier.onRefresh = onRefresh;

		function onToolbarInit() {
			if ( ++done === 2 ) {
				onToolbarsDone();

				positionSticky.watch( CKEDITOR.document.findOne( '.toolbar' ), function() {
					return mode === 'advanced';
				} );
			}
		}

		function onToolbarsDone() {
			if ( mode === 'basic' ) {
				toggleModeBasic( false );
			} else {
				toggleModeAdvanced( false );
			}

			updateSwitcher();

			setTimeout( function() {
				CKEDITOR.document.findOne( '.editors-container' ).addClass( 'active' );
				CKEDITOR.document.findOne( '#toolbarModifierWrapper' ).addClass( 'active' );
			}, 200 );
		}

		CKEDITOR.document.getById( 'toolbarModifierWrapper' ).append( toolbarTextModifier.mainContainer );

		function toogleModeSwitch( onElement, offElement, onModifier, offModifier ) {
			onElement.addClass( 'fancy-button-active' );
			offElement.removeClass( 'fancy-button-active' );

			onModifier.showUI();
			offModifier.hideUI();
		}

		function toggleModeBasic( callOnRefresh ) {
			callOnRefresh = ( callOnRefresh !== false );
			mode = 'basic';
			window.location.hash = '#basic';
			toogleModeSwitch( modeSwitchBasic, modeSwitchAdvanced, toolbarModifier, toolbarTextModifier );

			configuratorSection.removeClass( 'freed-width' );
			basicInstruction.show();
			advancedInstruction.hide();

			callOnRefresh && onRefresh( toolbarModifier );
		}

		function toggleModeAdvanced( callOnRefresh ) {
			callOnRefresh = ( callOnRefresh !== false );
			mode = 'advanced';
			window.location.hash = '#advanced';
			toogleModeSwitch( modeSwitchAdvanced, modeSwitchBasic, toolbarTextModifier, toolbarModifier );

			configuratorSection.addClass( 'freed-width' );
			advancedInstruction.show();
			basicInstruction.hide();

			callOnRefresh && onRefresh( toolbarTextModifier );
		}

		modeSwitchBasic.on( 'click', toggleModeBasic );
		modeSwitchAdvanced.on( 'click', toggleModeAdvanced );

		//
		// Position:sticky for the toolbar.
		//

		// Will make elements behave like they were styled with position:sticky.
		var positionSticky = {
			// Store object: {
			// 		element: CKEDITOR.dom.element, // Element which will float.
			// 		placeholder: CKEDITOR.dom.element, // Placeholder which is place to prevent page bounce.
			// 		isFixed: boolean // Whether element float now.
			// }
			watched: [],

			active: [],

			staticContainer: null,

			init: function() {
				var element = CKEDITOR.dom.element.createFromHtml(
					'<div class="staticContainer">' +
						'<div class="grid-container" >' +
							'<div class="grid-width-100">' +
								'<div class="inner"></div>' +
							'</div>' +
						'</div>' +
					'</div>' );

				this.staticContainer = element.findOne( '.inner' );

				CKEDITOR.document.getBody().append( element );
			},

			watch: function( element, preventFunc ) {
				this.watched.push( {
					element: element,
					placeholder: new CKEDITOR.dom.element( 'div' ),
					isFixed: false,
					preventFunc: preventFunc
				} );
			},

			checkAll: function() {
				for ( var i = 0; i < this.watched.length; i++ ) {
					this.check( this.watched[ i ] );
				}
			},

			check: function( element ) {
				var isFixed = element.isFixed;
				var shouldBeFixed = this.shouldBeFixed( element );

				// Nothing to be done.
				if ( isFixed === shouldBeFixed ) {
					return;
				}

				var placeholder = element.placeholder;

				if ( isFixed ) {
					// Unfixing.

					element.element.insertBefore( placeholder );
					placeholder.remove();

					element.element.removeStyle( 'margin' );

					this.active.splice( CKEDITOR.tools.indexOf( this.active, element ), 1 );

				} else {
					// Fixing.
					placeholder.setStyle( 'width', element.element.getSize( 'width' ) + 'px' );
					placeholder.setStyle( 'height', element.element.getSize( 'height' ) + 'px' );
					placeholder.setStyle( 'margin-bottom', element.element.getComputedStyle( 'margin-bottom' ) );
					placeholder.setStyle( 'display', element.element.getComputedStyle( 'display' ) );
					placeholder.insertAfter( element.element );

					this.staticContainer.append( element.element );

					this.active.push( element );
				}

				element.isFixed = !element.isFixed;
			},

			shouldBeFixed: function( element ) {
				if ( element.preventFunc && element.preventFunc() ) {
					return false;
				}

				// If element is already fixed we are checking it's placeholder.
				var related = ( element.isFixed ? element.placeholder : element.element ),
					clientRect = related.$.getBoundingClientRect(),
					staticHeight = this.staticContainer.getSize('height' ),
					elemHeight = element.element.getSize( 'height' );

				if ( element.isFixed ) {
					return ( clientRect.top + elemHeight < staticHeight );
				} else {
					return ( clientRect.top < staticHeight );
				}
			}
		};

		positionSticky.init();

		CKEDITOR.document.getWindow().on( 'scroll',
			CKEDITOR.tools.eventsBuffer( 100, positionSticky.checkAll, positionSticky ).input
		);

		// Make the toolbar sticky.
		positionSticky.watch( CKEDITOR.document.findOne( '.editors-container' ) );

		// Help button and help-content.
		( function() {
			var helpButton = CKEDITOR.document.getById( 'help' ),
				helpContent = CKEDITOR.document.getById( 'help-content' );

			// Don't show help button on IE8 because it's unsupported by Pico Modal.
			if ( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) {
				helpButton.hide();
			} else {
				// Display help modal when the button is clicked.
				helpButton.on( 'click', function( evt ) {
					SF.modal( {
						// Clone modal content from DOM.
						content: helpContent.getHtml(),

						afterCreate: function( modal ) {
							// Enable modal content button to close the modal.
							new CKEDITOR.dom.element( modal.modalElem() ).findOne( '.help-content-close' ).once( 'click', modal.close );
						}
					} ).show();
				} );
			}
		} )();
	} )();
</script>
</body>
</html>