balloontoolbar.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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:false */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
  8. import BalloonToolbar from '../../../src/toolbar/balloon/balloontoolbar';
  9. ClassicEditor
  10. .create( document.querySelector( '#editor' ), {
  11. plugins: [ ArticlePluginSet, BalloonToolbar ],
  12. toolbar: [ 'bold', 'italic', 'link', 'undo', 'redo' ],
  13. balloonToolbar: [ 'bold', 'italic', 'link' ]
  14. } )
  15. .then( editor => {
  16. window.editor = editor;
  17. const balloonToolbar = editor.plugins.get( 'BalloonToolbar' );
  18. balloonToolbar.on( 'show', evt => {
  19. const selectionRange = editor.model.document.selection.getFirstRange();
  20. const blockRange = editor.model.createRangeOn( editor.model.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. } );