【问题标题】:How to call thickbox from tinymce contextmenu plugin?如何从tinymce contextmenu插件调用thickbox?
【发布时间】:2010-12-21 15:23:49
【问题描述】:

如何在 tinymce 的上下文菜单中添加项目。我需要从tinymce的上下文菜单选择中打开一个厚框

    var url = "upload.php?keepThis=true&TB_iframe=1&width=1000&height=400&model=true";
    tb_show("Edit Image", url);

我可以用上面的代码调用thickbox。我需要在上下文菜单插件中重新编码的地方。帮帮我

【问题讨论】:

  • thickbox 是一个 javascript 库,用于在弹出窗口中打开另一个页面 请参阅此站点以获取thickbox jquery.com/demo/thickbox
  • 不知道,但这个帖子可能会有所帮助:tinymce.moxiecode.com/forum/viewtopic.php?id=5836
  • 你到底想做什么?例如,当您右键单击要打开的上下文菜单时,您可以从中选择什么
  • 一旦我右键单击图像编辑图像选项想要显示在上下文菜单上,一旦我单击编辑图像选项。我喜欢用thickbox打开一个弹出窗口

标签: jquery tinymce thickbox


【解决方案1】:

好的,在这种情况下,您需要加载上下文菜单插件(在加载自定义插件之前执行此操作!)

plugins: '...,contextmenu,....,customcontextmenu,...',

这是一个自己的上下文菜单插件的完整示例代码。您需要在插件目录的名为“contextmenu”的子目录中的名为“editor_plugin.js”的文件(和名为“editor_plugin_src.js”的文件)中包含此代码。

(function() {

  tinymce.PluginManager.requireLangPack('customcontextmenu');

  tinymce.create('tinymce.plugins.customcontextmenu', {

    init : function(ed, url) {
        ed.addCommand('custom_option', function() {
            // do what you want here!!!
        });

// we need the real contextmenu in order to make this work
if (ed && ed.plugins.contextmenu) {

        // contextmenu gets called - this is what we do
    ed.plugins.contextmenu.onContextMenu.add(function(th, m, e, col) {

        // remove all options from standard contextmenu
        m.removeAll();

        // only if selected node is an image do this
        if (typeof e !== "undefined" && e.nodeName.toLowerCase() == 'img'){

            th._menu.add({
                title: 'Option 1',
                icon: 'option1',  // you might need to specify an image here
                cmd: 'custom_option' // call command custom_option
            });

            m.addSeparator();

                        // Second option
            //m.add({
            //  title: 'Option 2',
            //  icon: 'option2',
            //  cmd: 'custom_option2'
            //});
        }
                else {
                   // you might want to hinder the display of the contextmenu in all other cases
                   // or present other options....
                }
    });
    }
   });
},

  // Register plugin
  tinymce.PluginManager.add('customcontextmenu', tinymce.plugins.customcontextmenu);


})();

确保括号设置正确(我不得不复制/粘贴和删除部分代码,因此可能缺少括号)。

【讨论】:

  • 你的代码帮助我以一种明亮的方式发展我的概念。谢谢你@Thariama
  • 很高兴能够提供帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-02-20
  • 1970-01-01
  • 1970-01-01
  • 2014-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多