2011-12-08 50 views

回答

2

我知道這個問題已經有人問過,但是當我偶然發現同樣的問題時,我想我會回答這個問題。也許它可以幫助別人。

tinyMCE中的source of the DropDown-Control中的評論結果非常有用。

您只需要先使用createDropMenu()創建下拉菜單,然後您可以調用add()方法將項目添加到下拉菜單中。

/** 
* This class is used to create drop menus, a drop menu can be a 
* context menu, or a menu for a list box or a menu bar. 
* 
* @class tinymce.ui.DropMenu 
* @extends tinymce.ui.Menu 
* @example 
* // Adds a menu to the currently active editor instance 
* var dm = tinyMCE.activeEditor.controlManager.createDropMenu('somemenu'); 
* 
* // Add some menu items 
* dm.add({title : 'Menu 1', onclick : function() { 
*  alert('Item 1 was clicked.'); 
* }}); 
* 
* dm.add({title : 'Menu 2', onclick : function() { 
*  alert('Item 2 was clicked.'); 
* }}); 
* 
* // Adds a submenu 
* var sub1 = dm.addMenu({title : 'Menu 3'}); 
* sub1.add({title : 'Menu 1.1', onclick : function() { 
*  alert('Item 1.1 was clicked.'); 
* }}); 
*/ 
+2

此代碼似乎創建DropMenu對象,但尚未添加它。將下拉菜單添加到工具欄需要什麼樣的代碼? – supertrue

2

這增加了一個按鈕,這樣你只需要調整它使一個下拉框

// register button 
function register_button($buttons) { 
    array_push($buttons, "btn"); 
    return $buttons; 
} 

// add button 
function add_button() { 
    if (current_user_can('edit_posts') && current_user_can('edit_pages')) 
    { 
    add_filter('mce_external_plugins', 'add_plugin'); 
    add_filter('mce_buttons', 'register_button'); 
    } 
} 

// add plugin 
function add_plugin($plugin_array) { 
    $plugin_array['btn'] =get_bloginfo('template_url').'/js/customcodes.js'; 

    return $plugin_array; 
} 

然後你會需要添加JS文件

(function() { 
    tinymce.create('tinymce.plugins.btn', { 
     init : function(ed, url) { 
      ed.addButton('btn', { 
       title : 'Add a btn', 
       image : url+'/btn.png', 
       onclick : function() { 
        ed.selection.setContent('[btn]'); 
       } 
      }); 
     }, 
     createControl : function(n, cm) { 
      return null; 
     }, 
    }); 
    tinymce.PluginManager.add('btn', tinymce.plugins.btn); 
})(); 
相關問題