block-quote.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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, console */
  6. import ClassicEditor from '@ckeditor/ckeditor5-build-classic/src/ckeditor';
  7. import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment';
  8. ClassicEditor.builtinPlugins.push( Alignment );
  9. ClassicEditor
  10. .create( document.querySelector( '#snippet-block-quote' ), {
  11. toolbar: {
  12. items: [
  13. 'heading',
  14. '|',
  15. 'bold',
  16. 'italic',
  17. '|',
  18. 'alignment',
  19. '|',
  20. 'blockQuote',
  21. 'outdent',
  22. 'indent',
  23. '|',
  24. 'undo',
  25. 'redo'
  26. ],
  27. viewportTopOffset: window.getViewportTopOffsetConfig()
  28. }
  29. } )
  30. .then( editor => {
  31. window.editor = editor;
  32. // The "Print editor data" button logic.
  33. document.querySelector( '#print-data-action' ).addEventListener( 'click', () => {
  34. const snippetCSSElement = [ ...document.querySelectorAll( 'link' ) ]
  35. .find( linkElement => linkElement.href.endsWith( 'snippet.css' ) );
  36. const iframeElement = document.querySelector( '#print-data-container' );
  37. iframeElement.srcdoc = '<html>' +
  38. '<head>' +
  39. `<title>${ document.title }</title>` +
  40. `<link rel="stylesheet" href="${ snippetCSSElement.href }" type="text/css">` +
  41. '</head>' +
  42. '<body class="ck-content">' +
  43. editor.getData() +
  44. '<script>' +
  45. 'window.addEventListener( \'DOMContentLoaded\', () => { window.print(); } );' +
  46. '</script>' +
  47. '</body>' +
  48. '</html>';
  49. } );
  50. } )
  51. .catch( err => {
  52. console.error( err.stack );
  53. } );