[英]Dynamically loading TinyMCE - wrong plugin, theme paths
When I add the script tag <script src="../Scripts/tinymce.min.js"></script>
to my page, TinyMCE loads fine - with plugins and theme referencing the .min versions. 当我将脚本标记<script src="../Scripts/tinymce.min.js"></script>
到我的页面时,TinyMCE加载正常 - 插件和主题引用.min版本。 However, when I remove the script tag and try loading it with jQuery, it's referencing the non-minified version, as noted in the console log. 但是,当我删除脚本标记并尝试使用jQuery加载它时,它会引用非缩小版本,如控制台日志中所述。 I'm using TinyMCE v4.1.7 (2014-11-27) 我正在使用TinyMCE v4.1.7(2014-11-27)
$.getScript('http://localhost:52417/Scripts/tinymce.min.js', function () {
window.tinymce.dom.Event.domLoaded = true;
tinymce.baseURL = 'http://localhost:52417/Scripts';
tinymce.init({
selector: '#announcementText',
plugins: ['link image'],
toolbar: 'undo redo | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist | outdent indent | link image',
menubar: false,
statusbar: false
});
});
GET http://localhost:52417/Scripts/themes/modern/theme.js 404 (Not Found) GET http://localhost:52417/Scripts/plugins/link/plugin.js 404 (Not Found) GET http://localhost:52417/Scripts/plugins/image/plugin.js 404 (Not Found)
The domLoaded and baseURL lines were found from other examples on SO, and didn't make a difference. domLoaded和baseURL行是从SO上的其他示例中找到的,并没有产生任何影响。 How can I get it to reference the correct path to the theme and plugins? 如何让它引用主题和插件的正确路径?
Add tinymce.suffix = '.min';
添加tinymce.suffix = '.min';
before invoking tinymce.init()
在调用tinymce.init()
之前
我能想到的唯一解决方案是将theme.min.js和plugin.min.js文件复制并重命名为theme.js和plugin.js,并将其与缩小版本一起发布。
Best solution is to include plugins in html in <script>
tag. 最佳解决方案是在<script>
标记中包含html中的插件。
Then use some lib to pack those files into one to reduce number of requests to serwer for example for Symfony2 (in twig template): 然后使用一些lib将这些文件打包成一个以减少对serwer的请求数量, 例如Symfony2 (在twig模板中):
{% javascripts output='js/tinymce_plugins.js' filter='?uglifyjs2'
'@BrokerStarCommonBundle/Resources/public/js/tinymce/themes/modern/theme.min.js'
'@BrokerStarCommonBundle/Resources/public/js/tinymce/plugins/advlist/plugin.min.js'
'@BrokerStarCommonBundle/Resources/public/js/tinymce/plugins/autolink/plugin.min.js'
.............
'@BrokerStarCommonBundle/Resources/public/js/tinymce/plugins/textpattern/plugin.min.js'
'@BrokerStarCommonBundle/Resources/public/js/tinymce/plugins/tabbutton/plugin.min.js'
'@BrokerStarCommonBundle/Resources/public/js/tinymce/plugins/checkboxes/plugin.min.js'
'@BrokerStarCommonBundle/Resources/public/js/tinymce/plugins/noneditable/plugin.min.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
<script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.