0

I've multiple textarea on my page, i'm trying to send a $lang variable to my link_list file to be able then to have links generated in the correct language,

How to get the current textarea ID value and send this value to my link_list file ?

I've tried with : tinymce.editors.id but unfortunately not working.

can someone please help me ?

Thanks a lot

<textarea id="fr" name="text_fr"></textarea>

<textarea id="en" name="text_en"></textarea>

and :

tinyMCE.init({

selector: "textarea",

link_list: "link_list.php?lang=" + tinymce.editors.id,

...

});
Lucien
  • 65
  • 1
  • 7

2 Answers2

0

The tinymce.editors array is not populated until after you init() the editor instances so you can't rely on it to have the data you need to do the initialization.

I would have separate inits for each language and have a base configuration that you just update with the link_list value and then init using the calculated configuration.

You can always use JavaScript to modify/extend your standard init on an editor instance basis.

For example, start with your standard configuration:

baseConfig = {
  selector: 'textarea'
  //everything here except your language specific configuration
  ....
}

...since this is just a simple JavaScript object you can inject additional properties/methods into that object before you use it to initialize TinyMCE.

For example:

customConfigEn = {
  link_list: "link_list.php?lang=en"
}

customConfigFr = {
  link_list: "link_list.php?lang=fr"
}

Then you can "inject" customConfig into baseConfig. The easiest way is to use jQuery's extend method:

$.extend(baseConfig, customConfigEn);

... or ...

$.extend(baseConfig, customConfigFr);

...this will take all the methods and properties from customConfig and add them to baseConfig. Once you are done you can then load TinyMCE using the newly updated baseConfig:

tinymce.init(baseConfig);

This general technique allows you to create a "standard" configuration with all the base capabilities you need while injecting additional configuration options on a page by page basis.

Note: You could also choose to create these configurations on the server before you render the HTML page but you did not mention what server side language you are using so I can't speak to how you might do it from the server side.

Michael Fromin
  • 13,131
  • 2
  • 20
  • 31
  • Tried your solution but i don't understand how to use customConfigEn when my english textarea is used and customConfigFr when my french textarea is used. – Lucien May 16 '17 at 06:34
  • You have to determine when you use which language and build the configuration as needed prior to initializing that particular instance of TinyMCE. If you are putting multiple textareas on the page how do you know what languages to use? – Michael Fromin May 16 '17 at 14:03
  • Hello, i found the solution here, it worked fine for me : http://stackoverflow.com/questions/36771770/dynamically-get-tinymce-settings-to-apply-them-to-another-init – Lucien May 17 '17 at 06:19
0

Michael Fromin, Thanks a lot for your answer.

Tried your solution but i don't understand how to use customConfigEn when my english textarea is used and customConfigFr when my french textarea is used.

This is my code where customConfigEn is used :

baseConfig = {
 theme : "modern", 
 selector: "textarea",
 plugins: ["advlist autolink...
 ...
}

customConfigEn = {  
    editor_selector: "en",
    link_list: "link_list.php?lang=en",
}
customConfigFr = {  
    editor_selector: "fr",
    link_list: "link_list.php?lang=fr",
}


$.extend(baseConfig, customConfigEn);

tinyMCE.init(baseConfig);

Again, thanks for your help, i really appreciate

Lucien
  • 65
  • 1
  • 7