2013-04-20 63 views
0

我想知道是否可以將自定義格式添加到redactor?我創建了一個自定義按鈕,我可以更改文本的格式,但只能使用某些元素:如何將自定義格式添加到Redactor

['p','blockquote','pre','h3','h4',' H5「]

但是,我不能添加任何的以下內容:

[」小」,‘figcaption’]

我跟着主編文檔設置按鈕,這裏是我正在調用的函數:

var selected_html = $('#redactor_content').getSelected(); 
    $('#redactor_content').execCommand('formatblock', '<small>'); 

我也嘗試向我的'formattingTags'數組添加元素,但它似乎沒有任何影響。

formattingTags: 'P', '塊引用', '小', '前', 'H3', 'H4']

預先感謝您。

回答

1

我想我明白了。

添加以下到我的按鈕功能:

var $selected_html = $('#redactor_content').getSelected(); 
$('#redactor_content').execCommand('inserthtml', '<small>' + $selected_html + '</small>'); 

然而,這不是完美的,因爲它不會取代父標籤,你可以不斷加入的元素中的元素。

redactorOptionsDefaults = { 
    buttonsAdd: {}, 
    activeButtonsAdd: {}, 
    buttonsCustom: {} 
}; 

redactorOptionsDefaults.buttonsCustom.small = { 
    title: 'small Header', 
    callback: function() { 
     this.formatBlocks('small'); 
    } 
} 
redactorOptionsDefaults.activeButtonsAdd.small = 'small'; 

它如果需要格式化塊,高亮按鈕,同時選擇塊:

0

類似的東西。但重複按鈕點擊時不要移除樣式