Search code examples
javascriptjqueryhtmltinymcewysiwyg

TinyMCE Save button in the File menu


I am using TinyMCE and I am using an inline editor if that matters. This is my code...

<script type="text/javascript">
tinymce.init({
    selector: "div.prut8Eje",
    inline: true,
    plugins: [
        "advlist autolink lists link image charmap print preview anchor save",
        "searchreplace visualblocks code fullscreen",
        "insertdatetime media table contextmenu paste"
    ],
    menu : { // this is the complete default configuration
        file   : {title : 'File'  , items : 'save newdocument | print'},
        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'}
    },
    toolbar: "save | insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
</script>

Well, the save button works fine in the toolbar, but doesn't show up in the File Menu. I tried to post pictures, but I need 10 reputation.

Edit: You can see the pictures at http://gyazo.com/3d08cd176cd7b3cb4c6d6d395884e466 http://gyazo.com/daed4520adb902cb87336d943d6a30f7

Thanks in advance,

Ben


Solution

  • According to their own documentation, the "save" plugin is only for the toolbar and not for the menu: http://www.tinymce.com/wiki.php/Controls

    It looks like you'd have to create your own menu item manually; something like this could work:

    tinymce.PluginManager.add('menusave', function(editor, url) {
        editor.addMenuItem('menusave', {
            text: 'Save',
            context: 'file',
            onclick: function() {
                $('.mce-i-save').closest('button').trigger('click');
            }
        });
    });
    

    For that to work though, you'd have to have the save button in the toolbar as well, but there are probably better ways to do it than by triggering a click on the button in the toolbar.

    Then don't forget to add "menusave" (or whatever you choose to name it) to the list of plugins, and to add it to wherever you want it to be in the menu:

    file   : {title : 'File'  , items : 'menusave newdocument | print'},
    

    By the way, to come up with the code above I played with this "TinyMCE Fiddle": http://fiddle.tinymce.com/ngdaab/0