2016-02-13 122 views
0

我在我的web應用程序上使用Tinymce 4.0。但我真的不知道如何做到這一點:當用戶點擊瀏覽按鈕時,如何打開本地文件瀏覽器並從本地文件瀏覽器向對話窗口添加圖像URL?我有這個源代碼:Tinymce 4 file_browser_callback:打開本地文件瀏覽器的功能

file_browser_callback: function(field_name, url, type, win) {win.document.getElementById(field_name).value = ''; } 

但我不知道如何解決這個問題。我不需要特殊的文件瀏覽器,但可以打開本地文件瀏覽器

+0

是不是有一個插件,會做這個?我之前使用過HTML編輯器 - 我認爲最後一個是FKEditor - 並且有幾乎所有的插件。 – halfer

+0

TinyMCE作者爲此創建了一個插件 - [MoxieManager](http://www.moxiemanager.com/demos/tinymce.php),但它是一個付費的插件。 – jayarjo

回答

0

這裏從TinyMCE的文檔Basic Local File Picker演示片斷:不幸的是它似乎並沒有在這裏工作的StackOverflow的片段:

注。

tinymce.init({ 
 
    selector: '#editor', 
 
    plugins: 'image code', 
 
    toolbar: 'undo redo | link image | code', 
 
    // enable title field in the Image dialog 
 
    image_title: true, 
 
    // enable automatic uploads of images represented by blob or data URIs 
 
    automatic_uploads: true, 
 
    // URL of our upload handler (for more details check: https://www.tinymce.com/docs/configure/file-image-upload/#images_upload_url) 
 
    images_upload_url: 'postAcceptor.php', 
 
    // here we add custom filepicker only to Image dialog 
 
    file_picker_types: 'image', 
 
    // and here's our custom image picker 
 
    file_picker_callback: function(cb, value, meta) { 
 
    var input = document.createElement('input'); 
 
    input.setAttribute('type', 'file'); 
 
    input.setAttribute('accept', 'image/*'); 
 
    
 
    // Note: In modern browsers input[type="file"] is functional without 
 
    // even adding it to the DOM, but that might not be the case in some older 
 
    // or quirky browsers like IE, so you might want to add it to the DOM 
 
    // just in case, and visually hide it. And do not forget do remove it 
 
    // once you do not need it anymore. 
 

 
    input.onchange = function() { 
 
     var file = this.files[0]; 
 
     
 
     // Note: Now we need to register the blob in TinyMCEs image blob 
 
     // registry. In the next release this part hopefully won't be 
 
     // necessary, as we are looking to handle it internally. 
 
     var id = 'blobid' + (new Date()).getTime(); 
 
     var blobCache = tinymce.activeEditor.editorUpload.blobCache; 
 
     var blobInfo = blobCache.create(id, file); 
 
     blobCache.add(blobInfo); 
 
     
 
     // call the callback and populate the Title field with the file name 
 
     cb(blobInfo.blobUri(), { title: file.name }); 
 
    }; 
 
    
 
    input.click(); 
 
    } 
 
});
<script src="//cdn.tinymce.com/4/tinymce.js"></script> 
 
<textarea id="editor"></textarea>