tiny mce can't be inited when load js dynamically

前端 未结 2 978
忘了有多久
忘了有多久 2020-12-30 17:53

i am having trouble with tinyMCE, when i put

2条回答
  •  庸人自扰
    2020-12-30 18:11

    I resolved this issue by creating a separate coffee script file. Then I declared below function with window scope to access in views.

    window.initialize_tiny_mce = () ->
      if (typeof tinymce != 'undefined' && tinymce != null)
        tinymce.remove();
    
      tinymce.init
        height: '180'
        menubar: false
        statusbar: false
        cleanup: true
        selector: '.new-tinymce-printable-html'
        plugins: [ 'autolink link image code lists advlist' ]
        toolbar: 'styleselect | bold underline italic | bullist numlist outdent indent | link image | code'
        browser_spellcheck: true
        setup: (editor) ->
          editor.on 'keyup', ->
            tinymce.triggerSave()
          editor.on 'change', ->
            console.log editor.getContent()
            return
          return
    

    Then in view partial, I called this function:

    :coffeescript
      initialize_tiny_mce()
    

    Now dynamically created element is assigned a tinymce editor.

提交回复
热议问题