Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/07/2013, 15:54
blaherrod
 
Fecha de Ingreso: marzo-2011
Ubicación: Matehuala
Mensajes: 10
Antigüedad: 13 años, 1 mes
Puntos: 0
crear botones dinamicamente en tinyMCE 4.x

hola buenas tardes!
tengo el problema de que en tinyMCE quiero agregar un menu con la siguiente estructura:
item 1
sub item 1.1
item 2
sub item 2.1
sub item 2.2
...
de una forma dinamica, encontre un ejemplo y lo modifique en la siguiente forma
Código:
tinymce.create('tinymce.plugins.ExamplePlugin', {
        createControl: function(n, cm) {
                switch (n) {
                        case 'mymenubutton':
                                var c = cm.createMenuButton('mymenubutton', {
                                        title : 'My menu button',
                                	image : '/example_data/example.gif',
                                        icons : false
                                });

                                c.onRenderMenu.add(function(c, m) {
                                        var sub;
                                        for(i=1;i<=3;i++)
                                        {
                                            sub = m.addMenu({title:'Item '+ i});
                                            for(j = 1; j <= 4; j++)
                                            {
                                                sub.add({title:'subItem' + j, onclick : function(){
                                                tinyMCE.activeEditor.execCommand('mceInsertContent', false, i+'this is sub_item -> '+j);
                                                }});
                                            }
                                        }
                                });
                                      
                                // Return the new menu button instance
                                return c;
                }

                return null;
        }
});

// Register plugin with a short name
tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
el problema es que solo funciona con tinyMCE 3.X y lo necesito para tinyMCE4.x
ademas siempre manda a imprimir el ultimo ciclo en todos los submenus