关于javascript:如何在tinyMCE中添加字体大小的工具栏?

how to add font-size toolbar in tinyMCE?

这样,我将tinyMCE初始化为文本区域。字体,粗体斜体字起作用,但字体大小选择不起作用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
tinymce.init({
    selector:"textarea#content",
    theme:"modern",
    width: 586,
    height: 300,
    menubar:false,
    font_size_classes :"fontSize1, fontSize2, fontSize3, fontSize4, fontSize5, fontSize6",//i used this line for font sizes
    content_css:"css/content.css",
    toolbar:"sizeselect | bold italic | fontselect | fontsize",//used font size for showing font size toolbar  
style_formats: [

    {title: 'Bold text', inline: 'b'},
            {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
            {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
            {title: 'Example 1', inline: 'span', classes: 'example1'},
            {title: 'Example 2', inline: 'span', classes: 'example2'},
            {title: 'Table styles'},
            {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ],
});**

您需要做的就是将fontsizeselect添加到工具栏配置参数中:

1
toolbar:"sizeselect | bold italic | fontselect |  fontsizeselect",

更新:

1
2
3
tinymce.init({
  fontsize_formats:"8pt 10pt 12pt 14pt 18pt 24pt 36pt"
});

这可能用于透视。以下是我的TinyMCE初始化JS代码,其中包括字体类型和大小的选项。

1
2
3
4
5
6
7
8
9
10
11
12
13
tinymce.init({
    selector: '#articletextarea',
    plugins: [
        'advlist autolink lists link image charmap preview hr anchor pagebreak',
        'searchreplace wordcount visualblocks visualchars code',
        'insertdatetime media nonbreaking table contextmenu directionality',
        'emoticons template paste textcolor colorpicker textpattern imagetools codesample'
    ],
    toolbar: 'codesample | bold italic sizeselect fontselect fontsizeselect | hr alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | insertfile undo redo | forecolor backcolor emoticons | code',
    fontsize_formats:"8pt 10pt 12pt 14pt 18pt 24pt 36pt",
    height:"350",
    menubar: false
});

1
2
3
4
theme_modern_font_sizes:"10px,12px,13px,14px,16px,18px,20px",
font_size_style_values:"12px,13px,14px,16px,18px,20px",

toolbar:"insertfile undo redo | fontsizeselect |

我真的很生气,因为wordpress似乎努力使人们想要挖掘背景并玩代码,即使是所谓的基本功能(如更改字体)也是如此。

幸运的是,我找到了一种无需做任何实际编码即可启用字体大小菜单的方法。

正好-

  • 使用插件" TinyMCE Advanced"
  • 在设置中激活它。
  • 此处有更详细的说明。