我如何使用 TinyMCE jQuery 包以及与 TinyMCE jQuery 插件有什么区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21434388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 01:34:19  来源:igfitidea点击:

How do i use TinyMCE jQuery package and what is the difference with TinyMCE jQuery plugin

jquerytinymcetinymce-4

提问by Andy

I've seen this post What is the TinyMCE jQuery Package?which explains what the v4 TinyMCE jQuery package is but the post and the tinymce site only contain examples of v3.

我看过这篇文章TinyMCE jQuery 包是什么?它解释了 v4 TinyMCE jQuery 包是什么,但帖子和 tinymce 站点仅包含 v3 的示例。

When I download the v4 TinyMCE jQuery package there is no tiny_mce.js; there seems to be two files jquery.tinymce.min.js and tinymce.min.js. I've read that if I include both files then I am using full TinyMCE and not the jQuery version, but if I only include the jQuery file, my call to tinyMCE.init fails with "tinyMCE is not defined".

当我下载 v4 TinyMCE jQuery 包时,没有 tiny_mce.js;似乎有两个文件 jquery.tinymce.min.js 和 tinymce.min.js。我读过,如果我包含两个文件,那么我使用的是完整的 TinyMCE 而不是 jQuery 版本,但如果我只包含 jQuery 文件,我对 tinyMCE.init 的调用将失败,并显示“tinyMCE 未定义”。

I'd really rather be figuring this out from the documentation, but I've tried to search it and can't find anything about the jQuery version.

我真的宁愿从文档中弄清楚这一点,但我试图搜索它并且找不到任何关于 jQuery 版本的信息。

On a related point can anyone explain what the TinyMCE jQuery plugin is and how it relates to the above? I think that may be the gap in my understanding.

在相关方面,谁能解释一下 TinyMCE jQuery 插件是什么以及它与上述内容有何关系?我想这可能是我理解上的差距。

Thanks very much in advance

首先十分感谢

回答by 2potatocakes

I ran into the same issue a few weeks back. You don't need to use tinymce as a jQuery plugin but the option is there if you would like to. The vast majority of the tinymce source code is in the tinymce.min.js file and the jQuery.tinymce.min file just contains the code that wraps the tinymce functionality into a jQuery plugin. Anyways, if you want to use it you'll need to require both.

几周前我遇到了同样的问题。您不需要将 tinymce 用作 jQuery 插件,但如果您愿意,可以选择使用。tinymce 的大部分源代码都在 tinymce.min.js 文件中,而 jQuery.tinymce.min 文件只包含将 tinymce 功能包装到 jQuery 插件中的代码。无论如何,如果你想使用它,你需要两者都需要。

<script src="/js/jquery-1.10.2.js" type="text/javascript"></script>
<script src="/js/tinymce/tinymce.min.js" type="text/javascript"></script>
<script src="/js/tinymce/jquery.tinymce.min.js" type="text/javascript"></script>

The only main difference as far as I know in terms of TinyMCE is the way the editor is initialised. If you're not using jQuery you'd initialise it something like this:

据我所知,在 TinyMCE 方面唯一的主要区别是编辑器的初始化方式。如果你不使用 jQuery,你会像这样初始化它:

tinymce.init({
    selector: 'textarea',
    theme: "modern"
    ...
}) 

Whereas when you're using it as a jQuery plugin you can use jQuery to initialise it and you get the added benefit of being able to chain additional jQuery goodness onto your initialisation method. As in:

而当您将它用作 jQuery 插件时,您可以使用 jQuery 对其进行初始化,并且可以获得额外的好处,即能够将额外的 jQuery 优点链接到您的初始化方法上。如:

$('textarea').html('<p>some dynamic content</p>').tinymce({
   theme: "modern",
   ...
})

Other than that they're basically the same I think.

除此之外,我认为它们基本相同。

回答by Thariama

The tinymce jQuery version enables a developer to use jQuery commands concerning the tinymce editor. I strongly advise anyone who listens not to use the jQuery build of tinymce and stick with the regular tinymce version. The reason for this is easy: the overhead of creating additional objects and elements using the jQuery version does not weight out the benefits. In case of using own tinymce plugins with several keyevent handlers i found out that the jQuery tinymce version took a long time to process many fast keyboard strokes (resulting in a delay of the appearance of letters in the editor). The way to go here is to use the regular tinymce build and load the regular jQuery on the main document as well. Accessing tinymce and adressing html elements using jQuery is then possible.

tinymce jQuery 版本使开发人员能够使用有关 tinymce 编辑器的 jQuery 命令。我强烈建议任何倾听的人不要使用 tinymce 的 jQuery 版本并坚持使用常规的 tinymce 版本。原因很简单:使用 jQuery 版本创建额外对象和元素的开销并没有抵消好处。如果使用自己的 tinymce 插件和几个 keyevent 处理程序,我发现 jQuery tinymce 版本需要很长时间来处理许多快速键盘敲击(导致编辑器中字母出现的延迟)。去这里的方法是使用常规的 tinymce 构建并在主文档上加载常规的 jQuery。然后就可以使用 jQuery 访问 tinymce 和寻址 html 元素。

回答by Gone Coding

Given the confusion over the jQuery "version" vs. jQuery "plugin", I though I would investigate as I am adding TinyMCE to an MVC jQuery project at the moment.

鉴于对 jQuery“版本”与 jQuery“插件”的混淆,我虽然我会调查,因为我目前正在将 TinyMCE 添加到 MVC jQuery 项目中。

I installed the raw TinyMCE NuGet package from Exphox (raw JS version) in one project and the TinyMCE.jQuery NuGet package in another project.

我在一个项目中安装了来自 Exphox(原始 JS 版本)的原始 TinyMCE NuGet 包,在另一个项目中安装了 TinyMCE.jQuery NuGet 包。

I then compared folders, files, size etc with Araxis Merge, and then "prettified" the minified source code to examine the contents.

然后我将文件夹、文件、大小等与 Araxis Merge 进行比较,然后“美化”缩小的源代码以检查内容。

Here are the NuGet results:

以下是 NuGet 结果:

The NuGet packages are identicalwith the exception of the single jquery.tinymce.min.jsfile, which was added to the TinyMCE.jQuery NuGet package.

除了jquery.tinymce.min.js添加到 TinyMCE.jQuery NuGet 包的单个文件之外,NuGet 包是相同的。

The jQuery file is just a straight-forward plugin to apply the MCE to jQuery elements!

jQuery 文件只是一个将 MCE 应用到 jQuery 元素的直接插件!

So, as far as the NuGet packages go, the jQuery version is nothing but a plugin implementing TinyMCE on jQuery elements. Nothing else!

因此,就 NuGet 包而言,jQuery 版本只不过是一个在 jQuery 元素上实现 TinyMCE 的插件。没有其他的!

This goes against the comments found here http://www.tinymce.com/tryit/3_x/jquery_version.phpthat state:

这与此处http://www.tinymce.com/tryit/3_x/jquery_version.php中的评论背道而驰:

This example loads a specific jQuery version of TinyMCE this version is a bit smaller since it doesn't include some redundant logic such as the Sizzle engine.

此示例加载了 TinyMCE 的特定 jQuery 版本,此版本较小,因为它不包含一些冗余逻辑,例如 Sizzle 引擎。