-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Integration with TinyMCE 4.x
Naoki Sawada edited this page Apr 9, 2017
·
27 revisions
In the TinyMCE init code, add the following line:
plugins: "image, link, media", // example
toolbar: "link image media", // example
file_picker_callback : elFinderBrowser
Then add the following function (change the elfinder_url
to the correct path on your system):
function elFinderBrowser (callback, value, meta) {
tinymce.activeEditor.windowManager.open({
file: '/elfinder/elfinder.html',// use an absolute path!
title: 'elFinder 2.0',
width: 900,
height: 450,
resizable: 'yes'
}, {
oninsert: function (file, elf) {
var url, reg, info;
// URL normalization
url = file.url;
reg = /\/[^/]+?\/\.\.\//;
while(url.match(reg)) {
url = url.replace(reg, '/');
}
// Make file info
info = file.name + ' (' + elf.formatSize(file.size) + ')';
// Provide file and text for the link dialog
if (meta.filetype == 'file') {
callback(url, {text: info, title: info});
}
// Provide image and alt text for the image dialog
if (meta.filetype == 'image') {
callback(url, {alt: info});
}
// Provide alternative source and posted for the media dialog
if (meta.filetype == 'media') {
callback(url);
}
}
});
return false;
}
Copy main.default.js
to main.mce.js
And edit a part opts = {...},
. Or dounload main.mce.js.
opts = {
getFileCallback : function(file, fm) {
// pass selected file data to TinyMCE
parent.tinymce.activeEditor.windowManager.getParams().oninsert(file, fm);
// close popup window
parent.tinymce.activeEditor.windowManager.close();
},
url : 'php/connector.minimal.php', // connector URL (REQUIRED)
lang: lang // auto detected language (optional)
},
Edit elfinder.html
a part main.default.cke.js
to main.mce.js
<script data-main="./main.mce.js" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.min.js"></script>