Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

TinyMCE button disappearing

  • #10528
    Avatar photo[anonymous]

    I have added a button to tinyMCE, using the same technique as outlined here:

    https://getpublii.com/dev/how-to-add-custom-config-or-js-for-post-editor/

    The button works perfectly BUT only displays the first time tinyMCE is displayed (after loading publii). If I browse to a different post, my custom button disappears.

    Sharing in case anyone can help! Thanks everyone.

    Related info

    I am using prodocs theme, and publii 0.42.1

    my tinymce.override.json is as follows:

    {
      "toolbar2": "styleselect formatselect sourcecode customInsertButton"
    }

    and my tinymce.script.js is:

    // get an instance of the editor
    var editor = tinymce.editors[0]; //or tinymce.editors[0], or loop, whatever
    
    
    editor.ui.registry.addButton('customInsertButton', {
      text: 'My Button',
      onAction: (_) => editor.insertContent(` It's my button! `)
    });
    #10532
    Avatar photo[anonymous]

    I was able to get this working with the below (rather hacky) code.

    var editor = tinyMCE.activeEditor; //or tinymce.editors[0], or loop, whatever
    
    editor.on('init', function(e) {
        console.log('The Editor has initialized.');
    
        var mybuthtml = ``;
    
        $( ".tox-toolbar:nth-child(2)" ).css("background", "yellow");
        $( ".tox-toolbar:nth-child(2)" ).append( mybuthtml );
    
        $("#mycustbut").on('click touchstart', function () {
            console.log("custom but clicked");
            editor.insertContent(` It's my button! `);
        });
    });
    #10599
    Avatar photo[anonymous]

    Hi,

    Your issue can be related to this bug: https://github.com/GetPublii/Publii/issues/1237 – it will be fixed on upcoming Publii v.0.43