2012-12-10 68 views
4

好吧,这是杀了我。我已经写了一个WordPress插件,它为TinyMCE编辑器添加了一个自定义按钮,并且它的工作效果非常好,除了由按钮触发的选项弹出窗口与WP原生的类似弹出窗口不同之外...如何在WordPress中为自定义TinyMCE按钮指定href值?

具体来说,当您在WordPress中点击TinyMCE工具栏上方的添加媒体按钮时,添加媒体窗口会以一个不错的thickbox模式打开。它还加载在iframe,因为按钮的HTML获取输出被包裹在一个锚定标记与URL href的值:

<a href="http://.../wp-admin/media-upload.php?post_id=916&amp;TB_iframe=1&amp;width=640&amp;height=354" class="thickbox add_media" id="content-add_media" title="Add Media" onclick="return false;"> 

但是,当我的按钮的HTML获取输出,锚标记有“一个href值的javascript :;“:

<a role="button" id="content_companyinfo" href="javascript:;" class="mceButton mceButtonEnabled mce_companyinfo" onmousedown="return false;" onclick="return false;" aria-labelledby="content_companyinfo_voice" title="Insert company info fields" tabindex="-1"> 

这里是我的TinyMCE的编辑器插件代码:http://pastebin.com/kuQJRHJR

这里是添加媒体按钮的WP核心TinyMCE的编辑器插件:http://core.trac.wordpress.org/browser/trunk/wp-includes/js/tinymce/plugins/media/editor_plugin_src.js

TinyMCE addButton函数不允许您设置href值,而只是一个链接到使用addCommand创建的自定义命令函数的cmd值。

我试着在addButton函数的设置中将类'thickbox'添加到我的按钮中,但是在我的常规弹出窗口后面创建了thickbox模式的奇怪效果。

任何人都知道如何以正确的方式做到这一点?提前致谢!

回答

5
  1. 在你的插件的editor_plugin.js init功能添加这个功能:

    ed.onInit.add(function(ed, evt) { 
    // make that the interactions window will open in a thickbox by adding the button the right attributes 
         jQuery('#content_myInteractions').addClass('thickbox'); 
    }); 
    

    更改 “content_myInteractions” 你的按钮的ID。

  2. 在您的按钮的命令,使用tb_show()打开您在ThickBox想要的内容:我把我的ThickBox的内容从我进入到我的网页蒙山jQuery的底部的DIV

    tb_show('myInteractions', '#TB_inline?height=300&width=400&inlineId=interactions_wrapper'); 
    

(内联内容)。 您也可以使用iframe。 这可能有帮助thickbox.net

相关问题