I want to add a custom button on the Insert/Edit Link dialog/popup in tinymce v5.
I only got this code for the setup option where I put in call to a function.
function tinyMceEditLink(editor) {
    console.log("tinyMceEditLink");
    editor.on("click", function(e) {
        console.log("this click");
    });
}
                I'll be the first to admit this is a bit hacky, but you could try:
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
    };
}
This will give you the following result:

Setup:
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');
        });
      }
    });
Tips:
$('.tox-dialog__footer-end')... with $('.tox-dialog__footer-start')... if you want your button on the left hand side of the footer..tox-dialog__footer class could break this.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With