Gosha
Gosha

Reputation: 53

Dynamic items menu in tinymce

my menu must changes depending on context:

editor.addMenuItem('table_entity', {
    context     : 'contextmenu',
    text        : 'Table Entity',
    icon        : false,
    onPostRender: function () {
        var menu = this;
        editor.on('NodeChange', function (e) {
            var table = editor.dom.getParent(e.element, 'table');
            if (table === null || table.classList.value.search(/prefix_/) == -1) {
                menu.disabled(true);
                menu.settings.menu = null;
            } else {
                var match = table.classList.value.match(/prefix_(.+)\s|$/);
                if (match[1] !== undefined) {
                    menu.settings.menu = firstItem(match[1]).concat(self.getMenu(match[1], self[match[1] + 'Property']));
                    menu.disabled(false);
                }
            }
        })
    }
});

, but its not work. Data in the object changed (menu.settings.menu), and when menu.disabled(true) - all ok, but in other cases I see the menu items that were generated for the first time (i.e. data in object is changing, items in the drop down menu not changing).

Upvotes: 0

Views: 457

Answers (1)

Michael Fromin
Michael Fromin

Reputation: 13744

TinyMCE does not support dynamically adding items to the menu after the editor is initialized. If you have to do this you could either

  • Add them all at first and just enable/disable as needed
  • User remove() and init() to reinitialize the editor with different menu options

Upvotes: 0

Related Questions