如何在 TinyMCE 4 中创建一个增加字体大小的按钮 [英] How to create a button in TinyMCE 4 that increments font size

查看:19
本文介绍了如何在 TinyMCE 4 中创建一个增加字体大小的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人设法在 TinyMCE 4 中创建一个按钮,将所选文本的字体大小增加 1 像素?

Has anyone managed to create a button in TinyMCE 4 that will increment the font size of the selected text by, say, 1px?

我遇到的问题是获取所选文本,无论它是否已经在跨度中.我愿意修改 TinyMCE 源.

The problem I'm having is getting ahold of the selected text, whether it's in a span already or not. I'm willing to modify the TinyMCE source.

感谢您的任何想法.

推荐答案

不需要修改源码,创建插件即可.

You don't need to modify the source code, you can create a plugin.

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

Here is the documentation of how to create a plugin for TinyMCE: http://www.tinymce.com/wiki.php/Tutorials:Creating_a_plugin

基于此,您可以创建自己的按钮(参见工作示例)这是代码的一部分:

based on that you can create your own button (see working example) here is part of the code:

    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

这篇关于如何在 TinyMCE 4 中创建一个增加字体大小的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆