1

例如,如果我有一个现成的 CKEDITOR 实例,并且在同一页面上我有一个图片列表,带有以下标记:

<div class="galleryPictures">
    <a href="#image-id-1" data-id="1" data-img-src="/pictures/image-1.jpg" class="galleryPicture">
        <img src="/pictures/image-1.jpg" />
    </a>
    <a href="#image-id-2" data-id="2" data-img-src="/pictures/image-2.jpg" class="galleryPicture">
        <img src="/pictures/image-2.jpg" />
    </a>
    <a href="#image-id-3" data-id="3" data-img-src="/pictures/image-3.jpg" class="galleryPicture">
        <img src="/pictures/image-3.jpg" />
    </a>
</div>

我有以下委托给这些a.galleryPicture项目的jQuery点击处理程序:

$(document).ready(function() {
    $('.galleryPictures').on('click', 'a.galleryPicture', function() {
        // when this accours I would like to open CKEditor's
        // Insert-Image Component, and to get the "url" field filled with
        // $(this).data('img-src'); value
    });
});

是否可以以编程方式触发/打开插入图像?

4

1 回答 1

1

找到了。可能对其他人有帮助:

通过对 Firebug 的简单检查,我发现<a>单击时触发 Insert-Image 组件的打开在其onclick属性中包含此函数调用:

CKEDITOR.tools.callFunction(51,{});
// second argument is {} (an empty js-object), it the original the <a> onclick it was like this:
// CKEDITOR.tools.callFunction(51, this); meaning it was sending the instance of that element

在此调用之后,可以执行以下操作:

CKEDITOR.tools.callFunction(51,{});

// a failsafe if jQuery doesn't find the specified element after the function is executed
setTimeout(function() {
    $('#cke_69_textInput').val('someImageUrl');
}, 50);
于 2013-02-27T13:05:53.377 回答