在插入/编辑链接对话框中插入自定义按钮?

问题描述 投票:3回答:1

我想在tinymce v5的Insert / Edit Link对话框/弹出窗口中添加一个自定义按钮。

我只有安装选项的代码,我调用了一个函数。

function tinyMceEditLink(editor) {
    console.log("tinyMceEditLink");

    editor.on("click", function(e) {
        console.log("this click");
    });
}
tinymce tinymce-5
1个回答
1
投票

我会第一个承认这有点hacky,但你可以尝试:

function tinyMceEditLink(editor) {
    editor.windowManager.oldOpen = editor.windowManager.open;  // save for later
    editor.windowManager.open = function (t, r) {    // replace with our own function
        var modal = this.oldOpen.apply(this, [t, r]);  // call original

        if (t.title === "Insert/Edit Link") {
            $('.tox-dialog__footer-end').append(
                '<button title="Custom button" type="button" data-alloy-tabstop="true" tabindex="-1" class="tox-button" id="custom_button">Custom button</button>'
            );

            $('#custom_button').on('click', function () {
                //Replace this with your custom function
                console.log('Running custom function')
            });
        }

        return modal; // Template plugin is dependent on this return value
    };
}

这将给您以下结果:

enter image description here

建立:

tinymce.init({
      selector: "#mytextarea",  // change this value according to your HTML
      plugins: "link",
      menubar: "insert",
      toolbar: "link",
      setup: function(editor) {
        // Register our custom button callback function
        editor.on('init',function(e) {
            tinyMceEditLink(editor);
        });

        // Register some other event callbacks...
        editor.on('click', function (e) {
            console.log('Editor was clicked');
        });

        editor.on('keyup', function (e) {
            console.log('Someone typed something');
        });

      }
    });

提示:

  1. 如果你想要你的页脚左侧的按钮,你可以用$('.tox-dialog__footer-end')...替换$('.tox-dialog__footer-start')...
  2. 这当前适用于默认皮肤,对.tox-dialog__footer类的更改可能会破坏这一点。
  3. 对库更改标题“插入/编辑链接”的任何更新都将打破此问题。
  4. 上面的例子需要jQuery才能工作。
  5. 这是一个最基本的例子。使用配置指南自定义工具栏,设置事件等。
© www.soinside.com 2019 - 2024. All rights reserved.