2010-12-21 90 views
1

如何在tinymce的上下文菜單中添加項目。我需要從文本菜單選擇打開TinyMCE的如何從tinymce contextmenu插件調用thickbox?

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

的ThickBox時我可以調用的ThickBox與上面的代碼。我需要在contextmenu插件中重新編碼。幫我

+0

什麼是厚盒子? – Thariama 2010-12-21 15:35:41

+0

thickbox是一個JavaScript庫來打開彈出窗口中的另一個頁面請參閱此網站的thickbox http://jquery.com/demo/thickbox/ – 2010-12-21 15:36:49

回答

1

好了,在這種情況下,你需要加載文本菜單插件(加載自定義插件之前做到這一點!)

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

這裏是一個文本菜單自己的插件完整的示例代碼。您需要將此代碼放在plugins目錄的名爲'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); 


})(); 

確保括號設置正確(我不得不復制/粘貼和刪除部分代碼,以便可能會丟失括號)。