ckeditor4.html 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <script src="/static/plugins/ckeditor/ckeditor4/ckeditor.js"></script>
  2. <script>
  3. if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
  4. CKEDITOR.tools.enableHtml5Elements( document );
  5. // The trick to keep the editor in the sample quite small
  6. // unless user specified own height.
  7. CKEDITOR.config.height = 300;
  8. CKEDITOR.config.width = 'auto';
  9. var initSample = ( function() {
  10. var wysiwygareaAvailable = isWysiwygareaAvailable(),
  11. isBBCodeBuiltIn = !!CKEDITOR.plugins.get( 'bbcode' );
  12. return function() {
  13. var editorElement = CKEDITOR.document.getById( 'editor' );
  14. // :(((
  15. if ( isBBCodeBuiltIn ) {
  16. editorElement.setHtml(
  17. 'Hello world!\n\n' +
  18. 'I\'m an instance of [url=https://ckeditor.com]CKEditor[/url].'
  19. );
  20. }
  21. // Depending on the wysiwygarea plugin availability initialize classic or inline editor.
  22. if ( wysiwygareaAvailable ) {
  23. CKEDITOR.replace( 'editor' );
  24. } else {
  25. editorElement.setAttribute( 'contenteditable', 'true' );
  26. CKEDITOR.inline( 'editor' );
  27. // TODO we can consider displaying some info box that
  28. // without wysiwygarea the classic editor may not work.
  29. }
  30. };
  31. function isWysiwygareaAvailable() {
  32. // If in development mode, then the wysiwygarea must be available.
  33. // Split REV into two strings so builder does not replace it :D.
  34. if ( CKEDITOR.revision == ( '%RE' + 'V%' ) ) {
  35. return true;
  36. }
  37. return !!CKEDITOR.plugins.get( 'wysiwygarea' );
  38. }
  39. } )();
  40. initSample();
  41. $("#form-button-save").click(function(){
  42. if (!validator().form()) {
  43. return false
  44. }
  45. const content = CKEDITOR.instances.editor.getData();
  46. $("<input/>").attr("type","hidden").attr("name", "content").val(content).appendTo($("#form-save"));
  47. $("#form-save")[0].submit();
  48. })
  49. </script>