使用 Ajax 重新打开页面后,TinyMCE 列表框和菜单保持打开状态

发布于 2024-12-10 15:08:20 字数 10894 浏览 0 评论 0原文

我有我的网络应用程序,在其中我在 colorbox 弹出窗口中打开一些弹出页面(http://jacklmoore.com/colorbox/)

在其中一个弹出窗口中,我必须使用我的 TinyMCE 安装加载一个页面,并且我已经设法做到了这。 我遇到的问题是,当我使用编辑器关闭弹出窗口并重新打开它进行编辑时,下拉菜单和菜单保持打开状态,如屏幕截图中所示。

屏幕截图已删除,请参阅下面的截屏视频,

我正在使用tiny_mce.js,并且每次加载页面时,都会执行此函数:

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++)
                                                            {
                                                                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();
            });
}

问题可能是每次我打开颜色框弹出窗口时它都会重新加载吗?老实说,我不这么认为,但由于我是这个世界的新手,我不能确定.. 有没有一个函数可以收集所有可以打开的菜单项并关闭它们?

编辑:我添加了一个截屏视频,以便您可以看到发生了什么

http://screencast.com/t/ZTysWEBaQ

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++)
                                                            {
                                                                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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘦怹 2024-12-17 15:08:20

我通过插入解决了这个错误:

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

在我的弹出窗口的关闭函数中。
我认为这是由实例的重复 ID 引起的问题,因为它们从未被销毁,并且每次我加载页面时都会生成另一个页面。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文