2014-08-29 47 views
2

我想知道如何在tinymce可視化編輯器的彈出框中添加文件選擇器(默認的wordpress圖書館應該是完美的)。在可視化編輯器中添加wordpress文件選取器

此刻我有一個領域,我必須通過圖片的網址,如果我可以添加一個按鈕從我的圖書館中選擇一張圖片,那就太好了!

What I try to achieve

這裏是我迄今爲止

editor.addButton('thumbnail', { 
      title: 'Thumbnail', 
      image: url+'/../images/icon-thumbnail.png', 
      onclick: function() { 
       // Open window 
       editor.windowManager.open({ 
        title: 'Thumbnail', 
        width: 940, 
        height: 150, 
        body: [ 
    //I have to change this line---------> {type: 'textbox', name: 'url', label: 'Media URL'},<----- Is there an option to put a filepicker here ? 
         {type: 'textbox', name: 'caption', label: 'Caption'}, 
         {type: 'checkbox', name: 'lightbox', value: '1', label: 'Lightbox'} 
        ], 
        onsubmit: function(e) { 
         if(e.data.url==''){ 
          alert('you have to provide the media\'s URL'); 
          e.stopPropagation(); 
          e.preventDefault(); 
         }else{ 
          // Insert content when the window form is submitted 
          var shortCode = '[thumbnail url="'+e.data.url+'"'; 
          if(e.data.caption != ''){ 
           shortCode = shortCode+' caption="'+e.data.caption+'"'; 
          } 
          if(e.data.lightbox){ 
           shortCode = shortCode+' lightbox=true'; 
          } 
          shortCode = shortCode+' ]'; 
          editor.insertContent(shortCode); 
         } 
        } 
       }); 
      } 
     }); 
+0

這裏是你如何可以添加TinyMCE的自定義按鈕:http://www.tinymce.com/wiki。 php/API3:method.tinymce.Editor.addButton你所需要做的只是調整你的wordpress設置,關於tinymce init。 – bodi0 2014-08-29 14:11:01

+0

對不起,如果我不清楚,我已經有我的按鈕,它會渲染我的彈出窗口(圖片附加到我的問題)實際上,我只需要替換文件選擇器在該彈出文本字段 – 0x1gene 2014-08-29 14:18:56

回答

0

您可以閱讀this有用的文章,this也可能會有幫助。

我dont't想從文章的文本複製粘貼,但基本上你有你的主題functions.php文件,該文件將處理媒體對話框顯示創建自定義的PHP函數,然後包括它add_action()事件admin_print_scripts

最後一部分是裏面的一些使用JavaScript和上傳,像這樣:

jQuery(document).ready(function() { 

jQuery('#upload_image_button').click(function() { 
formfield = jQuery('#upload_image').attr('name'); 
tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true'); 
return false; 
}); 

window.send_to_editor = function(html) { 
imgurl = jQuery('img',html).attr('src'); 
jQuery('#upload_image').val(imgurl); 
tb_remove(); 
} 

}); 
相關問題