简体   繁体   English

加载响应。 使用TinyMCE API卸载插件或MenuItem

[英]Load resp. unload Plugin or MenuItem using the TinyMCE API

I am using TinyMCE 4.0.x, API4 for a project at work. 我正在使用TinyMCE 4.0.x,API4进行工作的项目。 I have some simple custom plugins like: 我有一些简单的自定义插件,例如:

tinymce.PluginManager.add('simplePlugin', function(editor, url) {
    editor.addButton('simplePluginButton', { 
        text: 'Simple Example', 
        icon: false, 
        onclick: function() { alert('Do something...'); } });

    editor.addMenuItem('simplePluginMenuItem', { 
        text: 'Simple Example', 
        context: 'tools', 
        onclick: function() { alert('Do something...'); } });
});

I want to load resp. 我要加载 resp。 unload the Plugin-MenuItem and the Plugin-Button (or the Plugin itself!) on the fly using the TinyMCE API and the button resp. 使用TinyMCE API和按钮resp即时卸载 Plugin-MenuItemPlugin-Button (或Plugin !!)。 item resp. 项目响应 plugin name (in my case simplePluginMenuItem and simplePluginButton or simplePlugin ). 插件名称(在我的情况下为simplePluginMenuItemsimplePluginButtonsimplePlugin )。

The problem i am facing is that i can't reach/find the Plugin OR the MenuItem / Toolbar-Button using the API ! 我面临的问题是我无法使用API来访问/查找插件或MenuItem /工具栏按钮!

I tried different ways with no success! 我尝试了不同的方法,但没有成功! For example: 例如:

  • i can get and modify the list of the plugins using tinymce.activeEditor.plugins , but then how do i reload the editor using the API? 我可以使用tinymce.activeEditor.plugins获取和修改插件列表,但是如何使用API​​重新加载编辑器?
  • the tinymce.ui namespace has a MenuItem class, that has a remove method - how do i find the MenuItem through the API? tinymce.ui命名空间具有MenuItem类,该类具有remove方法 -如何通过API查找MenuItem? When i call tinymce.activeEditor.editorManager.ui.Menu i am getting the class and not the current menu instance! 当我调用tinymce.activeEditor.editorManager.ui.Menu我正在获取类,而不是当前菜单实例! Is there a way to retrieve the current menu instance using the API? 有没有一种使用API​​检索当前菜单实例的方法?
  • the editor instance has a lot of properties, but none of them is for the menu or the toolbar. 编辑器实例具有许多属性,但都不包含菜单或工具栏的属性。

Am i missing something? 我想念什么吗? Is there a way at all using the API to retrieve the MenuItem or the ToolbarButton or could the API be used only for creating new editor items resp. 是否有使用API​​检索MenuItemToolbarButton或者该API仅可用于创建新的编辑器项。 components? 组件?

Something like this pseudocode : 像这样的伪代码

tinymce.activeEditor.getActiveMenu.findMenuItem('simplePluginMenuItem').remove();

I found this old SO post , but at the time (year 2009) the question was asked the API Version 4.0.x was not yet released. 我找到了这个旧的SO帖子 ,但是在那时(2009年),有人问这个问题,API版本4.0.x尚未发布。

One possible solution that i found, would be to give the toolbar button and the menu item of the custom plugin, unique id of the containing div element: 我发现的一种可能的解决方案是提供自定义插件的工具栏按钮和菜单项,其中包含div元素的唯一ID:

tinymce.PluginManager.add('simplePlugin', function(editor, url) {
    editor.addButton('simplePluginButton', { 
        id  : 'simplePluginButton001',
        text: 'Simple Example', 
        icon: false, 
        onclick: function() { alert('Do something...'); } });

    editor.addMenuItem('simplePluginMenuItem', {
        id  : 'simplePluginMenuItem001',    
        text: 'Simple Example', 
        context: 'tools', 
        onclick: function() { alert('Do something...'); } });
});

Now the generated HTML code inside the TinyMCE editor looks like this: 现在,TinyMCE编辑器中生成的HTML代码如下所示:

<div    id="simplePluginButton001"
        role="button" 
        class="mce-widget mce-btn mce-first mce-last" 
        tabindex="-1" 
        aria-labelledby="simplePluginButton001">
            <button 
                role="presentation" 
                type="button" 
                tabindex="-1">
                    Simple Example
            </button>
</div>

and the div element containers could be retrieved and manipulated directly (for example using jQuery): 并且div元素容器可以直接检索和操作(例如使用jQuery):

var pluginToolbarButton = $("#simplePluginButton001");
pluginToolbarButton.hide();
//pluginToolbarButton.show();
//pluginToolbarButton.remove();

This works just fine for my case - i can build lists of menu item resp. 这对于我的情况来说很好用-我可以建立菜单项列表。 toolbar button id's, that should be made invisible resp. 工具栏按钮ID,应使其不可见。 visible. 可见。

Nevertheless i wish i could have used the API for such operations - IMO it is more elegant and it seems right . 不过,我希望我可以使用API​​进行此类操作-IMO更加优雅,而且似乎是正确的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM