最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Dynamically loading TinyMCE - wrong plugin, theme paths - Stack Overflow

programmeradmin8浏览0评论

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. 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. I'm using 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. How can I get it to reference the correct path to the theme and plugins?

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. 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. I'm using 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. How can I get it to reference the correct path to the theme and plugins?

Share Improve this question edited Dec 3, 2014 at 15:20 InbetweenWeekends asked Dec 3, 2014 at 13:59 InbetweenWeekendsInbetweenWeekends 1,4143 gold badges23 silver badges31 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 23

Add tinymce.suffix = '.min'; before invoking tinymce.init()

The only solution I could e up with is to copy and rename the theme.min.js, and plugin.min.js files to theme.js and plugin.js and publish those along with the minified versions.

Best solution is to include plugins in html in <script> tag.

Then use some lib to pack those files into one to reduce number of requests to serwer for example for Symfony2 (in twig template):

{% 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>
发布评论

评论列表(0)

  1. 暂无评论