javascript - Extending the format plugin for Aloha Editor -
is there real out there on how extend aloha editor?
what trying extend floating menu- want add drop down list custom fields.
for instance, if user selects custom field label added html , like: <special_field>
appears inside content editable.
update: code initialization part of plugin far...
example.product.init = function() { var = this; // floating menu "insert template field"-button 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 ); // product scope & product attribute field gentics.aloha.floatingmenu.createscope(this.getuid('product'), 'gentics.aloha.global'); this.productfield = new gentics.aloha.ui.attributefield(); //style drop down appears when user searches fieldname this.productfield.settemplate('<span><b>{name}</b>' + '<br class="clear" /><i>{type}</i></span>'); // set type of field allowed visible of field search this.productfield.setobjecttypefilter(['specialfield','systemfield']); this.productfield.setdisplayfield('name'); gentics.aloha.floatingmenu.addbutton( this.getuid('product'), this.productfield, this.i18n('floatingmenu.tab.specialfield'), 1 ); // handle event product block clicked 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'); } // re-layout floating menu gentics.aloha.floatingmenu.dolayout(); }); gentics.aloha.eventregistry.subscribe( gentics.aloha, "editabledeactivated", function(jevent, aevent) { jquery('.product-selected').removeclass('product-selected'); } );
this adds 1 field editor, must click on field change correct field type.
update2: latest code is: (with screenshot below)
/** * insert template field @ cursor position */ 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>'; // floating menu "insert template field"-button var insertbutton = new gentics.aloha.ui.button({ label: button.name.substring(0, 11), //truncate fields enable easy viewing 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; } }
i code reply can updated code... can see buttons overflow... else may notice pin cannot seen if there many tabs...
hej,
if want add dropdown custom contents may want try multisplitbutton (this kind of input element used apply h1, h2, h3 , on). multisplitbutton along inserting contents editable covered in product plugin (http://aloha-editor.org/guides/writing_plugins.html) contains demo.
all guides located @ http://aloha-editor.org/guides/.
Comments
Post a Comment