如何在aloha-multi split-expanded框中添加新的aloha按钮。 (我希望能够添加无限数量的样式。当然,不是通过管理员,而是硬编码)
答案 0 :(得分:0)
为aloha编辑器添加样式: 我将在这里展示如何添加名为“meg”的简单样式
在sites \ all \ libraries \ aloha \ aloha \ plugins \ common \ format \ lib \ format-plugin.js中添加“config”数组中的“default button configuration”,类的名称,这个方式:
config:['strong','meg','em'......。]
在“initButtons”函数中添加初始化样式按钮的实现: 在开关(按钮)下,为新样式添加“case”:
注意:'span'标签用于实现具有中性标签的普通css类。
将“span.meg”类定义为特殊样式: 在你的css主文件中添加(drupal网站主题的css)“span.meg”类:
span.meg {
color: green; }
刷新您的网站以进行重建,并在浮动aloha中使用新样式
示例代码
// Additional special styles
case 'charm-meg':
that.multiSplitItems.push({
'name' : button,
'tooltip' : i18n.t('button.' + button + '.tooltip'),
'iconClass' : 'aloha-button ' + i18n.t('aloha-button-' + button),
'markup' : jQuery('<span class=' + button + '></span>'),
'click' : function () {
var
markup = jQuery('<span class=' + button + '></span>'),
rangeObject = Aloha.Selection.rangeObject,
foundMarkup,
selectedCells = jQuery('.aloha-cell-selected');
// formating workaround for table plugin
if ( selectedCells.length > 0 ) {
var cellMarkupCounter = 0;
selectedCells.each( function () {
var cellContent = jQuery(this).find('div'),
cellMarkup = cellContent.find(button);
if ( cellMarkup.length > 0 ) {
// unwrap all found markup text
// <td><b>text</b> foo <b>bar</b></td>
// and wrap the whole contents of the <td> into <b> tags
// <td><b>text foo bar</b></td>
cellMarkup.contents().unwrap();
cellMarkupCounter++;
}
cellContent.contents().wrap('<span class=' + button + '></span>');
});
// remove all markup if all cells have markup
if ( cellMarkupCounter == selectedCells.length ) {
selectedCells.find(button).contents().unwrap();
}
return false;
}
// formating workaround for table plugin
// check whether the markup is found in the range (at the start of the range)
foundMarkup = rangeObject.findMarkup(function() {
return this.nodeName.toLowerCase() == markup.get(0).nodeName.toLowerCase();
}, Aloha.activeEditable.obj);
if ( foundMarkup ) {
// remove the markup
if (rangeObject.isCollapsed()) {
// when the range is collapsed, we remove exactly the one DOM element
GENTICS.Utils.Dom.removeFromDOM(foundMarkup, rangeObject, true);
} else {
// the range is not collapsed, so we remove the markup from the range
GENTICS.Utils.Dom.removeMarkup(rangeObject, markup, Aloha.activeEditable.obj);
}
} else {
// when the range is collapsed, extend it to a word
if (rangeObject.isCollapsed()) {
GENTICS.Utils.Dom.extendToWord(rangeObject);
}
// add the markup
GENTICS.Utils.Dom.addMarkup(rangeObject, markup);
}
// select the modified range
rangeObject.select();
return false;
},
'tooltip' : i18n.t('<span class=' + button + '></span>'),
'toggle' : true
});
break;