我需要返回我在jQuery UI对话框中选择的值。
目前,我只是像这样设置值:
jQuery('#fileBrowser input.addImage').live("click", function() {
// 'file' is set when selected in file browser
imageUrlInputBox.val(file); // Add relative image url to text field
jQuery("#fileBrowser").dialog("close");
});然而,我现在面临的问题是,我通过TinyMCE中的自定义按钮打开对话框。所以我需要另一种插入图像的方法。这就是我想出来的:
// This is the function valled when clicking the tinyMCE button
function openImageManager(ed) {
//tinymce is a global variable.
tinymce = ed;
jQuery("#fileBrowser").dialog("open");
}该函数接收从tinyMCE插件传递的“ed”变量。下面是这方面的脚本:
(function() {
tinymce.create('tinymce.plugins.wp_filebrowser_plugin', {
init : function(ed, url){
ed.addButton('wp_filebrowser_plugin', {
title : 'Insert image',
onclick : function() {
openImageManager(ed)
},
image: url + "/img/wand.png"
});
},
getInfo : function() {
return {
longname : 'WP Filebrowser TinyMCE plugin',
};
}
});
tinymce.PluginManager.add('wp_filebrowser_plugin', tinymce.plugins.wp_filebrowser_plugin);
})();现在,单击“插入”按钮时,可以执行以下代码将数据插入到文本编辑器中:
jQuery('#fileBrowser input.addImage').live("click", function() {
var img_html = '<img class="' + css_class + '" src="' + file_url + '" title="' + alt + '" alt="" />';
tinymce.execCommand('mceInsertContent', false, img_html);
});溶液
谢谢T.J.克劳德我找到了答案。对代码进行更新以反映这一点。
发布于 2010-11-28 13:41:26
你不能这样做:
function openImageManager() {
img_html = jQuery("#fileBrowser").dialog("open"); // I need some sort of callback here
return img_html;
}...because对话与用户之间的交互需要异步到openImageManager调用,在等待UI事件(如用户做某事)发生时,无法将openImageManager函数“搁置”。
您需要做的是显示对话框,然后在其他地方处理关闭它并将图像粘贴到TinyMCE中(例如,通过execCommand发送mceImage命令)。不能将它作为openImageManager函数的返回值。
https://stackoverflow.com/questions/4296985
复制相似问题