2012-04-04 86 views
1

我试图从jQuery的对话框通过一个URL回CKEditor的对话框如何从jQuery的对话框通过URL来CKEDITOR对话框

CKEditor和jQuery对话框都可以使用。

问题是我不知道如何将CKEditorFuncNum传递给服务器。 我跳入源代码并搜索'CKEditorFuncNum',并找到了访问此变量的方法。

现在我得到的错误:

Uncaught TypeError: Cannot call method 'getDialog' of undefined 


这是工作流程:

  • 通话CKEditor的对话框[OK]
  • 调用jQuery的功能,使一个Ajax请求[确定]
  • 与co调用jQuery对话框Ajax请求的ntent [OK]
  • 密切jQuery的对话,并通过URL回到CKEditor的对话框(URL字段)< - 这里的问题是


我改变了浏览按钮调用一个jQuery函数(jQuery的弹出)

... 
{ 
    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> 



调用window.parent.CKEDITOR。 tools.callFunction(...);导致以下错误:

Uncaught TypeError: Cannot call method 'getDialog' of undefined 


如何resove这个矛盾呢?

范围是否不正确?

我怎样才能掌握CKEditor对话框

如何使用jQuery对话框中的选定URL填充CKEditor对话框的URL字段?


我将不胜感激任何意见。谢谢。

回答

0

好吧,这里是我如何解决它:

传值回使用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); 
    } 
} 
... 


我做一个Ajax请求传递funcNumref,并selected_url。 (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); 
    }