TinyMCE4 file_picker_callback

发布于:
分类: Script Tagged

Code for TinyMCE:

tinymce.init({
    file_picker_callback: function (callback, value, meta) {
        myImagePicker(callback, value, meta);
    }
});
function myImagePicker(callback, value, meta) {
    tinymce.activeEditor.windowManager.open({
        title: 'Image Browser',
        url: '/media/browser/1?type=' + meta.filetype,
        width: 800,
        height: 550,
    },
        {
            oninsert: function (url, objVals) {
                callback(url, objVals);
            }
        });
};

Code for the Custom File Picker:

function mySubmit(url, objVals) {
    top.tinymce.activeEditor.windowManager.getParams().oninsert(url, objVals);
    top.tinymce.activeEditor.windowManager.close();
    return false;
}

file_picker_callback Example

file_picker_callback: function(callback, value, meta) {
    // Provide file and text for the link dialog
    if (meta.filetype == 'file') {
        callback('mypage.html', { text: 'My text' });
    }
    // Provide image and alt text for the image dialog 
    if (meta.filetype == 'image') {
        callback('myimage.jpg', { alt: 'My alt text' });
    }
    // Provide alternative source and posted for the media dialog 
    if (meta.filetype == 'media') {
        callback('movie.mp4', { source2: 'alt.ogg', poster: 'image.jpg' });
    }
}

 

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注