Search code examples
javascripttinymcewysiwyg

TinyMCE custom button with popup


I'm adding a button to my TinyMCE setup like this:

        setup : function(ed) {
        // Add a custom button
        ed.addButton('mybutton', {
            title : 'My button',
            image : 'mybutton.jpg',
            onclick : function() {
                // Add you own code to execute something on click
                ed.focus();
                ed.selection.setContent('Hello world!');
            }
        });
    },

I wan't to know if it's possible in the onclick event to open a popup and get some input from the popup. Which then can be pasted into the editor. Exactly like if you're doing a plugin i just want to create my own without all the plugin style and functions..

Thanks in advance.


Solution

  • There are 2 options:

    First you can set or disable all css for the regular popup.

    Second option is to open a classical popup or modal dialogue of your own using a button click or a click onto a specified element in the editor. When closing the popup you can write something back to the editor using a command like

    tinyMCE.get("my_editor_id").execCommand("mceInsertContent",false,'whatever');