contextualtoolbar.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals window, document, console:false */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePresets from '@ckeditor/ckeditor5-presets/src/article';
  8. import ContextualToolbar from '../../../src/toolbar/contextual/contextualtoolbar';
  9. import Range from '@ckeditor/ckeditor5-engine/src/model/range';
  10. ClassicEditor.create( document.querySelector( '#editor' ), {
  11. plugins: [ ArticlePresets, ContextualToolbar ],
  12. toolbar: [ 'bold', 'italic', 'link', 'undo', 'redo' ],
  13. contextualToolbar: [ 'bold', 'italic', 'link' ]
  14. } )
  15. .then( editor => {
  16. window.editor = editor;
  17. const contextualToolbar = editor.plugins.get( 'ContextualToolbar' );
  18. contextualToolbar.on( 'show', evt => {
  19. const selectionRange = editor.document.selection.getFirstRange();
  20. const blockRange = Range.createOn( editor.document.getRoot().getChild( 0 ) );
  21. if ( selectionRange.containsRange( blockRange ) || selectionRange.isIntersecting( blockRange ) ) {
  22. evt.stop();
  23. }
  24. }, { priority: 'high' } );
  25. } )
  26. .catch( err => {
  27. console.error( err.stack );
  28. } );