我正试图将URL从jQuery对话框传递回CKEditor对话框。
CKEditor和jQuery对话框都可以工作。
问题是我不知道如何将CKEditorFuncNum传递到服务器
我深入到源代码中,搜索"CKEditorFuncNum",并找到了访问该变量的方法
现在我得到错误:
Uncaught TypeError: Cannot call method 'getDialog' of undefined
这是工作流程:
- 调用CKEditor对话框[OK]
- 调用发出ajax请求的jQuery函数[OK]
- 使用ajax请求的内容调用jQuery对话框[OK]
- 关闭jQuery对话框并将url传递回CKEditor对话框(url字段)<-这就是问题所在
我更改了浏览按钮以调用jQuery函数(jQuery Popup)
...
{
type : 'button',
id : 'browseInternal',
label : 'jQuery Popup',
onClick :function() {
var funcNum = this.getDialog().getParentEditor()._.filebrowserFn;
showJQueryPopUp(funcNum);
}
}
...
jQuery函数发出一个get请求,传递CKEditorFuncNum值如何访问CKEditorFuncNum值(见下文)
function showJQueryPopUp(funcNum) {
ajax_url = '../../../site_links?CKEditorFuncNum=' + funcNum;
$.get(ajax_url, function(data) {
$('#my_dialog_content').html(data);
$('#my_dialog').dialog('open');
});
};
ajax请求返回一个url列表和一些JavaScript代码:
<a href="#" onclick="modify_link('http://www.google.com'); return false;">
Google
</a>
<a href="#" onclick="modify_link('http://www.yahoo.com'); return false;">
Yahoo
</a>
<a href="#" onclick="modify_link('http://www.microsoft.com'); return false;">
Microsoft
</a>
<script type='text/javascript'>
function modify_link(url) {
window.parent.CKEDITOR.tools.callFunction(<%= @funcNum %>, url, '' );
}
</script>
正在调用windowparent.CKEDITOR.tools.callFunction(…)导致以下错误:
Uncaught TypeError: Cannot call method 'getDialog' of undefined
如何解决此冲突
范围不正确吗
如何获取CKEditor对话框
如何用jQuery对话框中选择的URL填充CKEditor对话框的URL字段
如果有任何建议,我将不胜感激。非常感谢。
好吧,下面是我如何解决的:
使用window.parent.CKEDITOR.tools.callFunction...);
将值传递回对话框对我来说不起作用。所以我寻找另一种方法将一些值传递回CKEditor对话框。
在调用jQuery对话框(showJQueryPopUp()
)之前,我定义了一个回调函数(ref
):
...
{
type : 'button',
id : 'browseInternal',
label : 'jQuery Popup',
onClick :function() {
var dialog = this.getDialog();
var selected_url = dialog.getContentElement('info', 'url').getValue();
var ref = CKEDITOR.tools.addFunction(
function(url)
{
dialog.getContentElement('info','url').setValue(url);
});
var funcNum = this.getDialog().getParentEditor()._.filebrowserFn;
var editor_name = this.getDialog().getParentEditor().name;
showJQueryPopUp(funcNum, editor_name, ref, selected_url);
}
}
...
我通过funcNum
、ref
和selected_url
发出ajax请求。(ref
只是一个数字)
function showJQueryPopUp(funcNum, editor_name, ref, selected_url) {
var ajax_url = '../../../site_links?CKEditorFuncNum=' + funcNum + '&ref=' + ref + '&selected_url=' + selected_url;
$.get(ajax_url, function(data) {
$('#my_dialog_content').html(data);
$('#my_dialog').dialog('open');
});
};
服务器端脚本提取参数并将其传递到视图(@ref):
<a href="#" onclick="modify_link('http://www.google.com'); return false;">
Google
</a>
<a href="#" onclick="modify_link('http://www.yahoo.com'); return false;">
Yahoo
</a>
<a href="#" onclick="modify_link('http://www.microsoft.com'); return false;">
Microsoft
</a>
<script type='text/javascript'>
function modify_link(url) {
CKEDITOR.tools.callFunction(<%= @ref %>, url);
}