5

是否有人已经尝试将 elFinder 集成到新 (4b1) 版本的 TinyMCE 中?看起来以前的 实现不起作用。请发一些片段,非常感谢。

4

2 回答 2

7

好的。我找到了解决方案:

  1. 在名为 elfinder 的插件中创建文件夹。
  2. 下载最新的 elFinder并放入此文件夹 plugins/elfinder。
  3. 将插件“elfinder”添加到插件列表 (tinymce.init)。
  4. 将 js/elfinder.min.js 重命名为 js/plugin.min.js
  5. 在插件的根文件夹中创建文件 plugin.min.js (elfinder/plugin.min.js)
  6. 在里面插入下一个文本并保存:

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"]);

于 2013-04-15T18:38:23.447 回答
6

我更新了 Wiki,现在应该按照以下步骤工作:https ://github.com/Studio-42/elFinder/wiki/Integration-with-TinyMCE-4.x

主要的变化是 TinyMCE 不再使用 InlinePopup 插件,回调被改变,而不是file_browser_callback : 'elFinderBrowser'你必须删除引号:

在 TinyMCE 初始化中: file_browser_callback : elFinderBrowser

将 elFinderBrowser 回调添加到您的 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;
}

最后修改/复制 elfinder.html 文件以使用回调:

<!-- 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>
于 2013-08-26T14:51:30.400 回答