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.
Asked
Active
Viewed 1.2k times
2 Answers
7
Ok. I found the solution:
- Create folder in plugins named elfinder.
- Download latest elFinder and put into this folder plugins/elfinder.
- Add plugin 'elfinder' to the list of plugins (tinymce.init).
- Rename js/elfinder.min.js to js/plugin.min.js
- Create file plugin.min.js in root folder of plugin (elfinder/plugin.min.js)
- Insert next text inside and save:
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"]);

dikirill
- 1,873
- 1
- 19
- 21
-
You did everything like I said? – dikirill May 15 '13 at 21:03
-
@dikirill can this be used on rails 2? I'm getting an error `Cannot call method 'dialogelfinder' of null` browser console – Nithin Feb 04 '14 at 11:16
6
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>

Barryvdh
- 6,419
- 2
- 26
- 23
-
The link to documentation at the beginning of the post has the correct code. At least the code from there worked for me! – 6bytes Mar 09 '14 at 18:43
-