Oops, you need to build the package before running this example. It's easy: just run rake
in the project's directory.
This demonstrates how you can subclass the built in toolbar class and add your own behavior to it.
Toolbar = Class.create(WysiHat.Toolbar, {
createToolbarElement: function() {
var toolbar = new Element('div', { 'class': 'toolbar' });
this.editor.insert({before: toolbar});
return toolbar;
},
createButtonElement: function(toolbar, options) {
var button = Element('a', { 'href': '#' });
button.update(options.get('label'));
button.addClassName('button_' + options.get('name'));
toolbar.appendChild(button);
return button;
},
updateButtonState: function(element, name, state) {
if (state)
element.addClassName('highlight');
else
element.removeClassName('highlight');
}
});
document.on("dom:loaded", function() {
var editor = WysiHat.Editor.attach('content');
var toolbar = new Toolbar(editor);
toolbar.addButtonSet(WysiHat.Toolbar.ButtonSets.Basic);
});