动态获取TinyMCE设置(以将其应用到另一个init) [英] Dynamically get TinyMCE settings (to apply them to another init)

查看:536
本文介绍了动态获取TinyMCE设置(以将其应用到另一个init)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取TinyMCE 设置?

How can I get TinyMCE settings?

我想从第一个编辑器中获取它们并存储在变量中(第一个或最后一个都没有关系,只要所讨论的脚本不依赖于ID即可获取设置).然后,在需要时,将它们与tinyMCE.init一起使用以初始化新的编辑器.

I'd want to take them from the first editor and store in variable (first or last doesn't matter, as long as script in question doesn't rely on id to get settings). Then, when needed, use them with tinyMCE.init to initialize new editor.

var mysettings = $(".tinymce").last().GETEDITORSETTINGS;
$(".button").click(function(){
   mysettings.selector = ".newtextarea";
   tinyMCE.init(mysettings);
});

推荐答案

您可以通过两种基本方法来解决此问题...

There are two basic ways you can handle this...

选项1-抓取当前设置

tinymce.activeEditor.settings将为您提供一个包含当前TinyMCE实例设置的对象.然后,您可以按照需要为要实例化的新编辑器实例创建新的init对象的任何方式来进行操作. (您也可以使用tinymce.get().settings而不是活动编辑器来定位特定实例).

tinymce.activeEditor.settings will get you an object that contains the settings for the current TinyMCE instance. You can then manipulate this in whatever way you need to create a new init object for the new editor instance you want to instantiate. (You can also use tinymce.get().settings to target a specific instance as opposed to the active editor).

选项2-(推荐)使用默认init并在每次需要时克隆它

另一个选择(也是我推荐的选择)是在页面上创建一个默认"初始化对象作为JavaScript变量,然后在以后引用它.例如:

The other option (and the one I would recommend) is to create a "default" init object as a JavaScript variable on your page and then reference that later. For example:

var default_init = {
    theme: "modern",
    plugins....,
    toolbar....
}

...然后,当您要调用TinyMCE实例时,可以使用该基础对象进行初始化:

...then when you want to invoke a TinyMCE instance you can use that base object to make your init:

var first_init = jQuery.extend({}, default_init);
first_init.selector = ".first_textarea";
tinymce.init(first_init);

var second_init = jQuery.extend({}, default_init);
second_init.selector = ".second_textarea";
tinymce.init(second_init);

(如果您不使用jQuery,则可以编写自己的对象克隆方法,而不必使用extend()-搜索SO,您会发现很多示例.对于典型的init,您不需要深入的副本,因此浅拷贝算法就足够了.)

(If you are not using jQuery you can write your own object cloning method instead of using extend() - search SO and you will find many examples. You don't need a deep copy for a typical init so a shallow copy algorithm should suffice).

这篇关于动态获取TinyMCE设置(以将其应用到另一个init)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆