javascript - 自定义CKEditor链接插件

标签 javascript ckeditor dom-events wysiwyg

我正在编辑链接插件,以允许员工选择内部内容的链接。 我已成功向链接插件对话框添加另一个选项卡,其中包含带有 onKeyup 事件的文本输入。这个想法是,当他们输入时,它会在下面列出结果,他们可以在其中选择他们想要的链接。选择后,我将使用 url 和协议(protocol)更新信息选项卡。

这是现有链接插件中的我的代码部分:

....
....

//Should update info tab with value
function AddLink(txtLink)
{
    var dialog = this.getDialog();
    dialog.setValueOf('info', 'url', txtLink);
    dialog.setValueOf('info', 'protocol', ''); 
}

//called when the user types in the search box. currently just uses text for basic testing
var searchBoxChanged = function ()
{
    var dialog = this.getDialog();
    var href = $(this).attr('href');
    var txt = dialog.getValueOf('article', 'searchWords');
    $('#searchResults').html("<a href=\"JavaScript:AddLink('/Article/View/" + txt +      "')\">Test Title</a>");
}

....
....
{
     //Adds extra tab to the link plugin for custom link searching
     id: 'article',
     label: linkLang.article,
     title: linkLang.article,
     elements:
     [
         {
              type: 'text',
              id: 'searchWords',
              label: linkLang.articleSearch,
              style: 'height:40px',
              size: 29,
              onKeyUp: searchBoxChanged
          },
          {
              type: 'html',
              html: '<div id="searchResults">Please start tying to get results</div>'
          }
     ] 


}
....
....

目前我只是使用文本框中的一些基本静态数据。页面上创建的链接正常,但是单击它时出现错误:

CRIPT5009: 'AddLink' is undefined

任何人都可以阐明我哪里出了问题吗?

最佳答案

根据我的经验,[“x”未定义]错误通常意味着存在语法错误,或者通常是函数中的某些内容与您认为的不同。

可能,this.getDialog() 脱离了上下文,因此它不会返回任何内容。那么,dialog.setValueOf() 将不起作用。

关于javascript - 自定义CKEditor链接插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5698247/

相关文章:

javascript - 使用 val() 将变量附加到输入值

javascript - Discord JS - 如何对同一个嵌入做出多次 react ?

javascript - 清除 CKEditor 样式标签

javascript - Vue stopPropagation 不起作用 - child 到 parent

Javascript 触发两个事件 - onkeypress 和 onclick

javascript - 在 Firefox 无需重新启动的插件中,如何在新窗口打开时运行代码(监听窗口打开情况)?

css - 如何应用ckeditor css输出

ruby-on-rails - 如何使用Webkit或Selenium驱动程序填充来自 capybara 的ckeditor

javascript - 触发两个脚本 : one that loads data and another that manipulates styling? 的正确方法是什么

javascript - 如何用jest和vue-test-utils模拟上传文件进行测试