tiny mce can't be inited when load js dynamically

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

i am having trouble with tinyMCE, when i put

相关标签:
2条回答
  • 2020-12-30 18:02

    after a day's work, finally found the solution, just put

     window.tinymce.dom.Event.domLoaded = true;
    

    before

     tinymce.init();
    

    then the tinymce can be inited correctly.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题