5

Consider the initialization:

function initMyTinymce() {
    tinymce.init({
        selector: $(this).attr("id"),
        directionality: "ltr",
    });
}

Is it possible to add properties to tinyMCE after init()?

For example:

plugins: "link,code,textcolor",
relative_urls: false,
convert_urls: false,
remove_script_host: false

I'm using TinyMce 4.1.6 (2014-10-08).

Ninjakannon
  • 3,751
  • 7
  • 53
  • 76
JAN
  • 21,236
  • 66
  • 181
  • 318

2 Answers2

9

Yes, this is possible, but parameters that get read on initialisation only won't have an impact if they get set later on. Example: To change the parameter plugins changes nothing because the tinymce UI has been rendered already.

To set a paramter after initialization use:

editor.settings.my_setting = 'abcd',
arlomedia
  • 8,534
  • 5
  • 60
  • 108
Thariama
  • 50,002
  • 13
  • 138
  • 166
1
function Tiny_readonly(id, action) {
    tinymce.get(id).remove();
        if (action == 0) {
            tinymce.init({
                selector: 'textarea#' + id,
                skin: 'dark',
                height: 200,
                readonly: true,
                toolbar: false,
                menubar: false,
                statusbar: false,
                init_instance_callback: function(editor) {},
            });
        } else {
            tinymce.init({
                selector: 'textarea#' + id,
                height: 250,
                menubar: false,
                skin: 'default',
                plugins: [
                    'advlist autolink lists link  charmap print preview anchor',
                    'searchreplace visualblocks code fullscreen',
                    'insertdatetime media table paste code help wordcount'
                ],
                toolbar: 'undo redo | formatselect | ' +
                    'bold italic backcolor | alignleft aligncenter ' +
                    'alignright alignjustify | bullist numlist outdent indent | ' +
                    'removeformat | table',
                content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }'
            });
        }
}
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Panthelis
  • 11
  • 1
  • 1
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Suraj Rao Nov 07 '21 at 14:32