8
0

font-family.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* globals window, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import FontFamily from '../../src/fontfamily';
  9. const restrictedModeButton = document.getElementById( 'mode-restricted-values' );
  10. const standardModeButton = document.getElementById( 'mode-disable-value-matching' );
  11. restrictedModeButton.addEventListener( 'change', handleModeChange );
  12. standardModeButton.addEventListener( 'change', handleModeChange );
  13. // When page loaded.
  14. startMode( document.querySelector( 'input[name="mode"]:checked' ).value );
  15. // When a user changed a mode.
  16. async function handleModeChange( evt ) {
  17. await startMode( evt.target.value );
  18. }
  19. // Starts the editor.
  20. async function startMode( selectedMode ) {
  21. if ( selectedMode === 'restricted-values' ) {
  22. await reloadEditor();
  23. } else {
  24. await reloadEditor( { supportAllValues: true } );
  25. }
  26. }
  27. async function reloadEditor( options = {} ) {
  28. if ( window.editor ) {
  29. await window.editor.destroy();
  30. }
  31. const config = {
  32. plugins: [ ArticlePluginSet, FontFamily ],
  33. toolbar: [
  34. 'heading', '|', 'fontFamily', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote', 'undo', 'redo'
  35. ],
  36. fontFamily: {}
  37. };
  38. if ( options.supportAllValues ) {
  39. config.fontFamily.supportAllValues = true;
  40. }
  41. window.editor = await ClassicEditor.create( document.querySelector( '#editor' ), config );
  42. }