在自定义ui中为字体大小创建选择下拉框

时间:2012-10-05 23:48:20

标签: tinymce

以下内容摘自TinyMCE网站及其制作自定义ui的示例。问题是该示例仅演示了如果需要按钮该怎么做。如果你想为字体大小等实现自己的选择下拉列表怎么办。我甚至不想要任何自定义,只是默认标签会做。我该怎么办?

tinyMCE.init({
        mode: "textareas",
        content_css : "../css/custom_theme_editor.css",
        theme_advanced_font_sizes: "10px,12px,13px,14px,16px,18px,20px",
    font_size_style_values : "10px,12px,13px,14px,16px,18px,20px",
        language: false, // Prevents language packs from loading

        theme: function(editor, target) {
            var dom = tinymce.DOM, editorContainer;

            // Generate UI
            editorContainer = dom.insertAfter(dom.create('div', {style: ''},
                '<div>' +
                    '<button data-mce-command="bold">bold</button>' +
                    '<button data-mce-command="italic">italic</button>' +
                    '<button data-mce-command="underline">underline</button>' +
                    '<button data-mce-command="fontsizeselect">font size</button>' +  
                    '<button data-mce-command="mceInsertContent" data-mce-value="Hello">Insert Hello</button>' +
                '</div>' +
                '<div style="border: 1px dashed #cccccc;"></div>'
            ), target);

            // Set editor container size to target element size
            dom.setStyle(editorContainer, 'width', target.offsetWidth);

            // Bind events for each button
            tinymce.each(dom.select('button', editorContainer), function(button) {
                dom.bind(button, 'click', function(e) {
                    e.preventDefault();

                    // Execute editor command based on data parameters
                    editor.execCommand(
                        dom.getAttrib(e.target, 'data-mce-command'),
                        false,
                        dom.getAttrib(e.target, 'data-mce-value')
                    );
                });
            });

            // Register state change listeners
            editor.onInit.add(function() {
                tinymce.each(dom.select('button', editorContainer), function(button) {
                    editor.formatter.formatChanged(dom.getAttrib(button, 'data-mce-command'), function(state) {
                        state ? $(button).addClass("tiny-mce-button-clicked") : $(button).removeClass("tiny-mce-button-clicked");

                    });
                });
            });

            // Return editor and iframe containers
            return {
                editorContainer: editorContainer,
                iframeContainer: editorContainer.lastChild,

                // Calculate iframe height: target height - toolbar height
                iframeHeight: target.offsetHeight - editorContainer.firstChild.offsetHeight
            };
        }
    });

0 个答案:

没有答案
相关问题