如何使用TinyMCE自定义按钮,带有自定义对话框,添加内容?

发布于 2024-08-20 02:38:35 字数 978 浏览 1 评论 0原文

TinyMCE 编辑器允许您将自定义按钮分配到其编辑器工具栏。我这样做了并将其连接到 Flickr 帐户,因此会出现一个包含图像选择的自定义对话框。

我希望用户能够单击任何图像,并将该图像的 URL 添加到单击自定义 TinyMCE 按钮的原始输入中。

这是我拥有的 TinyMCE 自定义按钮代码:

setup : function(ed) {
    // Add a custom button
    ed.addButton('flickr', {
        title : 'Add Flickr Image',
        image : 'styles/media_icons/flickr.png',
        onclick : function() {
            // Add your own code to execute something on click

            $("div.mediaLibraryPopup .box").load("scripts/loadMediaLibrary.php");
            $("div.mediaLibraryPopup").fadeIn("slow").addClass(container);

        }
    });
}

然后,当您单击图像时,我有这个 jQuery 来处理该事件:

$("div.mediaLibraryPopup img").live("click", function() {
    var url = $(this).attr("src");
    $("div.mediaLibraryPopup").fadeOut("slow");
});

我已经阅读 TinyMCE 文档并使用它几个小时了,但我无法弄清楚如何将该 URL 变量传递回 TinyMCE“ed”事件,以便它可以将其添加到输入中。

由于我将在多个输入上使用它,所以我也不能只对输入类进行硬编码。有什么想法吗?

TinyMCE editor lets you assign a custom button to its editor toolbar. I did that and hooked it up to a Flickr account, so a custom dialog box appears with a selection of images.

I want the user to be able to then click any image and have the URL of that image added to the original input, from where the custom TinyMCE button was clicked.

This is the TinyMCE custom button code I have:

setup : function(ed) {
    // Add a custom button
    ed.addButton('flickr', {
        title : 'Add Flickr Image',
        image : 'styles/media_icons/flickr.png',
        onclick : function() {
            // Add your own code to execute something on click

            $("div.mediaLibraryPopup .box").load("scripts/loadMediaLibrary.php");
            $("div.mediaLibraryPopup").fadeIn("slow").addClass(container);

        }
    });
}

Then, when you click on an image, I have this jQuery to handle that event:

$("div.mediaLibraryPopup img").live("click", function() {
    var url = $(this).attr("src");
    $("div.mediaLibraryPopup").fadeOut("slow");
});

I've been reading the TinyMCE documentation and working with it for hours, and I can't figure out how to pass that URL variable back to the TinyMCE "ed" event so that it can add it to the input.

Since I'll be using this on multiple inputs, I can't just hard-code the input class, either. Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱桃奶球 2024-08-27 02:38:35

我认为您需要在编辑器中的当前光标位置插入 URL。如果是这种情况,那么您可以使用此命令插入内容:

tinyMCE.execCommand('mceInsertContent',false,'Your Content Goes Here...');

希望这有帮助:)

I think you need to insert The URL on the Current Cursor Location in the Editor. if that is the case then you can use this command to insert the content:

tinyMCE.execCommand('mceInsertContent',false,'Your Content Goes Here...');

Hope this helps :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文