Trumbowyg: Multiple Instances with different plugin options

Created on 14 Jul 2016  路  5Comments  路  Source: Alex-D/Trumbowyg

Hi,

i have the following problem and i cannot find a way to solveit. Maybe you can propose a solution. I have created a plugin that sends the content of the editor in my server. That was easy. But i would like to have multiple instances of the editor in the same page, with each one containing also an identifier which would be send with the from plugin together with the html to the server. If i extend the trumbowyg options with $.extend(true,$.trumbowyg.options {}); as you have already mentioned in previous posts and try to pass the id like this, only the last id will be saved in the plugin options . What i would really like is, to pass plugin options directly to the instance. For example i have two instances of trumbowyg in my page one will send the html to the server with id:1 and the other with id:2. Is it possible?

question

All 5 comments

Well i though that $.trumbowyg.options is the prototype and if you have multiple instances in the same page then the last instance will overwrite the plugin options. But this is not the case. Although i don't understand why it seems to work fine if the options are extended before the instantiation of Trumbowyg. Probably when the instance is created it strores the prototype options in local variables. This seems to do the trick

You can set plugin options for one instance only: https://github.com/Alex-D/Trumbowyg/blob/develop/index.html#L202

@vasileioslaios how about each() loop and data-* attributes?

<textarea class="editor"
    data-buttons="'formatting', 'btnGrp-design', 'btnGrp-justify', 'btnGrp-lists', 'foreColor', 'backColor', 'viewHTML'" ...>...</textarea>
<textarea class="editor"
    data-buttons="'formatting'" ...>...</textarea>
$('.editor').each(function(index, element){
    var $this = $(element);
    $this.trumbowyg({
        btns: [ $this.data('buttons') ]
    });
});

Well, it has to do with the plugin and the extra options you have to pass through $.extend mostly. Your proposal will only work for multiple instances without extra plugins

Thank you Alex-D this will also do the trick!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dmorrison-olive picture dmorrison-olive  路  3Comments

Tiogshi picture Tiogshi  路  5Comments

Jeong-YeongMin picture Jeong-YeongMin  路  5Comments

tonvanalebeek picture tonvanalebeek  路  6Comments

Droeftoeter picture Droeftoeter  路  5Comments