9

我正在尝试自定义默认styleselect工具栏菜单,以便可以向其添加自定义菜单元素。这个想法是将字体大小作为styleselect子菜单:

TinyMCE 4.0.5我通过以下方式 初始化 a :

tinymce.init(
{
    language_url : '/webobbywebapp/js/tiny_mce/language/es.js',
    selector:'textarea',
    plugins: "image, link, print",
    toolbar: "styleselect | undo redo | removeformat | bold italic underline |  aligncenter alignjustify  | bullist numlist outdent indent | link | print | fontselect fontsizeselect",
    menubar: false,
    statusbar: true,
    resize: true
});

由于我无法找到如何自定义默认样式选择菜单,我也在尝试创建一个完整的新菜单,我可以在其中添加字体大小控制。但我不想显示任何工具栏,我想要一个菜单​​栏。

编辑:现在我正在尝试使用以下代码修改样式选择菜单,但 fontselect 和 fontsizeselect 似乎已禁用

,style_formats:
[{
    标题:“标题_”,
    项目:[{标题:“标题1”,格式:“h1”},{标题:“标题2”,格式:“h2”},{标题:“标题3”,格式:“h3”},{标题:“标题 4”,格式:“h4”},{标题:“标题 5”,格式:“h5”},{标题:“标题 6”,格式:“h6”}]
},
            {标题:“_Inline”,项目:[{标题:“粗体”,图标:“粗体”,格式:“粗体”},{标题:“斜体”,图标:“斜体”,格式:“斜体”},
            {title: "_Underline",icon: "underline",format: "underline"}, {title: "Strikethrough",icon: "strikethrough",format: "strikethrough"}, {title: "Superscript",icon: "上标”,格式:“上标”},{标题:“下标”,图标:“下标”,格式:“下标”},{标题:“代码”,图标:“代码”,格式:“代码”}] },
            {title: "_Blocks",items: [{title: "Paragraph",format: "p"}, {title: "Blockquote",format: "blockquote"}, {title: "Div",format: "div" }, {title: "Pre",format: "pre"}]},
            {title: "_Alignment",items: [{title: "Left",icon: "alignleft",format: "alignleft"}, {title: "Center",icon: "aligncenter",format: "aligncenter"}, {标题:“右”,图标:“对齐”,格式:“对齐”},{标题:“对齐”,图标:“对齐”,格式:“对齐”}]},
            {title: "Classes", items: 'fontsizeselect'},
    {标题:“dddClasses”,项目:“字体选择”
}]
4

3 回答 3

6

最后,添加以下代码就可以了:


    ,style_formats:[
         {
           标题:“标题”,
           项目: [
             {标题:“标题1”,格式:“h1”},
             {标题:“标题2”,格式:“h2”},
             {标题:“标题 3”,格式:“h3”},
             {标题:“标题 4”,格式:“h4”},
             {标题:“标题 5”,格式:“h5”},
             {标题:“标题 6”,格式:“h6”}
           ]
        },
        {
             标题:“内联”,项目:[{标题:“粗体”,图标:“粗体”,格式:“粗体”},{标题:“斜体”,图标:“斜体”,格式:“斜体”},
            {title: "_Underline",icon: "underline",format: "underline"}, {title: "Strikethrough",icon: "strikethrough",format: "strikethrough"}, {title: "Superscript",icon: "上标”,格式:“上标”},{标题:“下标”,图标:“下标”,格式:“下标”},{标题:“代码”,图标:“代码”,格式:“代码”}] },
            {title: "_Blocks",items: [{title: "Paragraph",format: "p"}, {title: "Blockquote",format: "blockquote"}, {title: "Div",format: "div" }, {title: "Pre",format: "pre"}]},
            {title: "_Alignment",items: [{title: "Left",icon: "alignleft",format: "alignleft"}, {title: "Center",icon: "aligncenter",format: "aligncenter"}, {标题:“右”,图标:“对齐”,格式:“对齐”},{标题:“对齐”,图标:“对齐”,格式:“对齐”}]},
            {
                标题:“字体家族”,
                项目: [
                    {标题:'Arial',内联:'span',样式:{'font-family':'arial'}},
                    {title:'Book Antiqua',内联:'span',样式:{'font-family':'book antiqua'}},
                    {标题:'Comic Sans MS',内联:'span',样式:{'font-family':'comic sans ms,sans-serif'}},
                    {title: 'Courier New', inline: 'span', 样式: { 'font-family':'courier new,courier'}},
                    {标题:'Georgia',内联:'span',样式:{'font-family':'georgia,palatino'}},
                    {标题:'Helvetica',内联:'span',样式:{'font-family':'helvetica'}},
                    {标题:“影响”,内联:“跨度”,样式:{“字体家族”:“影响,芝加哥”}},
                    {标题:'Open Sans',内联:'span',样式:{'font-family':'Open Sans'}},
                    {title:'Symbol',内联:'span',样式:{'font-family':'symbol'}},
                    {标题:'Tahoma',内联:'span',样式:{'font-family':'tahoma'}},
                    {标题:'终端',内联:'跨度',样式:{'font-family':'终端,摩纳哥'}},
                    {title: 'Times New Roman', inline: 'span', 样式: { 'font-family':'times new roman,times'}},
                    {标题:'Verdana',内联:'span',样式:{'font-family':'Verdana'}}
                ]
            },
    {标题:“字体大小”,项目:[
                                {title: '8pt', inline:'span', 样式: { fontSize: '12px', 'font-size': '8px' } },
                                {title: '10pt', inline:'span', 样式: { fontSize: '12px', 'font-size': '10px' } },
                                {title: '12pt', inline:'span', 样式: { fontSize: '12px', 'font-size': '12px' } },
                                {title: '14pt', inline:'span', 样式: { fontSize: '12px', 'font-size': '14px' } },
                                {标题:'16pt',内联:'span',样式:{ fontSize:'12px','font-size':'16px'}}
]
}]

于 2013-09-09T14:43:08.807 回答
6

从 4.0.13 版开始,您可以在初始化期间使用一个名为style_formats_merge的新属性。将此属性设置为 true,它会将您的样式连接到默认集。

tinymce.init({
    style_formats_merge: true,
    style_formats: [
        {
            title: 'Line Height',
            items: [
                { title: 'Normal Line Height', inline: 'span', styles: { "line-height": '100%' } },
                { title: 'Line Height + 10%', inline: 'span', styles: { "line-height": '110%' } },
                { title: 'Line Height + 50%', inline: 'span', styles: { "line-height": '150%' } },
                { title: 'Line Height + 100%', inline: 'span', styles: { "line-height": '200%' } }
            ]
        }
    ]
});
于 2014-03-21T23:24:45.340 回答
2

如果您还需要从默认值中删除元素,您可以简单地从Github 上的源代码中复制/粘贴它们并根据需要进行调整:

tinymce.init({
    style_formats: [
        // Add the defaults from above
    ]
// ...
}

编辑感谢@lucas-moeskops 评论更新了 URL :)

于 2016-05-18T10:15:20.333 回答