contextualtoolbar.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  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 ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import ContextualToolbar from '../../../src/toolbar/contextual/contextualtoolbar';
  9. import Range from '@ckeditor/ckeditor5-engine/src/model/range';
  10. ClassicEditor
  11. .create( document.querySelector( '#editor' ), {
  12. plugins: [ ArticlePluginSet, ContextualToolbar ],
  13. toolbar: [ 'bold', 'italic', 'link', 'undo', 'redo' ],
  14. contextualToolbar: [ 'bold', 'italic', 'link' ]
  15. } )
  16. .then( editor => {
  17. window.editor = editor;
  18. const contextualToolbar = editor.plugins.get( 'ContextualToolbar' );
  19. contextualToolbar.on( 'show', evt => {
  20. const selectionRange = editor.document.selection.getFirstRange();
  21. const blockRange = Range.createOn( editor.document.getRoot().getChild( 0 ) );
  22. if ( selectionRange.containsRange( blockRange ) || selectionRange.isIntersecting( blockRange ) ) {
  23. evt.stop();
  24. }
  25. }, { priority: 'high' } );
  26. } )
  27. .catch( err => {
  28. console.error( err.stack );
  29. } );