简体   繁体   English

TinyMCE:如何添加快捷方式来更改字体大小

[英]TinyMCE: How to add a shortcut to change font size

I would like to have a shortcut in my TinyMCE edictor to easily change the size of the text. 我想在TinyMCE编辑器中有一个快捷方式,可以轻松更改文本的大小。 From TinyMCE Website , there is the command FontSize with this description TinyMCE网站上 ,有带有此描述的命令FontSize

Font size of the text. 文本的字体大小。 The value passed in should be the font size 1-7. 传入的值应为字体大小1-7。

I tried adding this command to my list of others custom shortcuts like this 我尝试将此命令添加到我的其他自定义快捷方式列表中

ed.addShortcut('ctrl+shift+w', 'size_desc', FontSize(5));

But it didn't work. 但这没有用。 I also tried this but without success: 我也尝试过,但是没有成功:

ed.addShortcut('ctrl+shift+w', 'size_desc', '["FontSize", 5]');

Also I am confused about the value: why can we only set 1 to 7 and not let say 12px ? 我也对值感到困惑:为什么我们只能将1设置为7而不是说12px

Have you tried this? 你有尝试过吗?

ed.addShortcut('ctrl+shift+w', 'size_desc', '["FontSize", !1, "5px"]');

Also you can create a TinyMce plugin: 您也可以创建一个TinyMce插件:

  1. go to your TinyMCE folder and open note.html 转到您的TinyMCE文件夹并打开note.html
  2. In the list of plugins add fontsize_plugin and in the list of toolbar add fontsizeselect plugins列表中添加fontsize_plugin ,在toolbar列表中添加fontsizeselect
  3. then add this line juste below toolbar: 然后在工具栏下面添加以下行:

    fontsize_formats: "8px 10px 12px 14px 16px 18px fontsize_formats:“ 8px 10px 12px 14px 16px 18px

  4. open the folder plugins and create in it a folder fontsize_plugin and in this filder create a file plugin.js in which you should copy paste this: 打开文件夹插件,并在其中创建一个文件夹fontsize_plugin然后在此filder中创建一个文件plugin.js ,您应该在其中复制粘贴以下内容:

     tinymce.PluginManager.add('fontsize_plugin', function (editor, url) { editor.addCommand('fontsize_plugin_command', function () { var node = tinymce.activeEditor.selection.getNode(); var fontsize = tinymce.activeEditor.dom.getStyle(node, 'font-size', true); fontsize = fontsize.split("p", 1) fontsize--; if (fontsize > 10 && fontsize <= 14) { fontsize = 10; } else if (fontsize <= 10) { fontsize = 18; } else { fontsize = 14; } fontsize = fontsize + "px"; tinymce.activeEditor.execCommand('fontsize', false, fontsize); }); editor.addShortcut('ctrl+shift+w', 'fontsize_plugin_desc', 'fontsize_plugin_command'); }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM