Is somebody already tried to integrate elFinder into new (4b1) version of TinyMCE? It looks like previous implementation isn't working. Please post some snippets, thanks a lot.
Ok. I found the solution:
tinymce.PluginManager.add("elfinder", function (editor, url) {
editor.settings.file_browser_callback = function (id, value, type, win) {
$('<div />').dialogelfinder({ url: url + '/php/connector.php', commandsOptions: { getfile: { oncomplete: 'destroy' } }, getFileCallback: function (url) { var fieldElm = win.document.getElementById(id); fieldElm.value = editor.convertURL(url, null, true); if ("fireEvent"in fieldElm) { fieldElm.fireEvent("onchange") } else { var evt = document.createEvent("HTMLEvents"); evt.initEvent("change", false, true); fieldElm.dispatchEvent(evt) } } });
}; }, ["elfinder/js"]);
I updated the Wiki, should work now when following the steps: https://github.com/Studio-42/elFinder/wiki/Integration-with-TinyMCE-4.x
Primary changes are that TinyMCE doesn't use the InlinePopup plugin any more, the callback is changed and instead of file_browser_callback : 'elFinderBrowser'
you have to remove the quotes:
In the TinyMCE init:
file_browser_callback : elFinderBrowser
Add the elFinderBrowser callback to your javascript:
function elFinderBrowser (field_name, url, type, win) {
tinymce.activeEditor.windowManager.open({
file: '/elfinder/elfinder.html',// use an absolute path!
title: 'elFinder 2.0',
width: 900,
height: 450,
resizable: 'yes'
}, {
setUrl: function (url) {
win.document.getElementById(field_name).value = url;
}
});
return false;
}
And finally modify/copy elfinder.html file to use the callback:
<!-- Include jQuery, jQuery UI, elFinder (REQUIRED) -->
<script type="text/javascript">
var FileBrowserDialogue = {
init: function() {
// Here goes your code for setting your custom things onLoad.
},
mySubmit: function (URL) {
// pass selected file path to TinyMCE
top.tinymce.activeEditor.windowManager.getParams().setUrl(URL);
// close popup window
top.tinymce.activeEditor.windowManager.close();
}
}
$().ready(function() {
var elf = $('#elfinder').elfinder({
// set your elFinder options here
url: 'php/connector.php', // connector URL
getFileCallback: function(file) { // editor callback
FileBrowserDialogue.mySubmit(file.url); // pass selected file path to TinyMCE
}
}).elfinder('instance');
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With