Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 962
Speedysnail6 Avatar asked Jun 07 '14 13:06

Speedysnail6


People also ask

How to save TinyMCE content to HTML file?

Re: How to save TinyMCE content to html file. To save the page, you have to insert TinyMCE in a HTML form and add a submit button. Then you'll have to handle the submitted form with a language like PHP. A call to the file_put_contents() function should do it.

How do I add menu items to TinyMCE?

The API has three methods for adding menu items: The two arguments these methods take are: configuration - an object containing your configuration for that button. Define the custom toolbar button with the setup callback of the TinyMCE configuration to add it to the editor.

How to view image and media options in TinyMCE editor?

In TinyMCE editor to view image and media options in the menu or in toolbar need to load them by using plugins option while initializing. This adds them to the editor but you can load external file by passing the source path. It does not allow to browse any file within the system.

How to select a file when Browse button clicks on TinyMCE?

Here, <input type='file'> is used to select a file when a browse button clicks on the TinyMCE editor. This will trigger from the jQuery.


2 Answers

This is an old question, but I found a very easy way to add a Save button to the file menu. Using the setup event in tinymce, you can add a menu item:

tinymce.init({
    .....
    setup: function(editor) {
           editor.addMenuItem('save', {
                icon: 'save',
                text: 'Save',
                cmd: 'mceSave',
                context: 'file',
                disabled: true,
                onPostRender: function () {
                    var self = this;
                    editor.on('nodeChange', function() {
                        self.disabled(editor.getParam("save_enablewhendirty", true) && !editor.isDirty());
                    });
                }
            });|
    }
});

This utilizes all the regular save funtions and the onPostRender function just enables or disables the button (using code I found in the save plugin.js file)

like image 160
hacker Avatar answered Sep 24 '22 21:09

hacker


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

like image 36
Niffler Avatar answered Sep 20 '22 21:09

Niffler