开发者

TinyMCE listboxes and menus stay open after page reopening with Ajax

开发者 https://www.devze.com 2023-04-13 08:56 出处:网络
I have my webapplication in which I open some popup pages in a colorbox popup (http://jacklmoore.com/colorbox/)

I have my webapplication in which I open some popup pages in a colorbox popup (http://jacklmoore.com/colorbox/)

In one of these popups I have to load a page with my TinyMCE installation, and I've managed to do this. The problem I'm running into is that when I close the popup with the editor and reopen it for an edit the drop downs and menus remain open, as you can see in the screenshots.

screenshots removed, see below for the screencast

I'm using tiny_mce.js, and everytime the page loads, this function gets executed:

function initScriptEditor()
{

    jQuery1_6_2.getJSON("/DeliDete/listTemplateVariables",

            function(result)
            {

                // Creates a new plugin class and a custom listbox
                tinymce
                      .create(
                            'tinymce.plugins.ExamplePlugin',
                            {
                                createControl : function(n, cm)
                                {

                                    switch(n)
                                    {
                                        case 'variablesMenu':
                                                                                                var total = parseInt(result.size, 10);
                                                var variables = new Array();
                                                for( var i = 0, j = 0; j < total; i += 5, j++)
                                                {
                                                    variables[i] = result.values[j].level;
                                                    variables[i + 1] = result.values[j].group;
                                                    variables[i + 2] = result.values[j].displayed_name;
                                                    variables[i + 3] = result.values[j].name;
                                                    variables[i + 4] = result.values[j].query;
                                                }

                                                var c = cm
                                                      .createMenuButton(
                                                            'variablesListBox',
                                                            {
                                                               title : 'Variabili',
                                                               image : 'javascripts/tiny_mce/template.gif',
                                                               icons : false
                                                            });

                                                c.onRenderMenu
                                                      .add(function(c, m)
                                                      {
                                                          var subMenuArray = new Array();
                                                          var subSubMenuArray = new Array();
                                                          var levels = new Array();
                                                            var groups;
                                                            var template_variables;
                                                            for( var levels_i = 0, levels_j = 0; levels_i < variables.length; levels_i += 5, levels_j++)
                                 开发者_如何学JAVA                           {
                                                                if(!isInArray(levels,variables[levels_i]))
                                                                {
                                                                    groups = new Array();
                                                                    levels[levels_j] = variables[levels_i];
                                                                    // aggiungo menu
                                                                            // livello
                                                                    subMenuArray[levels_j] = m.addMenu(
                                                                {
                                                                    title : levels[levels_j]
                                                                });
                                                                    // aggiungo tutti i
                                                                            // gruppi per quel
                                                                            // livello
                                                                    for( var groups_i = 1, groups_j = 0; groups_i < variables.length + 1; groups_i+=5, groups_j++)
                                                                    {
                                                                        if(variables[groups_i - 1] == levels[levels_j] && !isInArray(groups,variables[groups_i]))
                                                                        {
                                                                            template_variables = new Array();
                                                                            groups[groups_j] = variables[groups_i];
                                                                            // aggiungo menu
                                                                                    // gruppo
                                                                            subSubMenuArray[groups_j] = subMenuArray[levels_j].addMenu(
                                                                          {
                                                                              title : groups[groups_j]
                                                                          });
                                                                            // aggiungo tutte
                                                                                    // le variabili
                                                                                    // per quel
                                                                                    // gruppo
                                                                            for( var variables_i = 2, variables_j = 0; variables_i < variables.length + 2; variables_i+=5, variables_j++)
                                                                            {
                                                                                if(variables[variables_i - 2] == levels[levels_j] && variables[variables_i - 1] == groups[groups_j] && !isInArray(template_variables,variables[variables_i]))
                                                                                {
                                                                                    template_variables[variables_j] = variables[variables_i];
                                                                                    // //aggiungo
                                                                                            // menu
                                                                                            // item
                                                                                            // variabile
                                                                                    subSubMenuArray[groups_j].add(
                                                                                {
                                                                                   title : variables[variables_i],
                                                                                   onclick : function()
                                                                                   {
                                                                                       tinyMCE.activeEditor.execCommand('mceInsertContent',false,variables[findValue(variables,this.title)]);
                                                                                   }
                                                                                });
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                      });

                                                return c;

                                     }

                                    return null;
                                }
                            });

                // Register plugin with a short name
                tinymce.PluginManager.add('templatevariables',
                      tinymce.plugins.ExamplePlugin);

                tinyMCE
                      .init(
                      {
                         language : "it",
                         mode : "exact",
                         elements : "editor_editorText",
                         theme : "advanced",
                         skin : "o2k7",
                         plugins : "-templatevariables,searchreplace,pagebreak,advhr,insertdatetime,preview,print,table,template,paste,autoresize,advlist,contextmenu,inlinepopups,nonbreaking",
                         theme_advanced_buttons1 : "newdocument,|,cut,copy,paste,pastetext,pasteword,selectall,|,search,replace,|undo,redo,|,bullist,numlist,|,bold,italic,underline,|,justifyleft,justifycenter,justifyright,fontselect,fontsizeselect,formatselect",
                         theme_advanced_buttons2 : "outdent,indent,|,image,|,preview,|,forecolor,backcolor,|,insertdate,inserttime,|,advhr,removeformat,|,sub,sup,|,charmap,print,|,template,variablesMenu",
                         theme_advanced_buttons3 : "tablecontrols,table,row_props,cell_props,delete_col,delete_row,col_after,col_before,row_after,row_before,split_cells,merge_cells,|,nonbreaking,pagebreak",
                         theme_advanced_toolbar_location : "top",
                         theme_advanced_toolbar_align : "left",
                         // theme_advanced_resizing : true,
                         paste_block_drop : true,
                         dialog_type : "modal",
                         plugin_insertdate_dateFormat : "%d-%m-%Y",
                         nonbreaking_force_tab : true,
                         pagebreak_separator : "page-break-after: always;"
                      });

                fillTextBoxFromProposte();
            });
}

Could the problem be the fact it reloads every time I open the colorbox popup? Sincerely I don't think so, but since I am a newbie in this world, I can't know for sure.. Is there a function that collects all menu items that can be opened and closes them?

Edit: I added a screencast so you can see what's happening

http://screencast.com/t/ZTysWEBaQ


I resolved this bug by inserting:

tinymce.get("editorID").remove();

in my close function of the popup. I think it was a problem caused by duplicated id for the instances, because they were never destroyed and every time I loaded the page got generated another one.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号