index.html 15 KB

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