web-editor.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // const editor = new FroalaEditor('div#froala-editor', {
  2. // height: 300,
  3. // placeholderText: false,
  4. // zIndex: 2501,
  5. // })
  6. $(document).on("dblclick", "#modal-memo .fr-view, #modal-memo #memo-editor", function () {
  7. complete_memo(this);
  8. });
  9. function change_memo_mode($this) {
  10. const modal_body = $($this).closest('.modal-body')
  11. const html = get_editor_codeView_html($this)
  12. $(modal_body).find('.fr-view').html( html )
  13. $(modal_body).find('#memo-editor').val(html)
  14. $(modal_body).find('#froala-editor').toggle()
  15. $(modal_body).find('#memo-editor').toggle()
  16. }
  17. function get_editor_codeView_html(dom_val) {
  18. const modal_body = $(dom_val).closest('.modal-body')
  19. let editor_html = ''
  20. if ($(modal_body).find('#memo-editor').is(':visible')) {
  21. editor_html = $(modal_body).find('#memo-editor').val()
  22. } else {
  23. const editor = $(modal_body).find('#froala-editor')[0]['data-froala.editor']
  24. if (editor.codeView.isActive()) {
  25. editor_html = editor.codeView.get()
  26. editor.codeView.toggle()
  27. } else {
  28. editor_html = editor.html.get()
  29. }
  30. }
  31. return editor_html
  32. }
  33. function complete_memo($this) {
  34. let editor_html = get_editor_codeView_html($this)
  35. $($('#froala-editor').data('preview_id')).html(editor_html);
  36. $($('#froala-editor').data('txtarea_id')).val(
  37. remove_tag(editor_html)
  38. );
  39. $('#modal-memo').modal("hide");
  40. $('#modal-memo').trigger('complete.memo', [$('#froala-editor').data('txtarea_id'), $('#froala-editor').data('preview_id')])
  41. }
  42. // Define popup template.
  43. FroalaEditor.POPUP_TEMPLATES["customPlugin.popup"] =
  44. "[_BUTTONS_][_CUSTOM_LAYER_]";
  45. // Define popup buttons.
  46. Object.assign(FroalaEditor.DEFAULTS, {
  47. popupButtons: ["popupClose", "|", "popupButton1"],
  48. });
  49. // The custom popup is defined inside a plugin (new or existing).
  50. FroalaEditor.PLUGINS.customPlugin = function (editor) {
  51. };
  52. // Define an icon and command for the button that opens the custom popup.
  53. FroalaEditor.DefineIcon("buttonIcon", { NAME: "star", SVG_KEY: "star" });
  54. FroalaEditor.RegisterCommand("myButton", {
  55. title: "Media Library",
  56. icon: "buttonIcon",
  57. undo: false,
  58. focus: false,
  59. plugin: "customPlugin",
  60. callback: async function () {
  61. if ($('.content').find('#modal-media-btn').length === 0) {
  62. $('.content').append(`
  63. <button type="button" id="modal-media-btn" hidden
  64. class="btn btn-success btn-open-modal">
  65. </button>
  66. `)
  67. }
  68. $('#modal-media #media-form button').addClass('bg-primary')
  69. $('#modal-media').data('target-id', $('#froala-editor').data('target-id') ?? '#modal-memo')
  70. if (! PopupForm1FormBMediaForm.btn_act_new(
  71. $('#froala-editor').data('media_brand_code') ?? false)
  72. ) {
  73. return
  74. }
  75. $('#modal-media-btn').data('target', 'media')
  76. $('#modal-media-btn').data('variable', mediaModal)
  77. $('#modal-media-btn').trigger('click')
  78. },
  79. });
  80. function init_froala_editor(dom_val = '#froala-editor', html = undefined) {
  81. new FroalaEditor(dom_val, {
  82. entities: '',
  83. // htmlAllowComments: true,
  84. // useClasses: false,
  85. // htmlAllowedAttrs: ['.*'], // Changed this to all tags
  86. // htmlAllowedTags: ['.*'], // Changed this to all tags
  87. // htmlRemoveTags: [''], // Added this
  88. // fullPage: true, // Added this
  89. // lineBreakerTags: [''], // Added this, not sure if it does anything yet
  90. // linkAlwaysBlank: true, // Added this
  91. key: window.env['FROALA_LICENSE_KEY'],
  92. attribution: false,
  93. enter: FroalaEditor.ENTER_DIV,
  94. height: 600,
  95. placeholderText: false,
  96. zIndex: 2501,
  97. toolbarButtons: {
  98. // Key represents the more button from the toolbar.
  99. moreText: {
  100. // List of buttons used in the group.
  101. buttons: ['bold', 'italic', 'underline', 'strikeThrough', 'subscript', 'superscript', 'fontFamily', 'fontSize', 'textColor', 'backgroundColor', 'inlineClass', 'inlineStyle', 'clearFormatting'],
  102. // Alignment of the group in the toolbar.
  103. align: 'left',
  104. // By default, 3 buttons are shown in the main toolbar. The rest of them are available when using the more button.
  105. buttonsVisible: 3
  106. },
  107. moreParagraph: {
  108. buttons: ['alignLeft', 'alignCenter', 'formatOLSimple', 'alignRight', 'alignJustify', 'formatOL', 'formatUL', 'paragraphFormat', 'paragraphStyle', 'lineHeight', 'outdent', 'indent', 'quote'],
  109. align: 'left',
  110. buttonsVisible: 3
  111. },
  112. moreRich: {
  113. buttons: ['|', 'myButton', 'insertTable', 'emoticons', 'fontAwesome', 'specialCharacters', 'embedly', 'insertFile', 'insertHR'],
  114. align: 'left',
  115. buttonsVisible: 3
  116. },
  117. moreMisc: {
  118. buttons: ['undo', 'redo', 'fullscreen', 'print', 'getPDF', 'spellChecker', 'selectAll', 'html', 'help'],
  119. align: 'right',
  120. buttonsVisible: 2
  121. }
  122. },
  123. quickInsertButtons: ['table', 'ol', 'ul', 'hr'],
  124. }, function () {
  125. if (html) {
  126. this.html.set(html);
  127. }
  128. });
  129. }
  130. $(document).ready(function() {
  131. // Initialize the editor.
  132. init_froala_editor()
  133. });