2014-08-29 46 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(); 
} 

}); 
相关问题