Sign in
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

  • This topic has 2 replies, 2 voices, and was last updated 5 months, 1 week ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10528
    Avatar photoraph.roberts

    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 photoraph.roberts

    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 photoTomasz Dziuda

    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

    --
    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.