2013-10-31 33 views
1

當您初始化tinyMCE編輯器時,您可以傳遞以下自定義樣式。在tinyMCE編輯器加載後添加style_formats

tinyMCE.init({ style_formats: [{ title: 'flow', selector: 'img', styles: { 'float': 'left', 'margin-right': '5px' } }]}); 

但是,如果我想在加載後給tinyMCE som自定義樣式呢?我怎樣才能做到這一點。例如,我可以像這樣將style_formats添加到tinyMCE編輯器對象中。

tinyMCE.editors[0].settings["style_formats"] = [{title:'flow', selector:'img', styles: {'float' : 'left'}}]; 

但是編輯器本身沒有得到更新。有沒有辦法告訴tinyMCE重新加載它自己?或者有另一種方式來即時更新編輯器?

乾杯。

回答

2

您是否真的想要在現有設置之後添加它或僅追加到現有設置?從版本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%' } } 
      ] 
     } 
    ] 
}); 
0

在您的tinymce配置文件後,您可以通過向其中添加以下代碼來將您的tinymce設置擴展到新的js文件中。

jQuery.extend(tinymce.settings, 
{ 
    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%' } } 
      ] 
     } 
] 
}); 
相關問題