How do I adding new aloha-button in aloha-multisplit-expanded box. (I want the ability to add unlimted number of styles. of course, not via administrator, but hard coded)
Adding style to aloha editor: I will show here how to add simple style named “meg”
At sites\all\libraries\aloha\aloha\plugins\common\format\lib\format-plugin.js add to "default button configuration" in “config” array, the name of the class, this way:
config: ['strong', ‘meg’, ‘em’….]
Add implementation for initialize style button in “initButtons” function: Under switch(button), add ‘case’ for the new style:
Notice: 'span' tag used for implement ordinary css class with neutral tag.
Define the class “span.meg” as special style: Add within your css main file (drupal site theme’s css) “span.meg” class:
span.meg {
color: green; }
Refresh your site for rebuild, and use the new style in floating aloha
Sample Code
// 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;