sample.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. /* exported initSample */
  6. if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
  7. CKEDITOR.tools.enableHtml5Elements( document );
  8. // The trick to keep the editor in the sample quite small
  9. // unless user specified own height.
  10. CKEDITOR.config.height = 150;
  11. CKEDITOR.config.width = 'auto';
  12. var initSample = ( function() {
  13. var wysiwygareaAvailable = isWysiwygareaAvailable(),
  14. isBBCodeBuiltIn = !!CKEDITOR.plugins.get( 'bbcode' );
  15. return function() {
  16. var editorElement = CKEDITOR.document.getById( 'editor' );
  17. // :(((
  18. if ( isBBCodeBuiltIn ) {
  19. editorElement.setHtml(
  20. 'Hello world!\n\n' +
  21. 'I\'m an instance of [url=https://ckeditor.com]CKEditor[/url].'
  22. );
  23. }
  24. // Depending on the wysiwygarea plugin availability initialize classic or inline editor.
  25. if ( wysiwygareaAvailable ) {
  26. CKEDITOR.replace( 'editor' );
  27. } else {
  28. editorElement.setAttribute( 'contenteditable', 'true' );
  29. CKEDITOR.inline( 'editor' );
  30. // TODO we can consider displaying some info box that
  31. // without wysiwygarea the classic editor may not work.
  32. }
  33. };
  34. function isWysiwygareaAvailable() {
  35. // If in development mode, then the wysiwygarea must be available.
  36. // Split REV into two strings so builder does not replace it :D.
  37. if ( CKEDITOR.revision == ( '%RE' + 'V%' ) ) {
  38. return true;
  39. }
  40. return !!CKEDITOR.plugins.get( 'wysiwygarea' );
  41. }
  42. } )();