Is there any real help on how to extend aloha editor?
What I'm trying to do is expand their floating menu - I want to add a drop-down list with custom fields.
For example, if the user selects a custom field, then the label is added to html and something like: <special_field>appears inside the editable content.
Update: my code for the plugin initialization part is still ...
EXAMPLE.Product.init = function() {
var that = this;
var insertButton = new GENTICS.Aloha.ui.Button({
label: 'template field',
'size': 'small',
'onclick': function() {
that.insertfield();
},
'tooltip': this.i18n('button.insertfield'),
'toggle': false
});
GENTICS.Aloha.FloatingMenu.addButton(
'GENTICS.Aloha.continuoustext',
insertButton,
GENTICS.Aloha.i18n(GENTICS.Aloha, 'floatingmenu.tab.insert'),
2
);
GENTICS.Aloha.FloatingMenu.createScope(this.getUID('product'), 'GENTICS.Aloha.global');
this.productField = new GENTICS.Aloha.ui.AttributeField();
this.productField.setTemplate('<span><b>{name}</b>' +
'<br class="clear" /><i>{type}</i></span>');
this.productField.setObjectTypeFilter(['specialfield','systemfield']);
this.productField.setDisplayField('name');
GENTICS.Aloha.FloatingMenu.addButton(
this.getUID('product'),
this.productField,
this.i18n('floatingmenu.tab.specialfield'),
1
);
GENTICS.Aloha.EventRegistry.subscribe(GENTICS.Aloha, 'selectionChanged', function(event, rangeObject) {
var foundMarkup = that.findProduct(rangeObject);
jQuery('.product-selected').removeClass('product-selected');
if (foundMarkup.length != 0) {
GENTICS.Aloha.FloatingMenu.setScope(that.getUID('product'));
that.productField.setTargetObject(foundMarkup, 'data-field-name');
foundMarkup.addClass('product-selected');
}
GENTICS.Aloha.FloatingMenu.doLayout();
});
GENTICS.Aloha.EventRegistry.subscribe(
GENTICS.Aloha,
"editableDeactivated",
function(jEvent, aEvent) {
jQuery('.product-selected').removeClass('product-selected');
}
);
This adds only one field to the editor, then I have to click on the field itself to change it to the correct field type.
Update2: my last code: (with screenshot below)
function SetupButton(button) {
var scope = 'GENTICS.Aloha.continuoustext';
var definefield = '<label class="ui-specialfield" data-field-name="{0}" data-field-type="{1}" contentEditable="false">[{2}]</label>';
var insertButton = new GENTICS.Aloha.ui.Button({
label: button.Name.substring(0, 11),
size: 'small',
onclick: function() {
console.debug(" field: " + button);
var range = GENTICS.Aloha.Selection.getRangeObject();
definefield = definefield.replace("{0}", button.Name);
definefield = definefield.replace("{1}", button.Type);
definefield = definefield.replace("{2}", button.Name);
var newTemplate = jQuery(definefield);
GENTICS.Utils.Dom.insertIntoDOM(newTemplate, range, jQuery(GENTICS.Aloha.activeEditable.obj));
range.startContainer = range.endContainer = newTemplate.contents().get(0);
range.select();
},
tooltip: button.Name,
toggle: false
});
switch (button.Type) {
case "sfield":
GENTICS.Aloha.FloatingMenu.addButton(scope, insertButton, button.Type, 1);
break;
case "pfield":
GENTICS.Aloha.FloatingMenu.addButton(scope, insertButton, button.Type, 1);
break;
case "afield":
GENTICS.Aloha.FloatingMenu.addButton(scope, insertButton, button.Type, 1);
break;
case "cfield":
GENTICS.Aloha.FloatingMenu.addButton(scope, insertButton, button.Type, 1);
break;
default:
break;
}
}
, ...
, ...
- , , , , ...
