2014-11-21 19 views
5

ho bisogno di aggiungere un altro menu accanto alla voce "Strumenti" giù in TinyMCE 4:TinyMCE 4 add menu a discesa per barra dei menu

new item

La soluzione più vicina che ho trovato è stato questo:

// 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!!'); 
     } 
     }); 
    } 
}); 

Ma aggiunge solo un elemento al menu "Strumenti" già esistente.

risposta

14

Si può provare a specificare sia 'del menu' e 'barra dei menu 'opzione quando si chiama tinymce.init() per aggiungere una nuova voce barra dei menu sul tema moderno.

Ho provato e funziona.

È possibile controllare la demo dal vivo su http://fiddle.tinymce.com/39eaab/1 con 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

Fantastico, questo è esattamente ciò di cui ho bisogno. Grazie molto! – Tomarz

+0

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

0

Non sono sicuro che sia quello che ti serve, ma cosa succede se si prova questo:

<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> 

È possibile visualizzare il risultato del codice here

+0

Grazie per la risposta. Ho già provato questo, ma aggiunge questo nuovo elemento alla barra degli strumenti (è l'area con tutti gli stili di carattere, allineamento del testo, ecc ...). Quello di cui ho bisogno è di aggiungerlo alla barra dei menu (area con i menu a discesa in alto). – Tomarz