jQuery TinyMCE 路径,如何指定加载诸如 editor_plugin.js 之类的内容的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4412589/
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-26 17:14:52  来源:igfitidea点击:

TinyMCE Paths, How to specify where to load things like editor_plugin.js

jquerytinymcegoogle-closure

提问by AnApprentice

I installed TinyMCE, everything was working great. I then used Google Closure to package my site's JavaScript along with TinyMCE_src

我安装了 TinyMCE,一切都很好。然后我使用 Google Closure 将我网站的 JavaScript 与 TinyMCE_src 打包在一起

The problem I'm having is that TinyMCE is now making calls to:

我遇到的问题是 TinyMCE 现在正在调用:

plugins/paste/editor_plugin.js
themes/advanced/editor_template.js
langs/en.js

And that paths that are being used are invalid, they are 404'ing

并且正在使用的路径无效,它们是 404'ing

How can I tell TinyMCE where to go to get these files?

我如何告诉 TinyMCE 去哪里获取这些文件?

I tried:

我试过:

relative_urls : false,
document_base_url : "http://www.site.com/path1/",

But they have no effect on the files above.

但它们对上面的文件没有影响。

Advise? Thanks

建议?谢谢

回答by Rakesh

I had the same issue, and it could have been solved easily if we were able to specify the base urlusing the document_base_url.

我遇到了同样的问题,如果我们能够使用document_base_url指定基本 url,它可以很容易地解决。

Alternatively, I was able to specify the base url before initializing tinymce.

或者,我可以在初始化 tinymce 之前指定基本 url。

tinyMCE.baseURL = "URL_TO/tinymce/jscripts/tiny_mce/";// trailing slash important

tinyMCE.init({
        mode : "textareas",
        theme : "simple"
});

TinyMCE is working fine now.

TinyMCE 现在工作正常。

回答by Stefaan Colman

You can override the base url for tinyMCE by placing the following code before initializing tinyMCE.

您可以通过在初始化 tinyMCE 之前放置以下代码来覆盖 tinyMCE 的基本 url。

var tinyMCEPreInit = {
    suffix: '',
    base: '/tinymce/',
    query: ''
};

This is usefull if you already loaded tinyMCE from a merged source and the base path isn't correctly found.

如果您已经从合并的源加载了 tinyMCE 并且未正确找到基本路径,这将非常有用。

回答by Chaki_Black

According this: http://www.tinymce.com/wiki.php/Configuration:theme_url

根据这个:http: //www.tinymce.com/wiki.php/Configuration: theme_url

tinymce.init({
   ...
   theme_url: (document.location.pathname + '/js/tinymce/themes/modern/theme.js').replace("\/\/", "\/"),
   skin_url:  (document.location.pathname + '/js/tinymce/skins/lightgray/').replace("\/\/", "\/"),
   ...

But, need to be carefull with paths. With help document.location.pathnameI've got project root directory. Replace function need for replacing double slash with single slash, because different server can return "...//server/site" OR "...//server/site/" and it can be: "...//server/site/js..." OR "...//server/site//js...".

但是,需要小心路径。在帮助下,document.location.pathname我获得了项目根目录。替换函数需要用单斜线替换双斜线,因为不同的服务器可以返回“...//server/site”或“...//server/site/”,它可以是:“...//server” /site/js...”或“...//server/site//js...”。

回答by DarthJDG

If you're using the TinyMCE jQuery plugin, you can load everything from a remote location, just add the script_urlparameter into your init code. It will load everything from there, including any scripts/images/etc.

如果您使用 TinyMCE jQuery 插件,则可以从远程位置加载所有内容,只需将script_url参数添加到您的初始化代码中即可。它将从那里加载所有内容,包括任何脚本/图像/等。

$('textarea').tinymce({
    script_url: 'http://tinymce.moxiecode.com/js/tinymce/jscripts/tiny_mce/tiny_mce.js'
});

Check out this fiddle, it's including the whole thing remotely from the TinyMCE website: http://jsfiddle.net/xgPzS/22/

看看这个小提琴,它包括从 TinyMCE 网站远程的整个事情:http: //jsfiddle.net/xgPzS/22/

回答by Adnan

As per TinyMCE 4.x documentation you can specify the document base url during init.

根据 TinyMCE 4.x 文档,您可以在初始化期间指定文档基础 url。

tinymce.init({
        document_base_url: "http://www.example.com/path1/"
});

if you are using CodeIgniter, simply use base_url()

如果您使用的是 CodeIgniter,只需使用 base_url()

tinymce.init({
        document_base_url: "<?php echo base_url() ?>"
});

Remember: relative_urlmust be truein order to work it perfectly otherwise you will get absolute URLS.

请记住:relative_url必须为true才能完美运行,否则您将获得绝对 URL。

For more details: http://www.tinymce.com/wiki.php/Configuration:document_base_url

更多详情:http: //www.tinymce.com/wiki.php/Configuration: document_base_url

回答by cleison

Bundle everything using grunt (instructions on github) then you will just have to configure from where to load all the css using the option skin_url

使用 grunt(github 上的说明)捆绑所有内容,然后您只需使用选项配置从何处加载所有 cssskin_url

tinymce.init({skin_url: window.location.origin + '/css/tinymce'})