[英]How do I assign an href value to a custom TinyMCE button in WordPress?
Okay, this is killing me. 好的,这是在扼杀我。 I've written a WordPress plugin that adds a custom button to the TinyMCE editor and it works great, except that the options pop-up window triggered by the button loads differently than similar popup windows that are native to WP...
我写了一个WordPress插件,它为TinyMCE编辑器添加了一个自定义按钮,它工作得很好,除了由按钮触发的选项弹出窗口加载不同于WP原生的类似弹出窗口...
Specifically, when you click the Add Media button above the TinyMCE toolbar in WordPress, the Add Media window opens up in a nice thickbox modal. 具体来说,当您单击WordPress中TinyMCE工具栏上方的“添加媒体”按钮时,“添加媒体”窗口将以精美的厚箱模式打开。 It also loads in an iframe, because the button HTML that gets output is wrapped in an anchor tag with a URL href value:
它也会加载到iframe中,因为获取输出的按钮HTML包含在一个带有URL href值的锚标记中:
<a href="http://.../wp-admin/media-upload.php?post_id=916&TB_iframe=1&width=640&height=354" class="thickbox add_media" id="content-add_media" title="Add Media" onclick="return false;">
But when my button's HTML gets output, the anchor tag has an href value of 'javascript:;': 但是当我的按钮的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">
Here is my TinyMCE editor plugin code: http://pastebin.com/kuQJRHJR 这是我的TinyMCE编辑器插件代码: http : //pastebin.com/kuQJRHJR
And here is the WP core TinyMCE editor plugin for the Add Media button: http://core.trac.wordpress.org/browser/trunk/wp-includes/js/tinymce/plugins/media/editor_plugin_src.js 以下是添加媒体按钮的WP核心TinyMCE编辑器插件: http : //core.trac.wordpress.org/browser/trunk/wp-includes/js/tinymce/plugins/media/editor_plugin_src.js
The TinyMCE addButton function doesn't allow you to set an href value, only a cmd value that links to a custom command function, which you create using addCommand. TinyMCE addButton函数不允许您设置href值,只允许链接到使用addCommand创建的自定义命令函数的cmd值。
I tried just adding the class 'thickbox' to my button in the settings of the addButton function, but that had a weird effect of creating a thickbox modal behind my normal pop-up window. 我尝试在addButton函数的设置中将类“thickbox”添加到我的按钮,但这有一个奇怪的效果,即在我的普通弹出窗口后面创建一个厚盒模式。
Anyone know how to do this the right way? 任何人都知道如何以正确的方式做到这一点? Thanks in advance!
提前致谢!
In your plugin's editor_plugin.js init
function add this function: 在你的插件的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'); });
Change "content_myInteractions" to your button id. 将“content_myInteractions”更改为您的按钮ID。
In your button's command, use tb_show()
to open the content you want in a thickbox: 在按钮的命令中,使用
tb_show()
在thickbox中打开所需的内容:
tb_show('myInteractions', '#TB_inline?height=300&width=400&inlineId=interactions_wrapper');
I took my thickbox content from a div I entered to the bottom of my page whith jQuery (inline content). 我从我输入到jQuery(内联内容)页面底部的div中获取了我的thickbox内容。 You can also use an iframe.
您也可以使用iframe。 This might help thickbox.net
这可能对thickbox.net有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.