如何在TinyMCE 4中创建一个增加字体大小的按钮

时间:2015-01-09 18:54:44

标签: tinymce-4

有没有人设法在TinyMCE 4中创建一个按钮,它会增加所选文本的字体大小,例如1px?

我遇到的问题是获取所选文本,无论是否已经跨越。 我愿意修改TinyMCE来源。

感谢任何想法。

1 个答案:

答案 0 :(得分:4)

您不需要修改源代码,您可以创建插件。

以下是如何为TinyMCE创建插件的文档: http://www.tinymce.com/wiki.php/Tutorials:Creating_a_plugin

基于此你可以创建自己的按钮(see working example)  这是代码的一部分:

    var currentFontSize = new Number($(tinyMCE.activeEditor.selection.getNode()).css('font-size').replace('px','')); //remove the px part
        currentFontSize =  currentFontSize + 1; //increase font by one

        tinymce.activeEditor.formatter.register('mycustomformat', {
         inline : 'span',
        styles : {'font-size' : currentFontSize + 'px'} //this is the font size incremented by one
});

 tinymce.activeEditor.formatter.apply('mycustomformat'); //apply the format to the selected text