index.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <!DOCTYPE html>
  2. <!--
  3. Copyright (c) 2003-2021, CKSource - Frederico Knabben. All rights reserved.
  4. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  5. -->
  6. <!--[if IE 8]><html class="ie8"><![endif]-->
  7. <!--[if gt IE 8]><html><![endif]-->
  8. <!--[if !IE]><!--><html lang="en"><!--<![endif]-->
  9. <head>
  10. <meta charset="utf-8">
  11. <title>Toolbar Configurator</title>
  12. <script src="../../ckeditor.js"></script>
  13. <script>
  14. if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
  15. CKEDITOR.tools.enableHtml5Elements( document );
  16. </script>
  17. <link rel="stylesheet" href="lib/codemirror/codemirror.css">
  18. <link rel="stylesheet" href="lib/codemirror/show-hint.css">
  19. <link rel="stylesheet" href="lib/codemirror/neo.css">
  20. <link rel="stylesheet" href="css/fontello.css">
  21. <link rel="stylesheet" href="../css/samples.css">
  22. <meta name="description" content="Try the latest sample of CKEditor 4 and learn more about customizing your WYSIWYG editor with endless possibilities.">
  23. </head>
  24. <body id="toolbar">
  25. <nav class="navigation-a">
  26. <div class="grid-container">
  27. <ul class="navigation-a-left grid-width-70">
  28. <li><a href="https://ckeditor.com/ckeditor-4/">Project Homepage</a></li>
  29. <li><a href="https://github.com/ckeditor/ckeditor4/issues">I found a bug</a></li>
  30. <li><a href="https://github.com/ckeditor/ckeditor4" class="icon-pos-right icon-navigation-a-github">Fork CKEditor on GitHub</a></li>
  31. </ul>
  32. <ul class="navigation-a-right grid-width-30">
  33. <li><a href="https://ckeditor.com/blog/">CKEditor Blog</a></li>
  34. </ul>
  35. </div>
  36. </nav>
  37. <header class="header-a">
  38. <div class="grid-container">
  39. <h1 class="header-a-logo grid-width-30">
  40. <a href="../index.html"><img src="../img/logo.svg" onerror="this.src='../img/logo.png'; this.onerror=null;" alt="CKEditor Logo"></a>
  41. </h1>
  42. <nav class="navigation-b grid-width-70">
  43. <ul>
  44. <li><a href="../index.html" class="button-a">Start</a></li>
  45. <li><a href="index.html" class="button-a button-a-background">Toolbar configurator</a></li>
  46. </ul>
  47. </nav>
  48. </div>
  49. </header>
  50. <main>
  51. <div class="adjoined-top">
  52. <div class="grid-container">
  53. <div class="content grid-width-100">
  54. <div class="grid-container-nested">
  55. <h1 class="grid-width-60">
  56. Toolbar Configurator
  57. <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>
  58. </h1>
  59. <div class="grid-width-40 grid-switch-magic">
  60. <div class="switch">
  61. <span class="balloon-a balloon-a-se">Select configurator type</span>
  62. <input type="radio" name="radio" data-num="1" id="radio-basic" />
  63. <input type="radio" name="radio" data-num="2" id="radio-advanced" />
  64. <label data-for="1" for="radio-basic">Basic</label>
  65. <span class="switch-inner">
  66. <span class="handler"></span>
  67. </span>
  68. <label data-for="2" for="radio-advanced">Advanced</label>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. <div class="adjoined-bottom">
  76. <div class="grid-container">
  77. <div class="grid-width-100">
  78. <div class="editors-container">
  79. <div id="editor-basic"></div>
  80. <div id="editor-advanced"></div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. <div class="grid-container configurator">
  86. <div class="content grid-width-100">
  87. <div class="configurator">
  88. <div>
  89. <div id="toolbarModifierWrapper"></div>
  90. </div>
  91. </div>
  92. </div>
  93. </div>
  94. <div id="help-content">
  95. <div class="grid-container">
  96. <div class="grid-width-100">
  97. <h2>What Am I Doing Here?</h2>
  98. <div class="grid-container grid-container-nested">
  99. <div class="basic">
  100. <div class="grid-width-50">
  101. <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>
  102. <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>
  103. </div>
  104. <div class="grid-width-50">
  105. <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>
  106. <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>
  107. </div>
  108. </div>
  109. <div class="advanced" style="display: none;">
  110. <div class="grid-width-50">
  111. <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>
  112. <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>
  113. </div>
  114. <div class="grid-width-50">
  115. <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>
  116. </div>
  117. </div>
  118. </div>
  119. <p class="grid-container grid-container-nested">
  120. <button type="button" class="help-content-close grid-width-100 button-a button-a-background">Got it. Let's play!</button>
  121. </p>
  122. </div>
  123. </div>
  124. </div>
  125. </main>
  126. <footer class="footer-a grid-container">
  127. <p class="grid-width-100">
  128. CKEditor &ndash; The text editor for the Internet &ndash; <a class="samples" href="https://ckeditor.com/">https://ckeditor.com</a>
  129. </p>
  130. <p class="grid-width-100" id="copy">
  131. Copyright &copy; 2003-2021, <a class="samples" href="https://cksource.com/">CKSource</a> &ndash; Frederico Knabben. All rights reserved.
  132. </p>
  133. </footer>
  134. <script src="lib/codemirror/codemirror.js"></script>
  135. <script src="lib/codemirror/javascript.js"></script>
  136. <script src="lib/codemirror/show-hint.js"></script>
  137. <script src="js/fulltoolbareditor.js"></script>
  138. <script src="js/abstracttoolbarmodifier.js"></script>
  139. <script src="js/toolbarmodifier.js"></script>
  140. <script src="js/toolbartextmodifier.js"></script>
  141. <script src="../js/sf.js"></script>
  142. <script>
  143. ( function() {
  144. 'use strict';
  145. var mode = ( window.location.hash.substr( 1 ) === 'advanced' ) ? 'advanced' : 'basic',
  146. configuratorSection = CKEDITOR.document.findOne( 'main > .grid-container.configurator' ),
  147. basicInstruction = CKEDITOR.document.findOne( '#help-content .basic' ),
  148. advancedInstruction = CKEDITOR.document.findOne( '#help-content .advanced' ),
  149. // Configurator mode switcher.
  150. modeSwitchBasic = CKEDITOR.document.getById( 'radio-basic' ),
  151. modeSwitchAdvanced = CKEDITOR.document.getById( 'radio-advanced' );
  152. // Initial setup
  153. function updateSwitcher() {
  154. if ( mode === 'advanced' ) {
  155. modeSwitchAdvanced.$.checked = true;
  156. } else {
  157. modeSwitchBasic.$.checked = true;
  158. }
  159. }
  160. updateSwitcher();
  161. CKEDITOR.document.getWindow().on( 'hashchange', function( e ) {
  162. var hash = window.location.hash.substr( 1 );
  163. if ( !( hash === 'advanced' || hash === 'basic' ) ) {
  164. return;
  165. }
  166. mode = hash;
  167. onToolbarsDone( mode );
  168. } );
  169. CKEDITOR.document.getWindow().on( 'resize', function() {
  170. updateToolbar( ( mode === 'basic' ? toolbarModifier : toolbarTextModifier )[ 'editorInstance' ] );
  171. } );
  172. function onRefresh( modifier ) {
  173. modifier = modifier || this;
  174. if ( mode === 'basic' && modifier instanceof ToolbarConfigurator.ToolbarTextModifier ) {
  175. return;
  176. }
  177. // CodeMirror container becomes visible, so we need to refresh and to avoid rendering problems.
  178. if ( mode === 'advanced' && modifier instanceof ToolbarConfigurator.ToolbarTextModifier ) {
  179. modifier.codeContainer.refresh();
  180. }
  181. updateToolbar( modifier.editorInstance );
  182. }
  183. function updateToolbar( editor ) {
  184. var editorContainer = editor.container;
  185. // Not always editor is loaded.
  186. if ( !editorContainer ) {
  187. return;
  188. }
  189. var displayStyle = editorContainer.getStyle( 'display' );
  190. editorContainer.setStyle( 'display', 'block' );
  191. var newHeight = editorContainer.getSize( 'height' );
  192. var newMarginTop = parseInt( editorContainer.getComputedStyle( 'margin-top' ), 10 );
  193. newMarginTop = ( isNaN( newMarginTop ) ? 0 : Number( newMarginTop ) );
  194. var newMarginBottom = parseInt( editorContainer.getComputedStyle( 'margin-bottom' ), 10 );
  195. newMarginBottom = ( isNaN( newMarginBottom ) ? 0 : Number( newMarginBottom ) );
  196. var result = newHeight + newMarginTop + newMarginBottom;
  197. editorContainer.setStyle( 'display', displayStyle );
  198. editor.container.getAscendant( 'div' ).setStyle( 'height', result + 'px' );
  199. }
  200. var toolbarModifier = new ToolbarConfigurator.ToolbarModifier( 'editor-basic' );
  201. var done = 0;
  202. toolbarModifier.init( onToolbarInit );
  203. toolbarModifier.onRefresh = onRefresh;
  204. CKEDITOR.document.getById( 'toolbarModifierWrapper' ).append( toolbarModifier.mainContainer );
  205. var toolbarTextModifier = new ToolbarConfigurator.ToolbarTextModifier( 'editor-advanced' );
  206. toolbarTextModifier.init( onToolbarInit );
  207. toolbarTextModifier.onRefresh = onRefresh;
  208. function onToolbarInit() {
  209. if ( ++done === 2 ) {
  210. onToolbarsDone();
  211. positionSticky.watch( CKEDITOR.document.findOne( '.toolbar' ), function() {
  212. return mode === 'advanced';
  213. } );
  214. }
  215. }
  216. function onToolbarsDone() {
  217. if ( mode === 'basic' ) {
  218. toggleModeBasic( false );
  219. } else {
  220. toggleModeAdvanced( false );
  221. }
  222. updateSwitcher();
  223. setTimeout( function() {
  224. CKEDITOR.document.findOne( '.editors-container' ).addClass( 'active' );
  225. CKEDITOR.document.findOne( '#toolbarModifierWrapper' ).addClass( 'active' );
  226. }, 200 );
  227. }
  228. CKEDITOR.document.getById( 'toolbarModifierWrapper' ).append( toolbarTextModifier.mainContainer );
  229. function toogleModeSwitch( onElement, offElement, onModifier, offModifier ) {
  230. onElement.addClass( 'fancy-button-active' );
  231. offElement.removeClass( 'fancy-button-active' );
  232. onModifier.showUI();
  233. offModifier.hideUI();
  234. }
  235. function toggleModeBasic( callOnRefresh ) {
  236. callOnRefresh = ( callOnRefresh !== false );
  237. mode = 'basic';
  238. window.location.hash = '#basic';
  239. toogleModeSwitch( modeSwitchBasic, modeSwitchAdvanced, toolbarModifier, toolbarTextModifier );
  240. configuratorSection.removeClass( 'freed-width' );
  241. basicInstruction.show();
  242. advancedInstruction.hide();
  243. callOnRefresh && onRefresh( toolbarModifier );
  244. }
  245. function toggleModeAdvanced( callOnRefresh ) {
  246. callOnRefresh = ( callOnRefresh !== false );
  247. mode = 'advanced';
  248. window.location.hash = '#advanced';
  249. toogleModeSwitch( modeSwitchAdvanced, modeSwitchBasic, toolbarTextModifier, toolbarModifier );
  250. configuratorSection.addClass( 'freed-width' );
  251. advancedInstruction.show();
  252. basicInstruction.hide();
  253. callOnRefresh && onRefresh( toolbarTextModifier );
  254. }
  255. modeSwitchBasic.on( 'click', toggleModeBasic );
  256. modeSwitchAdvanced.on( 'click', toggleModeAdvanced );
  257. //
  258. // Position:sticky for the toolbar.
  259. //
  260. // Will make elements behave like they were styled with position:sticky.
  261. var positionSticky = {
  262. // Store object: {
  263. // element: CKEDITOR.dom.element, // Element which will float.
  264. // placeholder: CKEDITOR.dom.element, // Placeholder which is place to prevent page bounce.
  265. // isFixed: boolean // Whether element float now.
  266. // }
  267. watched: [],
  268. active: [],
  269. staticContainer: null,
  270. init: function() {
  271. var element = CKEDITOR.dom.element.createFromHtml(
  272. '<div class="staticContainer">' +
  273. '<div class="grid-container" >' +
  274. '<div class="grid-width-100">' +
  275. '<div class="inner"></div>' +
  276. '</div>' +
  277. '</div>' +
  278. '</div>' );
  279. this.staticContainer = element.findOne( '.inner' );
  280. CKEDITOR.document.getBody().append( element );
  281. },
  282. watch: function( element, preventFunc ) {
  283. this.watched.push( {
  284. element: element,
  285. placeholder: new CKEDITOR.dom.element( 'div' ),
  286. isFixed: false,
  287. preventFunc: preventFunc
  288. } );
  289. },
  290. checkAll: function() {
  291. for ( var i = 0; i < this.watched.length; i++ ) {
  292. this.check( this.watched[ i ] );
  293. }
  294. },
  295. check: function( element ) {
  296. var isFixed = element.isFixed;
  297. var shouldBeFixed = this.shouldBeFixed( element );
  298. // Nothing to be done.
  299. if ( isFixed === shouldBeFixed ) {
  300. return;
  301. }
  302. var placeholder = element.placeholder;
  303. if ( isFixed ) {
  304. // Unfixing.
  305. element.element.insertBefore( placeholder );
  306. placeholder.remove();
  307. element.element.removeStyle( 'margin' );
  308. this.active.splice( CKEDITOR.tools.indexOf( this.active, element ), 1 );
  309. } else {
  310. // Fixing.
  311. placeholder.setStyle( 'width', element.element.getSize( 'width' ) + 'px' );
  312. placeholder.setStyle( 'height', element.element.getSize( 'height' ) + 'px' );
  313. placeholder.setStyle( 'margin-bottom', element.element.getComputedStyle( 'margin-bottom' ) );
  314. placeholder.setStyle( 'display', element.element.getComputedStyle( 'display' ) );
  315. placeholder.insertAfter( element.element );
  316. this.staticContainer.append( element.element );
  317. this.active.push( element );
  318. }
  319. element.isFixed = !element.isFixed;
  320. },
  321. shouldBeFixed: function( element ) {
  322. if ( element.preventFunc && element.preventFunc() ) {
  323. return false;
  324. }
  325. // If element is already fixed we are checking it's placeholder.
  326. var related = ( element.isFixed ? element.placeholder : element.element ),
  327. clientRect = related.$.getBoundingClientRect(),
  328. staticHeight = this.staticContainer.getSize('height' ),
  329. elemHeight = element.element.getSize( 'height' );
  330. if ( element.isFixed ) {
  331. return ( clientRect.top + elemHeight < staticHeight );
  332. } else {
  333. return ( clientRect.top < staticHeight );
  334. }
  335. }
  336. };
  337. positionSticky.init();
  338. CKEDITOR.document.getWindow().on( 'scroll',
  339. CKEDITOR.tools.eventsBuffer( 100, positionSticky.checkAll, positionSticky ).input
  340. );
  341. // Make the toolbar sticky.
  342. positionSticky.watch( CKEDITOR.document.findOne( '.editors-container' ) );
  343. // Help button and help-content.
  344. ( function() {
  345. var helpButton = CKEDITOR.document.getById( 'help' ),
  346. helpContent = CKEDITOR.document.getById( 'help-content' );
  347. // Don't show help button on IE8 because it's unsupported by Pico Modal.
  348. if ( CKEDITOR.env.ie && CKEDITOR.env.version == 8 ) {
  349. helpButton.hide();
  350. } else {
  351. // Display help modal when the button is clicked.
  352. helpButton.on( 'click', function( evt ) {
  353. SF.modal( {
  354. // Clone modal content from DOM.
  355. content: helpContent.getHtml(),
  356. afterCreate: function( modal ) {
  357. // Enable modal content button to close the modal.
  358. new CKEDITOR.dom.element( modal.modalElem() ).findOne( '.help-content-close' ).once( 'click', modal.close );
  359. }
  360. } ).show();
  361. } );
  362. }
  363. } )();
  364. } )();
  365. </script>
  366. </body>
  367. </html>