Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move toolbar to the top in TinyMCE Simple theme

Tags:

tinymce

How do I move the toolbar to the top in TinyMCE Simple theme? Thanks

like image 368
Honza Pokorny Avatar asked Jun 20 '10 21:06

Honza Pokorny


2 Answers


Note: The instructions below are valid for TinyMCE 3.x. TinyMCE 4.x is available now and you should probably use it instead. See http://www.tinymce.com/wiki.php/Configuration for more information.


The toolbar can only be moved to top when using theme : advanced in TinyMCE. There is no theme_simple_toolbar_location but a theme_advanced_toolbar_location. See documentation here http://www.tinymce.com/wiki.php/Configuration3x:theme_advanced_toolbar_location.

What you can do is to serve the editor as theme : advanced and then customize the buttons by using the theme_advanced_buttons_1_n property. It's documented here http://www.tinymce.com/wiki.php/Configuration3x:theme_advanced_buttons_1_n.

Example:

The code in the example is not tested, but it should work. It will show an editor with the buttons for Bold, Italic and Underline at the top.

tinyMCE.init({
  mode : "textareas",
  theme : "advanced",
  theme_advanced_toolbar_location : "top",
  theme_advanced_buttons1 : "bold,italic,underline",
  theme_advanced_buttons2 : "",
  theme_advanced_buttons3 : ""
});

So the answer would be: one cannot move the buttons when using theme : simple.

like image 142
Erik Töyrä Silfverswärd Avatar answered Nov 16 '22 01:11

Erik Töyrä Silfverswärd


To do this, you have to edit the editor_template.js which is inside themes/simple folder.

Following is the code with the change to bring the toolbar on top.

(function() {
    var a = tinymce.DOM;
    tinymce.ThemeManager.requireLangPack("simple");
    tinymce.create("tinymce.themes.SimpleTheme", {
        init: function(c, d) {
            var e = this,
                b = ["Bold", "Italic", "Underline", "Strikethrough", "InsertUnorderedList", "InsertOrderedList"],
                f = c.settings;
            e.editor = c;
            c.contentCSS.push(d + "/skins/" + f.skin + "/content.css");
            c.onInit.add(function() {
                c.onNodeChange.add(function(h, g) {
                    tinymce.each(b, function(i) {
                        g.get(i.toLowerCase()).setActive(h.queryCommandState(i))
                    })
                })
            });
            a.loadCSS((f.editor_css ? c.documentBaseURI.toAbsolute(f.editor_css) : "") || d + "/skins/" + f.skin + "/ui.css")
        },
        renderUI: function(h) {
            var e = this,
                i = h.targetNode,
                b, c, d = e.editor,
                f = d.controlManager,
                g, tbody;
            i = a.insertAfter(a.create("span", {
                id: d.id + "_container",
                "class": "mceEditor " + d.settings.skin + "SimpleSkin"
            }), i);
            i = g = a.add(i, "table", {
                cellPadding: 0,
                cellSpacing: 0,
                "class": "mceLayout"
            });
            tbody = c = a.add(i, "tbody");
            i = b = a.add(a.add(i, "td"), "div", {
                "class": "mceIframeContainer"
            });
            i = a.add(a.add(c, "tr", {
                "class": "last"
            }), "td", {
                "class": "mceToolbar mceLast",
                align: "center"
            });
            c = e.toolbar = f.createToolbar("tools1");
            c.add(f.createButton("bold", {
                title: "simple.bold_desc",
                cmd: "Bold"
            }));
            c.add(f.createButton("italic", {
                title: "simple.italic_desc",
                cmd: "Italic"
            }));
            c.add(f.createButton("underline", {
                title: "simple.underline_desc",
                cmd: "Underline"
            }));
            c.add(f.createButton("strikethrough", {
                title: "simple.striketrough_desc",
                cmd: "Strikethrough"
            }));
            c.add(f.createSeparator());
            c.add(f.createButton("undo", {
                title: "simple.undo_desc",
                cmd: "Undo"
            }));
            c.add(f.createButton("redo", {
                title: "simple.redo_desc",
                cmd: "Redo"
            }));
            c.add(f.createSeparator());
            c.add(f.createButton("cleanup", {
                title: "simple.cleanup_desc",
                cmd: "mceCleanup"
            }));
            c.add(f.createSeparator());
            c.add(f.createButton("insertunorderedlist", {
                title: "simple.bullist_desc",
                cmd: "InsertUnorderedList"
            }));
            c.add(f.createButton("insertorderedlist", {
                title: "simple.numlist_desc",
                cmd: "InsertOrderedList"
            }));
            c.renderTo(i);
            i = c = a.add(i, "tbody");
            i = a.add(c, "tr");
            return {
                iframeContainer: b,
                editorContainer: d.id + "_container",
                sizeContainer: g,
                deltaHeight: -20
            }
        },
        getInfo: function() {
            return {
                longname: "Simple theme",
                author: "Moxiecode Systems AB",
                authorurl: "http://tinymce.moxiecode.com",
                version: tinymce.majorVersion + "." + tinymce.minorVersion
            }
        }
    });
    tinymce.ThemeManager.add("simple", tinymce.themes.SimpleTheme)
})();
like image 44
CPM Avatar answered Nov 15 '22 23:11

CPM