如果点击tinymce工具栏中的按钮,如何监听,如果需要,可以防止默认功能

时间:2014-09-21 20:54:01

标签: image plugins tinymce

嗨,特别是我很难防止允许坑在文本中超过3张图片所以我想听听来自tinymce插件的按钮图像是点击然后我可以防止默认过程如果已经超过2张图片已经在文中,如果有人知道该怎么办?

我试过

tinymce.init({

setup : function(editor) {


editor.on('click', function(e) {
                    console.log(e);
});
}
});

但点击图片插件按钮

时没有任何评论

谢谢

1 个答案:

答案 0 :(得分:0)

为什么不创建自己的插件?

我在wordpress admin中使用了以下代码来分解上传媒体弹出窗口:

// Init tinyMCE
tinymce.init({
    editor_selector: 'nwac_editor_' + nextPlusSignId,
    mode: "specific_textareas",
    media_buttons: false,
    menubar: false,
    relative_urls: false,
    toolbar: 'undo redo formatselect bold italic alignleft aligncenter alignright alignjustify bullist numlist outdent indent plusimage',
    setup: function(editor) {
        editor.addButton('plusimage', {
            icon: 'image',
            tooltip: 'Insert/edit image',
            onclick: function() {

            // If the media frame already exists, reopen it.
            if (file_frame) {
                file_frame.open();
                return;
            }

            // Create the media frame.
            file_frame = wp.media.frames.file_frame = wp.media({
                title: 'Choose an image for the plus sign',
                button: {
                    text: 'Insert selected',
                },
                multiple: false // Set to true to allow multiple files to be selected
            });

            // When an image is selected, run a callback.
            file_frame.on('select', function() {
                // We set multiple to false so only get one image from the uploader
                attachment = file_frame.state().get('selection').first().toJSON();

                //console.log(attachment);

                editor.insertContent('<img src="' + attachment.url + '" data-mce-src="' + attachment.url + '" alt="' + attachment.alt + '">');

                return;
            });

            // Finally, open the modal
            file_frame.open();
            }
        });
    },
    content_css: nw.baseurl + '/skins/wordpress/wp-content.css',
    body_class: 'mce-content-body nwac_plus_signs_' + nextPlusSignId + '_template post-type-products post-status-publish mceContentBody webkit wp-editor wp-autoresize html4-captions has-focus',

});