protocol.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 console:false, window, document */
  6. import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
  7. import Enter from '@ckeditor/ckeditor5-enter/src/enter';
  8. import Typing from '@ckeditor/ckeditor5-typing/src/typing';
  9. import Link from '../../src/link';
  10. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  11. import Undo from '@ckeditor/ckeditor5-undo/src/undo';
  12. import Superscript from '@ckeditor/ckeditor5-basic-styles/src/superscript';
  13. ClassicEditor
  14. .create( document.querySelector( '#editor' ), {
  15. plugins: [ Link, Typing, Paragraph, Undo, Enter, Superscript ],
  16. toolbar: [ 'link', 'undo', 'redo' ],
  17. link: {
  18. addTargetToExternalLinks: true,
  19. defaultProtocol: 'http://'
  20. }
  21. } )
  22. .then( editor => {
  23. window.editor = editor;
  24. const LinkUIPlugin = editor.plugins.get( 'LinkUI' );
  25. const formView = LinkUIPlugin.formView;
  26. const defaultProtocol = editor.config.get( 'link.defaultProtocol' );
  27. document.getElementById( 'default-protocol' ).innerText = defaultProtocol;
  28. document.querySelectorAll( '#protocol-settings input[type="radio"]' ).forEach( radio => {
  29. radio.checked = radio.value === defaultProtocol;
  30. radio.addEventListener( 'click', ( {
  31. target: { value: protocol }
  32. } ) => {
  33. editor.config.set( 'link.defaultProtocol', protocol );
  34. // Change input placeholder just for manual test's case to provide more dynamic behavior.
  35. formView.urlInputView.fieldView.placeholder = protocol + 'example.com';
  36. } );
  37. } );
  38. } )
  39. .catch( err => {
  40. console.error( err.stack );
  41. } );