3 Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
\r 
   4 For licensing, see LICENSE.md or http://ckeditor.com/license
\r 
   6 <!--[if IE 8]><html class="ie8"><![endif]-->
\r 
   7 <!--[if gt IE 8]><html><![endif]-->
\r 
   8 <!--[if !IE]><!--><html><!--<![endif]-->
\r 
  10         <meta charset="utf-8">
\r 
  11         <title>Toolbar Configurator</title>
\r 
  12         <script src="../../ckeditor.js"></script>
\r 
  14                 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
\r 
  15                         CKEDITOR.tools.enableHtml5Elements( document );
\r 
  17         <link rel="stylesheet" href="lib/codemirror/codemirror.css">
\r 
  18         <link rel="stylesheet" href="lib/codemirror/show-hint.css">
\r 
  19         <link rel="stylesheet" href="lib/codemirror/neo.css">
\r 
  20         <link rel="stylesheet" href="css/fontello.css">
\r 
  21         <link rel="stylesheet" href="../css/samples.css">
\r 
  25 <nav class="navigation-a">
\r 
  26         <div class="grid-container">
\r 
  27                 <ul class="navigation-a-left grid-width-70">
\r 
  28                         <li><a href="http://ckeditor.com">Project Homepage</a></li>
\r 
  29                         <li><a href="https://github.com/ckeditor/ckeditor-dev/issues">I found a bug</a></li>
\r 
  30                         <li><a href="http://github.com/ckeditor/ckeditor-dev" class="icon-pos-right icon-navigation-a-github">Fork CKEditor on GitHub</a></li>
\r 
  32                 <ul class="navigation-a-right grid-width-30">
\r 
  33                         <li><a href="http://ckeditor.com/blog-list">CKEditor Blog</a></li>
\r 
  38 <header class="header-a">
\r 
  39         <div class="grid-container">
\r 
  40                 <h1 class="header-a-logo grid-width-30">
\r 
  41                         <a href="../index.html"><img src="../img/logo.png" alt="CKEditor Logo"></a>
\r 
  43                 <nav class="navigation-b grid-width-70">
\r 
  45                                 <li><a href="../index.html"  class="button-a">Start</a></li>
\r 
  46                                 <li><a href="index.html"  class="button-a button-a-background">Toolbar configurator</a></li>
\r 
  53         <div class="adjoined-top">
\r 
  54                 <div class="grid-container">
\r 
  55                         <div class="content grid-width-100">
\r 
  56                                 <div class="grid-container-nested">
\r 
  57                                         <h1 class="grid-width-60">
\r 
  58                                                 Toolbar Configurator
\r 
  59                                                 <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>
\r 
  62                                         <div class="grid-width-40 grid-switch-magic">
\r 
  63                                                 <div class="switch">
\r 
  64                                                         <span class="balloon-a balloon-a-se">Select configurator type</span>
\r 
  65                                                         <input type="radio" name="radio" data-num="1" id="radio-basic" />
\r 
  66                                                         <input type="radio" name="radio" data-num="2" id="radio-advanced" />
\r 
  67                                                         <label data-for="1" for="radio-basic">Basic</label>
\r 
  68                                                         <span class="switch-inner">
\r 
  69                                                                 <span class="handler"></span>
\r 
  71                                                         <label data-for="2" for="radio-advanced">Advanced</label>
\r 
  78         <div class="adjoined-bottom">
\r 
  79                 <div class="grid-container">
\r 
  80                         <div class="grid-width-100">
\r 
  81                                 <div class="editors-container">
\r 
  82                                         <div id="editor-basic"></div>
\r 
  83                                         <div id="editor-advanced"></div>
\r 
  89         <div class="grid-container configurator">
\r 
  90                 <div class="content grid-width-100">
\r 
  91                         <div class="configurator">
\r 
  93                                         <div id="toolbarModifierWrapper"></div>
\r 
  99         <div id="help-content">
\r 
 100                 <div class="grid-container">
\r 
 101                         <div class="grid-width-100">
\r 
 102                                 <h2>What Am I Doing Here?</h2>
\r 
 104                                 <div class="grid-container grid-container-nested">
\r 
 105                                         <div class="basic">
\r 
 106                                                 <div class="grid-width-50">
\r 
 107                                                         <p>Arrange <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbarGroups">toolbar groups</a>, toggle <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-removeButtons">button visibility</a> according to your needs and get your toolbar configuration.</p>
\r 
 108                                                         <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>
\r 
 110                                                 <div class="grid-width-50">
\r 
 111                                                         <p>Read more about different ways of <a href="http://docs.ckeditor.com/#!/guide/dev_configuration">setting configuration</a> and do not forget about <strong>clearing browser cache</strong>.</p>
\r 
 112                                                         <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>
\r 
 115                                         <div class="advanced" style="display: none;">
\r 
 116                                                 <div class="grid-width-50">
\r 
 117                                                         <p>With this code editor you can edit your <a href="http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-toolbar">toolbar configuration</a> live.</p>
\r 
 118                                                         <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>
\r 
 120                                                 <div class="grid-width-50">
\r 
 121                                                         <p>Read more about different ways of <a href="http://docs.ckeditor.com/#!/guide/dev_configuration">setting configuration</a> and do not forget about <strong>clearing browser cache</strong>.</p>
\r 
 126                                 <p class="grid-container grid-container-nested">
\r 
 127                                         <button type="button" class="help-content-close grid-width-100 button-a button-a-background">Got it. Let's play!</button>
\r 
 134 <footer class="footer-a grid-container">
\r 
 135         <p class="grid-width-100">
\r 
 136                 CKEditor – The text editor for the Internet – <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
\r 
 138         <p class="grid-width-100" id="copy">
\r 
 139                 Copyright © 2003-2017, <a class="samples" href="http://cksource.com/">CKSource</a> – Frederico Knabben. All rights reserved.
\r 
 143 <script src="lib/codemirror/codemirror.js"></script>
\r 
 144 <script src="lib/codemirror/javascript.js"></script>
\r 
 145 <script src="lib/codemirror/show-hint.js"></script>
\r 
 147 <script src="js/fulltoolbareditor.js"></script>
\r 
 148 <script src="js/abstracttoolbarmodifier.js"></script>
\r 
 149 <script src="js/toolbarmodifier.js"></script>
\r 
 150 <script src="js/toolbartextmodifier.js"></script>
\r 
 151 <script src="../js/sf.js"></script>
\r 
 157                 var mode = ( window.location.hash.substr( 1 ) === 'advanced' ) ? 'advanced' : 'basic',
\r 
 158                         configuratorSection = CKEDITOR.document.findOne( 'main > .grid-container.configurator' ),
\r 
 159                         basicInstruction = CKEDITOR.document.findOne( '#help-content .basic' ),
\r 
 160                         advancedInstruction = CKEDITOR.document.findOne( '#help-content .advanced' ),
\r 
 162                         // Configurator mode switcher.
\r 
 163                         modeSwitchBasic = CKEDITOR.document.getById( 'radio-basic' ),
\r 
 164                         modeSwitchAdvanced = CKEDITOR.document.getById( 'radio-advanced' );
\r 
 167                 function updateSwitcher() {
\r 
 168                         if ( mode === 'advanced' ) {
\r 
 169                                 modeSwitchAdvanced.$.checked = true;
\r 
 171                                 modeSwitchBasic.$.checked = true;
\r 
 177                 CKEDITOR.document.getWindow().on( 'hashchange', function( e ) {
\r 
 178                         var hash = window.location.hash.substr( 1 );
\r 
 179                         if ( !( hash === 'advanced' || hash === 'basic' ) ) {
\r 
 183                         onToolbarsDone( mode );
\r 
 186                 CKEDITOR.document.getWindow().on( 'resize', function() {
\r 
 187                         updateToolbar( ( mode === 'basic' ? toolbarModifier : toolbarTextModifier )[ 'editorInstance' ] );
\r 
 190                 function onRefresh( modifier ) {
\r 
 191                         modifier = modifier || this;
\r 
 193                         if ( mode === 'basic' && modifier instanceof ToolbarConfigurator.ToolbarTextModifier ) {
\r 
 197                         // CodeMirror container becomes visible, so we need to refresh and to avoid rendering problems.
\r 
 198                         if ( mode === 'advanced' && modifier instanceof ToolbarConfigurator.ToolbarTextModifier ) {
\r 
 199                                 modifier.codeContainer.refresh();
\r 
 202                         updateToolbar( modifier.editorInstance );
\r 
 205                 function updateToolbar( editor ) {
\r 
 206                         var editorContainer = editor.container;
\r 
 208                         // Not always editor is loaded.
\r 
 209                         if ( !editorContainer ) {
\r 
 213                         var displayStyle = editorContainer.getStyle( 'display' );
\r 
 215                         editorContainer.setStyle( 'display', 'block' );
\r 
 217                         var newHeight = editorContainer.getSize( 'height' );
\r 
 219                         var newMarginTop = parseInt( editorContainer.getComputedStyle( 'margin-top' ), 10 );
\r 
 220                         newMarginTop = ( isNaN( newMarginTop ) ? 0 : Number( newMarginTop ) );
\r 
 222                         var newMarginBottom = parseInt( editorContainer.getComputedStyle( 'margin-bottom' ), 10 );
\r 
 223                         newMarginBottom = ( isNaN( newMarginBottom ) ? 0 : Number( newMarginBottom ) );
\r 
 225                         var result = newHeight + newMarginTop + newMarginBottom;
\r 
 227                         editorContainer.setStyle( 'display', displayStyle );
\r 
 229                         editor.container.getAscendant( 'div' ).setStyle( 'height', result + 'px' );
\r 
 232                 var toolbarModifier = new ToolbarConfigurator.ToolbarModifier( 'editor-basic' );
\r 
 235                 toolbarModifier.init( onToolbarInit );
\r 
 236                 toolbarModifier.onRefresh = onRefresh;
\r 
 238                 CKEDITOR.document.getById( 'toolbarModifierWrapper' ).append( toolbarModifier.mainContainer );
\r 
 240                 var toolbarTextModifier = new ToolbarConfigurator.ToolbarTextModifier( 'editor-advanced' );
\r 
 241                 toolbarTextModifier.init( onToolbarInit );
\r 
 242                 toolbarTextModifier.onRefresh = onRefresh;
\r 
 244                 function onToolbarInit() {
\r 
 245                         if ( ++done === 2 ) {
\r 
 248                                 positionSticky.watch( CKEDITOR.document.findOne( '.toolbar' ), function() {
\r 
 249                                         return mode === 'advanced';
\r 
 254                 function onToolbarsDone() {
\r 
 255                         if ( mode === 'basic' ) {
\r 
 256                                 toggleModeBasic( false );
\r 
 258                                 toggleModeAdvanced( false );
\r 
 263                         setTimeout( function() {
\r 
 264                                 CKEDITOR.document.findOne( '.editors-container' ).addClass( 'active' );
\r 
 265                                 CKEDITOR.document.findOne( '#toolbarModifierWrapper' ).addClass( 'active' );
\r 
 269                 CKEDITOR.document.getById( 'toolbarModifierWrapper' ).append( toolbarTextModifier.mainContainer );
\r 
 271                 function toogleModeSwitch( onElement, offElement, onModifier, offModifier ) {
\r 
 272                         onElement.addClass( 'fancy-button-active' );
\r 
 273                         offElement.removeClass( 'fancy-button-active' );
\r 
 275                         onModifier.showUI();
\r 
 276                         offModifier.hideUI();
\r 
 279                 function toggleModeBasic( callOnRefresh ) {
\r 
 280                         callOnRefresh = ( callOnRefresh !== false );
\r 
 282                         window.location.hash = '#basic';
\r 
 283                         toogleModeSwitch( modeSwitchBasic, modeSwitchAdvanced, toolbarModifier, toolbarTextModifier );
\r 
 285                         configuratorSection.removeClass( 'freed-width' );
\r 
 286                         basicInstruction.show();
\r 
 287                         advancedInstruction.hide();
\r 
 289                         callOnRefresh && onRefresh( toolbarModifier );
\r 
 292                 function toggleModeAdvanced( callOnRefresh ) {
\r 
 293                         callOnRefresh = ( callOnRefresh !== false );
\r 
 295                         window.location.hash = '#advanced';
\r 
 296                         toogleModeSwitch( modeSwitchAdvanced, modeSwitchBasic, toolbarTextModifier, toolbarModifier );
\r 
 298                         configuratorSection.addClass( 'freed-width' );
\r 
 299                         advancedInstruction.show();
\r 
 300                         basicInstruction.hide();
\r 
 302                         callOnRefresh && onRefresh( toolbarTextModifier );
\r 
 305                 modeSwitchBasic.on( 'click', toggleModeBasic );
\r 
 306                 modeSwitchAdvanced.on( 'click', toggleModeAdvanced );
\r 
 309                 // Position:sticky for the toolbar.
\r 
 312                 // Will make elements behave like they were styled with position:sticky.
\r 
 313                 var positionSticky = {
\r 
 315                         //              element: CKEDITOR.dom.element, // Element which will float.
\r 
 316                         //              placeholder: CKEDITOR.dom.element, // Placeholder which is place to prevent page bounce.
\r 
 317                         //              isFixed: boolean // Whether element float now.
\r 
 323                         staticContainer: null,
\r 
 326                                 var element = CKEDITOR.dom.element.createFromHtml(
\r 
 327                                         '<div class="staticContainer">' +
\r 
 328                                                 '<div class="grid-container" >' +
\r 
 329                                                         '<div class="grid-width-100">' +
\r 
 330                                                                 '<div class="inner"></div>' +
\r 
 335                                 this.staticContainer = element.findOne( '.inner' );
\r 
 337                                 CKEDITOR.document.getBody().append( element );
\r 
 340                         watch: function( element, preventFunc ) {
\r 
 341                                 this.watched.push( {
\r 
 343                                         placeholder: new CKEDITOR.dom.element( 'div' ),
\r 
 345                                         preventFunc: preventFunc
\r 
 349                         checkAll: function() {
\r 
 350                                 for ( var i = 0; i < this.watched.length; i++ ) {
\r 
 351                                         this.check( this.watched[ i ] );
\r 
 355                         check: function( element ) {
\r 
 356                                 var isFixed = element.isFixed;
\r 
 357                                 var shouldBeFixed = this.shouldBeFixed( element );
\r 
 359                                 // Nothing to be done.
\r 
 360                                 if ( isFixed === shouldBeFixed ) {
\r 
 364                                 var placeholder = element.placeholder;
\r 
 369                                         element.element.insertBefore( placeholder );
\r 
 370                                         placeholder.remove();
\r 
 372                                         element.element.removeStyle( 'margin' );
\r 
 374                                         this.active.splice( CKEDITOR.tools.indexOf( this.active, element ), 1 );
\r 
 378                                         placeholder.setStyle( 'width', element.element.getSize( 'width' ) + 'px' );
\r 
 379                                         placeholder.setStyle( 'height', element.element.getSize( 'height' ) + 'px' );
\r 
 380                                         placeholder.setStyle( 'margin-bottom', element.element.getComputedStyle( 'margin-bottom' ) );
\r 
 381                                         placeholder.setStyle( 'display', element.element.getComputedStyle( 'display' ) );
\r 
 382                                         placeholder.insertAfter( element.element );
\r 
 384                                         this.staticContainer.append( element.element );
\r 
 386                                         this.active.push( element );
\r 
 389                                 element.isFixed = !element.isFixed;
\r 
 392                         shouldBeFixed: function( element ) {
\r 
 393                                 if ( element.preventFunc && element.preventFunc() ) {
\r 
 397                                 // If element is already fixed we are checking it's placeholder.
\r 
 398                                 var related = ( element.isFixed ? element.placeholder : element.element ),
\r 
 399                                         clientRect = related.$.getBoundingClientRect(),
\r 
 400                                         staticHeight = this.staticContainer.getSize('height' ),
\r 
 401                                         elemHeight = element.element.getSize( 'height' );
\r 
 403                                 if ( element.isFixed ) {
\r 
 404                                         return ( clientRect.top + elemHeight < staticHeight );
\r 
 406                                         return ( clientRect.top < staticHeight );
\r 
 411                 positionSticky.init();
\r 
 413                 CKEDITOR.document.getWindow().on( 'scroll',
\r 
 414                         new CKEDITOR.tools.eventsBuffer( 100, positionSticky.checkAll, positionSticky ).input
\r 
 417                 // Make the toolbar sticky.
\r 
 418                 positionSticky.watch( CKEDITOR.document.findOne( '.editors-container' ) );
\r 
 420                 // Help button and help-content.
\r 
 422                         var helpButton = CKEDITOR.document.getById( 'help' ),
\r 
 423                                 helpContent = CKEDITOR.document.getById( 'help-content' );
\r 
 425                         // Don't show help button on IE8 because it's unsupported by Pico Modal.
\r 
 426                         if ( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) {
\r 
 429                                 // Display help modal when the button is clicked.
\r 
 430                                 helpButton.on( 'click', function( evt ) {
\r 
 432                                                 // Clone modal content from DOM.
\r 
 433                                                 content: helpContent.getHtml(),
\r 
 435                                                 afterCreate: function( modal ) {
\r 
 436                                                         // Enable modal content button to close the modal.
\r 
 437                                                         new CKEDITOR.dom.element( modal.modalElem() ).findOne( '.help-content-close' ).once( 'click', modal.close );
\r