使用Tinymce创建自定义弹出窗口

Cha*_*ala 5 html javascript jquery tinymce tinymce-4

以下是我的Tinymce textarea的代码

    tinymce.init({
        selector: "textarea",
        height : 350,
            plugins: [
                    "link image lists preview anchor"
            ],
        toolbar: " image bold italic | formatselect | undo redo | cut copy paste | bullist numlist | undo redo | link unlink dummyimg | preview",
        menubar: false,
        toolbar_items_size: 'small',
        setup : function(ed) {
        // Add a custom button
        ed.addButton('dummyimg', {
            title : 'Add image',
            image : 'resources/images/img.jpg',
            onclick : function() {
                if($('#imageupload').val()){
                  ed.focus();
                  ed.selection.setContent('<img src="<%=strWebhost%>/news_cms/resources/images/dummyimg.jpg" />');
                } else{
                  alert("Please select an image.");
                }

                }
            });
        },
        onchange_callback: function(editor) {
            tinyMCE.triggerSave();
            $("#" + editor.id).valid();
        }
   });
Run Code Online (Sandbox Code Playgroud)

我添加了一个自定义按钮dummyimg,用于将预定义图像添加到tinymce容器中.我的要求是,我需要一个如下所示的弹出窗口,这使我只能title使用自定义按钮添加图像.

在此输入图像描述

提前致谢.

Ezr*_*ree 8

这个例子应该让你开始:

tinymce.init({
    selector:'textarea.editor',
    menubar : false,
    statusbar : false,
    toolbar: "dummyimg | bold italic underline strikethrough | formatselect | fontsizeselect | bullist numlist | outdent indent blockquote | link image | cut copy paste | undo redo | code",
    plugins : 'advlist autolink link image lists charmap print preview code',
    setup : function(ed) {
        ed.addButton('dummyimg', {
            title : 'Edit Image',
            image : 'img/example.gif',
            onclick : function() {
                ed.windowManager.open({
                    title: 'Edit image',
                    body: [
                        {type: 'textbox', name: 'source', label: 'Source'}
                    ],
                    onsubmit: function(e) {    
                        ed.focus();
                        ed.selection.setContent('<pre class="language-' + e.data.language + ' line-numbers"><code>' + ed.selection.getContent() + '</code></pre>');
                    }
                });
            }
        });
    }
});
Run Code Online (Sandbox Code Playgroud)

显然,您需要编辑该ed.selection.setContentonsubmit以满足您自己的需要,以及设置正确toolbarplugins设置.

  • 文档不是很有用,所以我继续编写了一篇文章,列出了可用的不同小部件和容器布局:http://makina-corpus.com/blog/metier/2016/how-to-create-a-custom - 对话功能于TinyMCE的-4- (2认同)