2012-01-05 175 views
11

我有一个使用高级主题的tinyMCE编辑器。我在该高级主题上使用了简单的布局,因此我可以在init()上定义自己的工具栏,而不必深入了解tinyMCE正在做什么。如何添加标题(h1,h2 ...)按钮到具有高级主题,简单布局的tinyMCE?

我遇到的问题是我的编辑器没有添加标题元素的按钮。我迫切需要这个选择,但在这个问题上找不到实际的建议。

一切我做的tinymce.init()函数,我已经粘贴下面里面发生的情况:

$("textarea.tinymce").not(".simple").tinymce({ 
      script_url : "/_lib/script/tiny_mce/tiny_mce.js", 
      plugins : "wordcount,paste,spellchecker,table", 
      theme : "advanced", 
      theme_advanced_layout_manager : "SimpleLayout", 
      theme_advanced_statusbar_location : "bottom", 
      theme_advanced_toolbar_location : "top", 
      theme_advanced_buttons1 
       : "bold,italic,underline,strikethrough,|,sub,sup,|,charmap,|,forecolorpicker", 
      theme_advanced_buttons2 
       : "undo,redo,|,cut,copy,pastetext,pasteword,|,link,unlink,anchor,|,image,code", 
      theme_advanced_buttons3 : "", 
      theme_advanced_toolbar_align : "left", 
      height : 480, 
      apply_source_formatting : false, 
      convert_fonts_to_spans : true 
     }); 

我使用jQuery插件来访问TinyMCE的(我敢肯定,这有什么好与我的问题做,但它解释了代码)。

我有一个想法是使用theme_advanced_styles选项,但我不认为这将允许我插入实际的标题标签,而只是样式我的标记与跨度和什么不看起来像一个头。

任何想法非常感谢。 干杯, J

+1

你想要一个下拉菜单吗?或者如果你有每个标题元素的按钮就足够了吗? – Thariama 2012-01-05 12:00:33

+1

按钮将是绝对好的。 – 2012-01-05 12:21:11

回答

16

这里是一个按钮,它将使段落中的标题1出现。添加“formath1”您buttonlist并添加到您的TinyMCE的初始化

setup : function(ed){ 
    ed.addButton('formath1', // name to add to toolbar button list 
    { 
     title : 'Make h1', // tooltip text seen on mouseover 
     image : 'http://myserver/ma_button_image.png', 
     onclick : function() 
     { 
     ed.execCommand('FormatBlock', false, 'h1'); 
     } 
    }); 
}, 
+0

真诚感谢。这正是我一直在寻找的!我可否问一下,我是否应该看到有什么特别的文件能够知道这些东西?除了http://www.tinymce.com/wiki.php/Configuration – 2012-01-05 13:37:55

+0

上的配置选项外,我找不到其他的配置选项,很高兴能够提供帮助。该页面可以保留所有内容,但是需要一些时间才能知道如何使用它们 – Thariama 2012-01-05 13:56:58

+1

@Thariama - 是否可以仅使用突出显示的文本进行此操作? – Webnet 2012-05-15 18:03:12

4

添加标题和其他元素与隐的造型可以通过formatselecttheme: 'advanced'实例theme_advanced_buttons_[1-3]列表中添加:

tinyMCE.init({ 
    mode : 'textareas', 
    theme : 'advanced', 
    editor_selector : 'mceAdvanced', 
    plugins: 'autolink,inlinepopups', 
    theme_advanced_blockformats: 'p,address,pre,h1,h2,h3,h4,h5,h6', 
    theme_advanced_buttons1: 'formatselect,|,bold,italic,removeformat', 
    theme_advanced_buttons2: '', 
    theme_advanced_buttons3: '', 
    theme_advanced_toolbar_location: 'top', 
    theme_advanced_statusbar_location: 'bottom', 
    theme_advanced_resizing: true, 
    theme_advanced_resize_horizontal: false, 
    relative_urls: false 
}); 

我多余地 - 包括默认值仅供演示,但TinyMCE Wiki指出,自从2010年10月28日此元素列表可以减少或添加到元素包括:

`p,div,h1,h2,h3,h4,h5,h6,blockquote,dt,dd,code,samp` 
3

我发现heading plugin只是这个问题的完美解决方案。接受的答案也可以。我们发现的唯一问题是,当您的光标位于标题上时,标题按钮不会显示为活动状态,因此您可以再次按下该按钮以恢复格式,这使得它非直观。标题插件正确显示活动状态。

相关问题