我试图upgradeTinyMCE 版本 4 起to ver.5,但函数 file_browser_callback 已被替换为文件选择器回调具有完全不同的参数:
TinyMCE v.4
file_browser_callback: function (fieldId, value, type, win) {
browseFiles(value, type, function (fileUrl) {
win.document.getElementById(fieldId).value = fileUrl;
});
}
TinyMCE v.5
file_picker_callback: function (callback, value, meta) {
browseFiles(value, meta.filetype, function (fileUrl) {
callback(fileUrl);
});
}
我只能检索旧参数type第 5 节中的内容是元文件类型, but 不是其他参数, 字段名称 and win,对于 Roxy Fileman 来说是必要的。
这是我使用 v.4 的完整实现:
function initEditor(selector) {
tinymce.init({
selector: selector,
plugins: "paste,link,lists,advlist,image,table,contextmenu,media,fullscreen",
paste_as_text: true,
menubar: false,
language: 'en',
forced_root_block: 'div',
encoding: 'xml', //used to solve Dangerous Request.Form exception - Seems it's not enough alone.
block_formats: 'Paragraph=p;Header 1=h1;Header 2=h2;Header 3=h3',
toolbar: 'undo redo | styleselect | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | bullist numlist | link unlink | image | media | fullscreen',
file_browser_callback: RoxyFileBrowser,
inline: false,
setup: function (editor) {
editor.on('change', function (e) {
//saved = false;
//$("#btn-save").css('border', '2px solid #D85145');
//$("#btn-save").html('SAVE');
});
}
});
}
function RoxyFileBrowser(field_name, url, type, win) {
var cmsURL = roxyFileman; // script URL - use an absolute path!
if (cmsURL.indexOf("?") < 0) {
cmsURL = cmsURL + "?type=" + type;
}
else {
cmsURL = cmsURL + "&type=" + type;
}
cmsURL += '&input=' + field_name + '&value=' + win.document.getElementById(field_name).value;
tinyMCE.activeEditor.windowManager.open({
file: cmsURL,
title: 'MVAM - Media File Repository',
width: 850, // Your dimensions may differ - toy around with them!
height: 650,
resizable: "yes",
plugins: "media",
inline: "yes", // This parameter only has an effect if you use the inlinepopups plugin!
close_previous: "no"
}, {
window: win,
input: field_name
});
return false;
}