2014-11-21 33 views
5

muszę dodać kolejny spadek menu obok "Narzędzia" pozycja w TinyMCE 4:TinyMCE 4 add rozwijane menu do paska menu

new item

Najbliższym rozwiązaniem znalazłem to:

// Adds a custom menu item to the editor that inserts contents when clicked 
// The context option allows you to add the menu item to an existing default menu 
tinymce.init({ 
    ... 

    setup: function(ed) { 
     ed.addMenuItem('example', { 
     text: 'My menu item', 
     context: 'tools', 
     onclick: function() { 
      ed.insertContent('Hello world!!'); 
     } 
     }); 
    } 
}); 

Ale dodaje tylko element do już istniejącego menu "Narzędzia".

Odpowiedz

14

Można próbować określić zarówno „Menu” i „paska menu "opcja, gdy wywołasz tinymce.init(), aby dodać nowy element menu na nowoczesnym motywie.

Wypróbowałem i działa.

Możesz sprawdzić demo na żywo pod numerem http://fiddle.tinymce.com/39eaab/1 za pomocą TinyMCE 4.1.7.

<script type="text/javascript"> 
tinymce.init({ 
    selector: "textarea", 
    menu : { 
     file : {title : 'File' , items : 'newdocument'}, 
     edit : {title : 'Edit' , items : 'undo redo | cut copy paste pastetext | selectall'}, 
     insert : {title : 'Insert', items : 'link media | template hr'}, 
     view : {title : 'View' , items : 'visualaid'}, 
     format : {title : 'Format', items : 'bold italic underline strikethrough superscript subscript | formats | removeformat'}, 
     table : {title : 'Table' , items : 'inserttable tableprops deletetable | cell row column'}, 
     tools : {title : 'Tools' , items : 'spellchecker code'}, 
     newmenu: {title : 'New Menu', items : 'newmenuitem'} 
    }, 
    menubar: 'file edit newmenu', 
    setup: function(editor) { 
     editor.addMenuItem('newmenuitem', { 
      text: 'New Menu Item', 
      context: 'newmenu', 
      onclick: function() { alert('yey!'); } 
     }); 
    } 
}); 
</script> 

<form method="post" action="dump.php"> 
    <textarea name="content"></textarea> 
</form> 
+0

Wspaniale, to jest dokładnie to, czego potrzebowałem. Wielkie dzięki! – Tomarz

+0

................ – ghostCoder

0

Nie wiesz, że to, co trzeba, ale co jeśli spróbujesz to:

<script type="text/javascript"> 
tinymce.init({ 
    selector: "textarea", 
    toolbar: "mybutton", 
    setup: function(editor) { 
     editor.addButton('mybutton', { 
      type: 'menubutton', 
      text: 'My button', 
      icon: false, 
      menu: [ 
       {text: 'Menu item 1', onclick: function() {editor.insertContent('Menu item 1');}}, 
       {text: 'Menu item 2', onclick: function() {editor.insertContent('Menu item 2');}} 
      ] 
     }); 
    } 
}); 
</script> 

można wyświetlić wynik kodu here

+0

Dzięki za odpowiedź. Próbowałem już tego, ale dodaje ten nowy element do paska narzędzi (jest to obszar ze wszystkimi stylami czcionek, wyrównaniem tekstu itp.). Potrzebuję go dodać do paska menu (obszar z rozwijanymi menu u góry). – Tomarz